Skip to content

Commit

Permalink
Fix literal flag not being recognized from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Akmadan23 committed Nov 14, 2023
1 parent 6f8e095 commit 0231b9b
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/flags/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,22 @@ impl Configurable<Self> for Literal {
/// Get a potential `Literal` value from [Cli].
///
/// If the "literal" argument is passed, this returns a `Literal` with value `true` in a
/// [Some]. Otherwise this returns `Literal` with value `false` in a [Some].
/// [Some]. Otherwise this returns [None].
fn from_cli(cli: &Cli) -> Option<Self> {
if cli.literal {
Some(Self(true))
} else {
Some(Self(false))
None
}
}

/// Get a potential `Literal` value from a [Config].
///
/// If the `Config::indicators` has value,
/// this returns its value as the value of the `Literal`, in a [Some].
/// Otherwise this returns `Literal` with value `false` in a [Some].
/// Otherwise this returns [None].
fn from_config(config: &Config) -> Option<Self> {
if let Some(value) = config.literal {
Some(Self(value))
} else {
Some(Self(false))
}
config.literal.map(Self)
}
}

Expand All @@ -51,7 +47,7 @@ mod test {
fn test_from_cli_none() {
let argv = ["lsd"];
let cli = Cli::try_parse_from(argv).unwrap();
assert_eq!(Some(Literal(false)), Literal::from_cli(&cli));
assert_eq!(None, Literal::from_cli(&cli));
}

#[test]
Expand All @@ -63,10 +59,7 @@ mod test {

#[test]
fn test_from_config_none() {
assert_eq!(
Some(Literal(false)),
Literal::from_config(&Config::with_none())
);
assert_eq!(None, Literal::from_config(&Config::with_none()));
}

#[test]
Expand Down

0 comments on commit 0231b9b

Please sign in to comment.