cobra-cli
cobra-cli copied to clipboard
subcommand receives 2 args but report receives 0 when using MinimumNArgs(2) check args in the Args member of command.
...... Args: cobra.MatchAll(cobra.MinimumNArgs(2), cobra.OnlyValidArgs), Run: cropCmdRun, } ..... func cropCmdRun(cmd *cobra.Command, args []string) { fmt.Println("crop calling .....")
fmt.Printf("args :%v \n", spew.Sdump(args))
......
build the source and run like follow: utils.exe crop -s=src.png -c=i.cvs Error: requires at least 2 arg(s), only received 0 Usage: utils crop [flags] ......
if remove the MinimumNArgs like this : ... Args: cobra.MatchAll(cobra.OnlyValidArgs), ...
build and run like follow: utils.exe crop -s=src.png -c=i.cvs crop calling ..... args :([]string) (cap=2) { }
Flags and their value are not considered args. So utils.exe crop -s=src.png -c=i.cvs
has 2 flags and 0 args
Something like utils.exe crop src.png i.cvs
has 2 args (no flags)