scuffle_settings/
options.rs

1/// Options to customize parsing
2#[derive(Debug, Clone)]
3pub struct Options {
4    /// The CLI options
5    #[cfg(feature = "cli")]
6    pub cli: Option<Cli>,
7    /// The default config file name (loaded if no other files are specified)
8    pub default_config_file: Option<&'static str>,
9    /// Environment variables prefix
10    ///
11    /// A setting called `foo` would be read from the environment as `APP_FOO` where `APP` is the prefix.
12    pub env_prefix: Option<&'static str>,
13}
14
15impl Default for Options {
16    fn default() -> Self {
17        Self {
18            #[cfg(feature = "cli")]
19            cli: None,
20            default_config_file: Some("config"),
21            env_prefix: Some("APP"),
22        }
23    }
24}
25
26/// A struct used to define how the CLI should be generated
27///
28/// See the [`cli!`](crate::cli) macro for a more convenient way to initialize this struct.
29#[derive(Debug, Clone)]
30pub struct Cli {
31    /// The name of the program
32    pub name: &'static str,
33
34    /// The version of the program
35    pub version: &'static str,
36
37    /// The about of the program
38    pub about: &'static str,
39
40    /// The author of the program
41    pub author: &'static str,
42
43    /// The arguments passed to the program
44    pub argv: Vec<String>,
45}
46
47/// A macro to create a CLI struct
48///
49/// This macro will automatically set the name, version, about, and author from
50/// the cargo environment variables at compile time.
51///
52/// Used internally when using the [`bootstrap!`](crate::bootstrap) macro.
53#[macro_export]
54macro_rules! cli {
55    () => {
56        $crate::cli!(std::env::args().collect())
57    };
58    ($args:expr) => {
59        $crate::Cli {
60            name: option_env!("CARGO_BIN_NAME").unwrap_or(env!("CARGO_PKG_NAME")),
61            version: env!("CARGO_PKG_VERSION"),
62            about: env!("CARGO_PKG_DESCRIPTION"),
63            author: env!("CARGO_PKG_AUTHORS"),
64            argv: $args,
65        }
66    };
67}