-
I'm trying to look for a way to change the default value based off the OS. For example, I want to change the default path for the parameter #[derive(Clone, Parser, Debug)]
#[clap(author, version, about, long_about = None)]
pub struct Cli {
/// The config file to load in.
#[clap(short, long)]
pub config: String
} I tried to use a Any suggestions? |
Beta Was this translation helpful? Give feedback.
Answered by
madelaney
Mar 16, 2024
Replies: 1 comment
-
I was able to solve this by using #[derive(Clone, Parser, Debug)]
#[clap(author, version, about, long_about = None)]
pub struct Cli {
/// The config file to load in.
#[clap(short, long, default_value_t = config_path())]
pub config: String,
}
fn config_path() -> String {
if cfg!(os = "freebsd") {
String::from("/usr/local/etc/service.yaml")
}
else {
String::from("/etc/service.yaml")
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
madelaney
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was able to solve this by using
default_value_t
instead ofdefault_value
.