-
Notifications
You must be signed in to change notification settings - Fork 5
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
Parent arguments are not handled when a sub command is defined #21
Comments
Thanks for the PR. parser := argparse.NewParser("basic", "this is a basic program", nil)
name := parser.String("n", "name", nil)
subcmd := parser.AddCommand("a", "", nil)
if e := parser.Parse([]string{"-n", "world", "a"}); e != nil {
fmt.Println(e.Error())
return
} Programer defined a sub command with entry usage: xxx a [--help]
options:
--help, -h show this help message and you won't get the Expected behavior Because this is a false use, if you want the Expected behavior, except your pr, you should add at least one argument for entry parser := argparse.NewParser("basic", "this is a basic program", nil)
name := parser.String("n", "name", nil)
subA := parser.AddCommand("a", "", nil) // add one argument for `a`
subA.String("b", "", nil) and the user should input Frankly speaking, I didn't expect such use for a real case. In my original design, if the user choose to execute the subcommand, the main command will be shadowed, if the user want to test the sub command, just input |
Hello @hellflame and thx for the reply My use case is a CLI for managing a server. For example, I have this root argument Then, I can show the configuration with the subcommand I thought to use the -c for every subcommands with the magy of copy/paste :-/ Maybe a parent argument might be duplicated to subcommands ? |
Oh, I just discovered the argument property "Inherited". Maybe it is sufficient for my case... I test it and I give you a feedback |
Ok, it works perfectly. Your library is really my favorite, thanks for your work ! |
Thanks for using this library. We can build it better and better. |
Hello, I already fix this issue in a dedicated PR
Describe the bug
When I define a command argument and a sub command, my argument is never handled.
To Reproduce
Expected behavior
Must display "hello world"
Terminal Output
Environment:
Resolution
I provided those two pull requests #19 & #20 which respectively solve my case and test the bugfix.
Regards
Additional context
The text was updated successfully, but these errors were encountered: