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

Auto add --version to print program version #32

Open
Boscop opened this issue Jun 28, 2020 · 4 comments
Open

Auto add --version to print program version #32

Boscop opened this issue Jun 28, 2020 · 4 comments

Comments

@Boscop
Copy link

Boscop commented Jun 28, 2020

Please automatically add --version to print program version: env!("CARGO_PKG_VERSION").
Also I think it'd make sense if --help prints the version as well.

@benbrittain
Copy link
Contributor

This library is currently used most widely through build systems that are not Cargo based. I don't think that cargo package version is always guaranteed to match the version surfaced to users either. It's pretty trivial to add this flag yourself, so for now I'd like to hold off on this feature request.

@suluke
Copy link

suluke commented May 3, 2022

FWIW I didn't find it that trivial to add a --version flag in case one has (otherwise) required options. But I came up with a solution here: https://gist.github.com/suluke/e0c672492126be0a4f3b4f0e1115d77c
Just replace argh::from_env with this module's argh_cargo::from_env. Since it more or less just wraps argh::from_env internally the integration should be clean-ish. The way the help text is extended is obviously a bit naive, but so is the current help text formatting in general IIUIC looking at https://github.com/google/argh/blob/master/argh_shared/src/lib.rs#L18. If this is something anyone would like to see upstreamed I'd be happy to create a PR.

@homeworkprod
Copy link

I agree that it's not that trivial.

Given a program that requires positional arguments, one could not simply add a --version switch and just print the version string because myprogram --version is aborted early with "Required positional arguments not provided: […]`.

Regarding CARGO_PKG_VERSION: How about defaulting to its value while providing an optional way to override it?

@SamuelMarks
Copy link

Thanks @suluke that's useful. Would be great to see this integrated into the core library, with @homeworkprod's suggestion of CARGO_PKG_VERSION being just the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants