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

version = expr ignored, and incorrectly uses env!(CARGO_PKG_VERSION) #283

Closed
matsadler opened this issue Nov 25, 2019 · 1 comment · Fixed by #284
Closed

version = expr ignored, and incorrectly uses env!(CARGO_PKG_VERSION) #283

matsadler opened this issue Nov 25, 2019 · 1 comment · Fixed by #284

Comments

@matsadler
Copy link

Setting #[structopt(version = expr)] (where expr is any expression, but not a literal) the expression is ignored and env!(CARGO_PKG_VERSION) is used instead.

It looks like the problem is clap::App::version is being called twice, first time with expr, and second time with the value of CARGO_PKG_VERSION, and the second call wins. In the expanded macro output I'm seeing something like:

let app = ::structopt::clap::App::new("example")
    .version(VERSION)
    .version("0.1.0");

Here is a reduction of my code that's seeing the problem:

use structopt::StructOpt;

const VERSION: &str = "custom version";

#[derive(StructOpt)]
#[structopt(version = VERSION)]
pub struct Opts {}

fn main() {
    let _ = Opts::from_args();
}

As a workaround I can set #[structopt(no_version, version = VERSION)] and get the result I want, although looking at structopt_derive::attrs::Attrs::top_level_methods it doesn't look like this was intended to work.

@CreepySkeleton
Copy link
Collaborator

Right, we'll fix it sometime this week

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

Successfully merging a pull request may close this issue.

2 participants