Skip to content
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

internal/flags: add missing flag types for auto-env-var generation #28692

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion internal/flags/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func MigrateGlobalFlags(ctx *cli.Context) {
func doMigrateFlags(ctx *cli.Context) {
// Figure out if there are any aliases of commands. If there are, we want
// to ignore them when iterating over the flags.
var aliases = make(map[string]bool)
aliases := make(map[string]bool)
for _, fl := range ctx.Command.Flags {
for _, alias := range fl.Names()[1:] {
aliases[alias] = true
Expand Down Expand Up @@ -239,15 +239,24 @@ func AutoEnvVars(flags []cli.Flag, prefix string) {
case *cli.StringFlag:
flag.EnvVars = append(flag.EnvVars, envvar)

case *cli.StringSliceFlag:
flag.EnvVars = append(flag.EnvVars, envvar)

case *cli.BoolFlag:
flag.EnvVars = append(flag.EnvVars, envvar)

case *cli.IntFlag:
flag.EnvVars = append(flag.EnvVars, envvar)

case *cli.Int64Flag:
flag.EnvVars = append(flag.EnvVars, envvar)

case *cli.Uint64Flag:
flag.EnvVars = append(flag.EnvVars, envvar)

case *cli.Float64Flag:
flag.EnvVars = append(flag.EnvVars, envvar)

case *cli.DurationFlag:
flag.EnvVars = append(flag.EnvVars, envvar)
Comment on lines 239 to 261
Copy link

@axelKingsley axelKingsley Dec 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm late to this review, but just an offer that this could be written more compactly/without duplication:

switch flag := flag.(type) {
case
    *cli.StringFlag,
    *cli.StringSliceFlag,
    *cli.BoolFlag,
    *cli.IntFlag,
    *cli.Int64Flag,
    *cli.Uint64Flag,
    *cli.Float64Flag,
    *cli.DurationFlag:
        flag.EnvVars = append(flag.EnvVars, envvar)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good idea, let's open a new PR to fix this :)


Expand Down
Loading