Skip to content

default value based on os. #5398

Closed Answered by madelaney
madelaney asked this question in Q&A
Discussion options

You must be logged in to vote

I was able to solve this by using default_value_t instead of default_value.

#[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")
  }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by madelaney
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant