Comments (11)
I'd be interested in helping with this one if possible.
from argparse.
Feel free to pick this up! I think can start with adding relevant test case for tests.
from argparse.
Im not getting an error message like I would expect. Is this just referring to the '[--arg] is required' and then the help message being dumped after that or is it something else? Im have trouble reproducing an error with subcommands.
from argparse.
@jhughes1153 I've put together following example:
package main
import (
"fmt"
"github.com/akamensky/argparse"
"os"
)
func main() {
p := argparse.NewParser("example", "simple sub-command example")
subOne := p.NewCommand("sub-one", "Sub-command one")
subTwo := p.NewCommand("sub-two", "Sub-command two")
intArgOne := subOne.Int("i", "int", &argparse.Options{
Required: true,
Help: "simple integer",
})
intArgTwo := subTwo.Int("i", "int", &argparse.Options{
Required: true,
Help: "simple integer",
})
err := p.Parse(os.Args)
if err != nil {
panic(err)
}
if subOne.Happened() {
fmt.Printf("sub-command one arg is %d\n", *intArgOne)
} else if subTwo.Happened() {
fmt.Printf("sub-command two arg is %d\n", *intArgTwo)
}
}
the output running this is as follows:
$ go run main.go --help
usage: example <Command> [-h|--help]
simple sub-command example
Commands:
sub-one Sub-command one
sub-two Sub-command two
Arguments:
-h --help Print help information
$ go run main.go sub-one --help
panic: [-i|--int] is required
goroutine 1 [running]:
main.main()
/tmp/main.go:28 +0x603
exit status 2
As you can see on second run it did not print help message as requested, but instead it returned error that [-i|--int] is required
, while i believe it should have printed help message for sub-command. If I change Required: false
and add Default: 0
to sub-commands then it works as expected:
$ go run main.go sub-one --help
usage: example sub-one [-i|--int <integer>] [-h|--help]
Sub-command one
Arguments:
-i --int simple integer. Default: 0
-h --help Print help information
from argparse.
I believe -h|--help
should have higher priority than required:true
arguments.
from argparse.
Thanks for the explanation, I was trying to use the zooprog example and I guess I was just doing something wrong with trying to produce the error.
from argparse.
So it looks like help isnt caught in the sub commands because the sub commands dont look for the --help so they just panic on the required, so I guess we could either add help as a special flag to all subcommands or change that when it parses the flags and sees help itll call the most recent help function. Ill look into what python argparse does in this case for reference as well.
from argparse.
It looks like in argparse for python they just add help to each subparser so I think ill head in that direction first
from argparse.
@akamensky when you disable help on the parser should it disable the help for all subcommands as well?
from argparse.
Sorry for taking so long with this, I still want to work on this bug but my job has been crazy lately and taking up a lot of time on my weekends, but these next few weekends I should be free to work on it so i'll be able to spend some time on this
from argparse.
Closed by #72
from argparse.
Related Issues (20)
- How do I make a hidden argument? HOT 1
- enable required for positionals HOT 5
- SelectorList flag HOT 2
- Golang Argparse not picking correct value for multiple flags HOT 1
- Allow parser.ParseKnownArgs(...) HOT 2
- How do you get >=0 positionals? HOT 2
- [BUG] v1.4.0 args does not happened when subcommand exists
- Positional args HOT 2
- Creating commands in a type HOT 1
- Add compatibility with complete library [ bash completions ] HOT 1
- Auto complete subcommands HOT 1
- [bug] Unable to detect if file flag was actually provided? HOT 7
- subparser not implemented HOT 1
- Provide ability to configure helptext maxWidth columns HOT 9
- Getting: import cycle not allowed using the example. HOT 1
- Provide <META> fields and Author Information in usage string HOT 2
- Question about returned parameters (not a bug report) HOT 1
- FlagCounter display unexpectedly HOT 1
- expect File arg to take standard input / output stream as a value HOT 2
- Options.Default should be ignored for Flag HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from argparse.