Skip to content

Commit

Permalink
Remove FromStr impl for arg enums
Browse files Browse the repository at this point in the history
This is covered by clap's `ValueEnum` via derive. The `FromStr` impl is
now merely a hazard of forgetting to update code.
  • Loading branch information
LukasKalbertodt committed Nov 5, 2022
1 parent 6084b4f commit e975412
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::str::FromStr;

use clap::{Parser, ValueEnum};

/// Command line arguments.
Expand Down Expand Up @@ -171,18 +169,6 @@ impl Default for ColorSetting {
}
}

impl FromStr for ColorSetting {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"auto" => Ok(ColorSetting::Auto),
"always" => Ok(ColorSetting::Always),
"never" => Ok(ColorSetting::Never),
_ => Err("invalid color setting"),
}
}
}

/// Possible values for the `--format` option.
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum FormatSetting {
Expand All @@ -199,24 +185,13 @@ impl Default for FormatSetting {
}
}

impl FromStr for FormatSetting {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"pretty" => Ok(FormatSetting::Pretty),
"terse" => Ok(FormatSetting::Terse),
_ => Err("invalid output format"),
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn verify_cli() {
use clap::CommandFactory;
Arguments::command().debug_assert()
Arguments::command().debug_assert();
}
}

0 comments on commit e975412

Please sign in to comment.