Skip to content

Manage unset flag/environment variable #402

Description

@matteodisabatino

Hi, I noticed a "strange behaviour" with flags and environment variables. This is my configuration:

type Config struct {
	MyRequiredField string `env:"MY_REQUIRED_FIELD" long:"my-required-field" required:"true"`
}

func GetConfig(args []string) Config {
	var c Config
	if _, err := flags.ParseArgs(&c, args); err != nil {
		panic(err)
	}

	return c
}

Now, if I launch program both this way: go run my_program.go --my-required-field=, and this other MY_REQUIRED_FIELD= go run my_program.go I receive no errors.

I know that both flag (first case) and environment variable (second case) are passed to the program, but they are unset. Shouldn't this be an error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions