-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Positional argument before positional,required argument doesn't work #124
Comments
Try this: // ...
type args struct {
Age int `arg:"positional,required"`
Name string `arg:"positional"`
}
// ... |
Sorry, I should be more clear on what I want to have happend: |
Ah, I've not used this package for that specific use case, so unfortunately I have no advice there. |
You would have to do something like this: var args struct {
First *string `arg:"positional,required"
Second *string `arg:"positional"`
}
arg.MustParse(&args)
var name string
var age int
if args.Second == nil {
age = strconv.Atoi(*args.First)
} else {
name = *args.First
age = strconv.Atoi(*args.Second)
} |
Closing for now but feel free to reopen if you have further questions. |
I have the following code:
This is a weird example, but it shows what I'd like to do.
When I run "./cli 15", I want it to leave name alone and set age to 15, but it seems to assume that I passed in the value for name, because I get this:
Usage: cli NAME AGE
error: age is required
The text was updated successfully, but these errors were encountered: