Structopt: rename_all for env vars

Created on 21 Nov 2018  路  3Comments  路  Source: TeXitoi/structopt

(I'm not sure if this should be on structopt or clap-rs),

This is a feature request so env may be used without any value (lik short/long), and be automatically (but differently) renamed.

Quick example:

from this:

#[derive(Clone, Debug, Deserialize, Serialize, StructOpt)]
#[serde(rename_all = "kebab-case")]
#[structopt(rename_all = "kebab-case")]
pub struct Config {
    #[structopt(long, env = "BIND_ADDR", default_value = "127.0.0.1:8080")]
        /// Address which the server will bind to.
        pub bind_addr: SocketAddr,
}

into this:

#[derive(Clone, Debug, Deserialize, Serialize, StructOpt)]
#[serde(rename_all = "kebab-case")]
#[structopt(rename_all = "kebab-case")]
#[structopt(rename_all_env = "SCREAMING_SNAKE_CASE")]
pub struct Config {
    #[structopt(long, env, default_value = "127.0.0.1:8080")]
        /// Address which the server will bind to.
        pub bind_addr: SocketAddr,
}
enhancement

Most helpful comment

That would be a structopt feature, not sens in clap.

Even the default rename_all_env value can be by default to SCREAMING_SNAKE_CASE as it would only be used by env without argument and that would be a new feature.

Thanks for the suggestion, great idea.

All 3 comments

That would be a structopt feature, not sens in clap.

Even the default rename_all_env value can be by default to SCREAMING_SNAKE_CASE as it would only be used by env without argument and that would be a new feature.

Thanks for the suggestion, great idea.

I'm voting for implementing this as #[structopt(rename_all_env)], should I do that? cc @TeXitoi

OK.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gnzlbg picture gnzlbg  路  5Comments

lucab picture lucab  路  9Comments

tathanhdinh picture tathanhdinh  路  3Comments

polarathene picture polarathene  路  6Comments

dpc picture dpc  路  9Comments