Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix literal flag not being recognized from config file #935

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading