Skip to content
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

Open
daenney opened this issue Oct 2, 2022 · 5 comments
Open

Configurable version in usage output #193

daenney opened this issue Oct 2, 2022 · 5 comments
Labels
v2-ideas Possible inclusion in V2

Comments

@daenney
Copy link
Contributor

daenney commented Oct 2, 2022

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

if p.version != "" {
fmt.Fprintln(w, p.version)
}

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 return false causing the Version() to not be emitted, or a flag on Config?

@alexflint
Copy link
Owner

Hey @daenney - why not just have your Version() function return the empty string when you don't want to print a version?

@daenney
Copy link
Contributor Author

daenney commented Oct 3, 2022

I mean, I still want to print a version. Just not where the current version is being outputted in --help. I'd also still like --version to work, which also seems to require a Version() if I understand it correctly?

@alexflint
Copy link
Owner

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 Version() function from your argument struct and handle ErrVersion explicitly like this:

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...

@daenney
Copy link
Contributor Author

daenney commented Oct 4, 2022

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.

@alexflint
Copy link
Owner

Will add this in upcoming v2 of this library

@alexflint alexflint added the v2-ideas Possible inclusion in V2 label Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2-ideas Possible inclusion in V2
Projects
None yet
Development

No branches or pull requests

2 participants