cobra-cli icon indicating copy to clipboard operation
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.

Open johngovr opened this issue 1 year ago • 1 comments

...... 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) { }

johngovr avatar Jul 12 '23 02:07 johngovr

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)

marckhouzam avatar Jul 12 '23 03:07 marckhouzam