Skip to content

Empty default value for enum #250

@jotaen

Description

@jotaen

Defining an enum like so enum:"a,b," allows these values: "a", "b", and "".

It doesn’t seem possible to set the default to empty string, however. The following program wouldn’t run:

type program struct {
	Flag string `enum:"a,b," default:""`
}
panic: program.Flag: enum value is only valid if it is either required or has a valid default value

Playground: https://go.dev/play/p/x5OERlVyu-J

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