-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Configurable version in usage output #193
Comments
Hey @daenney - why not just have your |
I mean, I still want to print a version. Just not where the current version is being outputted in |
Got it. That's reasonable. I think the best solution would be the ability to specify a custom template for help output, as discussed in a previous issue on the topic. In the absence of that, a workaround would be to omit the var args struct {
...
}
p, err := arg.NewParser(&args)
err = p.Parse(os.Args())
if err == arg.ErrVersion {
fmt.Println("Version: 1.2.3")
os.Exit(1)
} This still wouldn't solve your use-case of putting the version string at the bottom... |
Ah, I suppose that would work. Thanks for the pointer. Being able to supply a template to customise the usage output sounds useful. I might look into that over the weekend. |
Will add this in upcoming v2 of this library |
Hi, I also think that the output from As the original poster indicated, for example, consider the following program: package main
import "github.com/alexflint/go-arg"
type args struct {}
func (args) Description() string {
return "This is my program."
}
func (args) Version() string {
return "version 1.0.0 (git:master/abcd1234)"
}
func main() {
var args args
p := arg.MustParse(&args)
p.Fail("oops, some error!")
} This is the output with different combinations of arguments:
As it can be seen, the output of I personally don't think this needs to be configurable. I doubt anyone is particularly happy with the current behaviour. The other ideas proposed here were (1) supply a template and (2) use @alexflint if you agree, I'm happy to make a PR fixing this and updating unit tests as needed. EDIT: As a real-world example, this is what I've resorted to do in my programs to get rid of this behaviour at the expense of having a proper |
Here is my proposal to fix this issue as described above: master...hhromic:go-arg:fix-193 Let me know if you want me to turn it into a PR. |
I think you're right, it's too noisy at present, better to pare it back as you suggest. For the examples you have here, how do they look with your proposal? |
I think it looks much more concise and clean :) |
Yeah seems good to me! Happy to accept a pr |
PR with the proposed changed submitted. 👍 |
Right now, this library will always output the result of
Version()
at the start of the usage output:go-arg/usage.go
Lines 84 to 86 in 74af96c
From my own observations, doing this is fairly uncommon amongst the CLI utilities installed on my system, especially for those that provide a dedicated flag to retrieve the version. To me personally it also feels a little out of place. If I were going to include the version information in usage output I would probably do it in the epilogue, not in the prologue.
Would you accept a PR which makes this configurable? Something like a
func (args) VersionInHelp() bool {}
that could returnfalse
causing theVersion()
to not be emitted, or a flag onConfig
?The text was updated successfully, but these errors were encountered: