-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
area/v2relates to / is being considered for v2relates to / is being considered for v2kind/featuredescribes a code enhancement / feature requestdescribes a code enhancement / feature requeststatus/triagemaintainers still need to look into thismaintainers still need to look into this
Milestone
Description
I think I can already do this by creating a custom struct that implements Flag
, but maybe it's something we could have in the package 🤔
Consider this:
var debugFlag = &cli.BoolFlag{
Name: "debug",
Usage: "Enable debug output",
Aliases: []string{"d"},
EnvVars: []string{"DEBUG"},
Action: func(v bool) error {
if v {
logger.SetLevel(logger.DebugLevel)
}
},
}
With this defined, I could just bring that into my command's Flags
:
cmd := &cli.Command{
Name: "do",
Usage: "do things",
Flags: []cli.Flag{
flags.debugFlag,
&cli.StringFlag{
Name: "config",
Usage: "Path to config ",
..without having to handle the flag in that command's Before
or Action
.
Metadata
Metadata
Assignees
Labels
area/v2relates to / is being considered for v2relates to / is being considered for v2kind/featuredescribes a code enhancement / feature requestdescribes a code enhancement / feature requeststatus/triagemaintainers still need to look into thismaintainers still need to look into this