baoyachi / shadow-rs

A build-time information stored in your rust project.(binary,lib,cdylib,dylib)
https://docs.rs/shadow-rs
MIT License
447 stars 41 forks source link

`clap_long_version` should work as-is with clap-derive `#[clap(long_version = clap_long_version())]` #86

Closed davidkna closed 2 years ago

davidkna commented 2 years ago

Right now, clap_long_version() (despite the name) is not supported as an argument with clap-derive via #[clap(long_version = clap_long_version())]

Sample:

use clap::Parser;
use crate::build::clap_long_version;

use shadow_rs::shadow;

shadow!(build);

#[derive(Parser, Debug)]
#[clap(long_version = clap_long_version())]

struct Config {
    foo: String,
}

fn main() {
    println!("{:?}", Config::parse());
}

Shadow-rs should work as-is in this scenario, without any wrapper function such as this:

fn long_version() -> &'static str {
    let ver = Box::new(clap_long_version());
    Box::leak(ver).as_str()
}
baoyachi commented 2 years ago

similar:https://github.com/baoyachi/shadow-rs/issues/68 @davidkna

baoyachi commented 2 years ago

Hi @davidkna . Now shadow-rs 0.10.0 version can support this question.

Notice :Now, you can use Upper const CLAP_LONG_VERSION, not clap_long_version()

E.g:

[dependencies]
shadow-rs = "0.10.1"

[build-dependencies]
shadow-rs = "0.10.1"
use clap::Parser;
use crate::build::CLAP_LONG_VERSION;

use shadow_rs::shadow;

shadow!(build);

#[derive(Parser, Debug)]
#[clap(long_version = CLAP_LONG_VERSION)]

struct Config {
    foo: String,
}

fn main() {
    println!("{:?}", Config::parse());
}
baoyachi commented 2 years ago

DONE .

davidkna commented 2 years ago

Thanks!