-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Although version
derive is not set, the --version
logic is exist
#3737
Comments
version
derive is not set, the --version
logic is exist yetversion
derive is not set, the --version
logic is exist
I can see in
When transitioning from structopt, we intentionally stopped implicitly reading the manifest's version and adding it, instead requiring users to specify
If it doesn't support a function call, then that is a bug that should be reported As for runtime strings, we plan to fix that with #2150. A short-term workaround is to leak the memory to give it a
We have NoAutoVersion for disabling the built-in semantics when a version flag is specified by the user so you can provide your own. I can't remember if it will still auto-add a version flag or not. With #3405, we plan to add |
Thanks for your patient reply.
With
It's my fault. The custom function is work. What make me wrong is that the custom function should return #[derive(Parser, Debug)]
#[clap(author, version = print_version(), about, long_about = None)]
pub struct Args {}
fn print_version() -> &'static str {
Box::leak(format!("{} v{}", env!("CARGO_PKG_NAME").bright_black(), env!("CARGO_PKG_VERSION").red()).into())
} I will close the issue. Thank you again. |
We already do this // Determine if we should remove the generated --version flag
//
// Note that if only mut_arg() was used, the first expression will evaluate to `true`
// however inside the condition block, we only check for Generated args, not
// GeneratedMutated args, so the `mut_arg("version", ..) will be skipped and fall through
// to the following condition below (Adding the short `-V`)
if self.settings.is_set(AppSettings::DisableVersionFlag)
|| (self.version.is_none() && self.long_version.is_none()) What I had missed is the reproduction case had #[clap(short, long, help = "Print version information")]
pub version: bool, // show version info |
Please complete the following tasks
Rust Version
rustc 1.63.0-nightly (cd282d7f7 2022-05-18)
Clap Version
3.1.18
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo run -- --version
Actual Behaviour
While run
cargo run -- --version
the command get processed by clap lib itself. It will ruturnPKG_NAME
with no version specified and exit.LIKE :
Expected Behaviour
It should works like:
Additional Context
Because
derive mode
is not support dynamic string/function, we should to use a customversion
flag to run custom code.Debug Output
The text was updated successfully, but these errors were encountered: