Skip to main content

config/prelude/
cmd.rs

1use crate::{cmd, Builder};
2use std::env;
3
4/// Defines command line extension methods for a [configuration builder](Builder).
5pub trait CommandLineExt: Sized {
6    /// Adds a command line configuration source.
7    fn add_command_line(self) -> Self;
8
9    /// Adds a command line configuration source.
10    ///
11    /// # Arguments
12    ///
13    /// * `switch_mappings` - The mapping of switches to configuration values
14    fn add_command_line_map<S: AsRef<str>>(self, switch_mappings: &[(S, S)]) -> Self;
15}
16
17impl CommandLineExt for Builder {
18    fn add_command_line(mut self) -> Self {
19        self.add(cmd::Provider::from(env::args()));
20        self
21    }
22
23    fn add_command_line_map<S: AsRef<str>>(mut self, switch_mappings: &[(S, S)]) -> Self {
24        self.add(cmd::Provider::new(env::args(), switch_mappings));
25        self
26    }
27}