coder / coder/serpent

How to configure alias options?

Open
#15 0 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Go
Stars
21
Forks
6
PR merge metrics
No merged PRs in 30d

Description

Re the discussion [here](https://github.com/coder/envbuilder/issues/166#issuecomment-2100971392), 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:

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.