Skip to content

subcommand receives 2 args but report receives 0 when using MinimumNArgs(2) check args in the Args member of command. #82

@johngovr

Description

@johngovr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions