-
Notifications
You must be signed in to change notification settings - Fork 98
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
Overriding --version #171
Comments
Oh, interesting. Yeah I don't think we should print the version string in error lines. Do you mean that if you do something like type args struct {
N int
}
func (args) Version() string { return "something" }
func main() {
var arg Args
arg.MustParse(&args)
} and then invoke the program with something that doesn't parse as an integer then it behaves like this? $ ./program --n=not_a_number
Version: something
error: could not convert to an int not_a_number |
Indeed, or get something like:
With
It also doesn't pre-append "Version:", it just spits out whatever you return... I prefer to add the "Version: " part myself in the func anyway, but it seems wrong to use version in error message responses, and wrong to have them in the -h too, since the |
This is the kind of help I want, and looks a lot like you can get with clap in rust:
But to get there I have to do this:
This also gives:
|
Not a complete solution to this issue, but I recently submitted PR #223 which allows to override the package main
import (
"fmt"
"github.com/alexflint/go-arg"
)
type args struct {
Version bool `arg:"-V,--version" help:"display version and exit"`
}
func main() {
var args args
arg.MustParse(&args)
if args.Version {
fmt.Println("Show version...")
}
} With the current version of
And with my PR applied:
If both, the destination struct is versioned with Therefore, when using a custom |
Also, if there is no package main
import (
"github.com/alexflint/go-arg"
)
type args struct {
}
func main() {
var args args
arg.MustParse(&args)
} With the current version of
And with my PR applied:
|
I was tryng to make this library behave more closely to the behavior of the rust clap crate. They are similar in the way they present command line options, but with a key difference that I find annoying:
If you define a Version method in go-arg, it shows the version string in error: lines, too. My first thought was, well, why not just override Version and return it myself when I want it?
This almost works...However, --version always is processed internally and cannot be overridden, while -V does exit from MustParse with Version set to true...
Ultimately I came to doing this:
Which does what I want, but feels strange. I also go thru different paths if I also want the -V alternate, and do something like:
I think if there is an arg: --version flag the built-in --version option processing should be ignored.
The other problem is when I do my Version() function conditionally based on os.Args, the only way to get --help to show the --version option is to add the ShowVersion entry, too.
The text was updated successfully, but these errors were encountered: