Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
johngovr opened this issue Jul 12, 2023 · 1 comment

Comments

@johngovr
Copy link

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

@marckhouzam
Copy link
Collaborator

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants