Skip to content

Flag Action #1219

@kke

Description

@kke

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

No one assigned

    Labels

    area/v2relates to / is being considered for v2kind/featuredescribes a code enhancement / feature requeststatus/triagemaintainers still need to look into this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions