Skip to content

How to configure alias options? #15

Open
@ammario

Description

@ammario

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions