| //! How to use environment variable fallback an how it |
| //! interacts with `default_value`. |
| use structopt::StructOpt; |
| /// Example for allowing to specify options via environment variables. |
| #[derive(StructOpt, Debug)] |
| #[structopt(name = "env")] |
| // Use `env` to enable specifying the option with an environment |
| // variable. Command line arguments take precedence over env. |
| /// URL for the API server |
| #[structopt(long, env = "API_URL")] |
| // The default value is used if neither argument nor environment |
| // variable is specified. |
| #[structopt(long, env = "RETRIES", default_value = "5")] |
| let opt = Opt::from_args(); |