Skip to content

How to configure alias options? #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ammario opened this issue May 8, 2024 · 0 comments
Open

How to configure alias options? #15

ammario opened this issue May 8, 2024 · 0 comments
Labels
question Further information is requested

Comments

@ammario
Copy link
Member

ammario commented May 8, 2024

Re the discussion here, it's common to want multiple envs/flags to configure the same underlying option value esp. when refactoring the command line interface.

@mafredri proposes the concept of an OptionAlias that embeds within each Option like so:

type OptionAlias struct {
	Flag          string `json:"flag,omitempty"`
	FlagShorthand string `json:"flag_shorthand,omitempty"`
	Env           string `json:"env,omitempty"`
	Deprecated	  string `json:"deprecated,omitempty"`
}

// Option is a configuration option for a CLI application.
type Option struct {
	Aliases []OptionAlias `json:"aliases,omitempty"`
	// ...
}

// Usage:
{
	// ...
	Env: "CODER_FOOBAR",
	Alias: []serpent.OptionAlias{
		{Env: "FOOBAR", Deprecated: "Use CODER_FOOBAR instead."},
	},
},

I think the extra level of nesting on all options is unjustified when in the vast majority of options there is only one "alias".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant