返回flag的flag.FlagSet.String需要一个参数:

cmd is an instance of instance of a *Command struct in the form of:

type Command struct {
  Run func(cmd *Command, args []string)
  Flag flag.FlagSet

  Usage string
  Short string
  Long string
}

The problem that I am running into is that:

if err := cmd.Flag.Parse(args[1:]); err != nil {
  os.Exit(2)
}

Is returning the an err which reads: flag needs an argument: -list when I run my program. Here's how I have my flag setup:

func init() {
  cmdAddSensor.Flag.String("list", "default", "List all of the supported sensors")
}

Which follows the documentation here. I'm confused because the flag command line syntax mentions that any of these forms will work:

-flag
-flag=x
-flag x  // non-boolean flags only

When I run my executable with another argument (i.e.: ./myexecutable blah -list garbage my flag works as expected. I'm trying to understand why line 892 of the flag package's source is getting triggered by my setup.

I'm a Go newbie, so it's possible I'm missing something pretty obvious here. Thanks in advance!