aconfig icon indicating copy to clipboard operation
aconfig copied to clipboard

Deprecations

Open jakubdyszkiewicz opened this issue 2 years ago • 4 comments

It's not common to deprecate fields to remove them in the next release or move them to some other place. It would be nice to have support for it in aconfig. Maybe something like

type MyConfig struct {
	Hostname int `default:"xyz.internal" usage:"hostname" deprecated:"this will be gone in the next release, the internet is a dangerous place, localhost will be a default"`
}

and have a function to collect all deprecations if the value is set.

jakubdyszkiewicz avatar Jan 25 '22 16:01 jakubdyszkiewicz

Nice one, can you clarify this part:

a function to collect all deprecations if the value is set

?

cristaloleg avatar Jan 25 '22 16:01 cristaloleg

Sure, I'd like to collect all the deprecations in something like

type Deprecation struct {
  Flag string
  Env string
  YamlKey string
  Message string
}

So I can collect []Deprecation and print them for user. I want to bother the user with message only if they set (via env/flag/yaml) the deprecated config.

jakubdyszkiewicz avatar Jan 27 '22 22:01 jakubdyszkiewicz

Should this be enough? https://github.com/cristalhq/aconfig/blob/main/aconfig.go#L188

Basically you can iterate over all fields and these with .Deprecated == true are what you're looking for.

cristaloleg avatar Jan 27 '22 22:01 cristaloleg

Ah, yes. That makes sense 👍

jakubdyszkiewicz avatar Jan 29 '22 14:01 jakubdyszkiewicz