diff --git a/src/language.rs b/src/language.rs index 6f768b99b..f7cfbc686 100644 --- a/src/language.rs +++ b/src/language.rs @@ -11,7 +11,9 @@ pub enum Language { C, Clojure, CoffeeScript, + #[strum(serialize = "c++")] Cpp, + #[strum(serialize = "c#")] Csharp, CSS, Dart, @@ -31,6 +33,7 @@ pub enum Language { Lisp, Lua, Nim, + #[strum(serialize = "objective-c")] ObjectiveC, Perl, Php, diff --git a/src/main.rs b/src/main.rs index c5e538664..709a32c50 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,6 +93,11 @@ fn main() -> Result<()> { return Err(Error::GitNotInstalled); } + let possible_languages: Vec = Language::iter() + .filter(|language| *language != Language::Unknown) + .map(|language| language.to_string().to_lowercase()) + .collect(); + let matches = App::new(crate_name!()) .version(crate_version!()) .author("o2sh ") @@ -109,8 +114,14 @@ fn main() -> Result<()> { .short("a") .long("ascii_language") .takes_value(true) - .default_value("") - .help("Overrides showing the dominant language ascii logo"), + .possible_values( + &possible_languages + .iter() + .map(|l| l.as_str()) + .collect::>(), + ) + .case_insensitive(true) + .help("Overrides showing the dominant language ascii logo."), ) .arg( Arg::with_name("disable_field") @@ -179,7 +190,8 @@ Possible values: [{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}]", .long("image") .takes_value(true) .help("Sets a custom image to use instead of the ascii logo"), - ).arg( + ) + .arg( Arg::with_name("no-merges") .short("m") .long("no-merges") @@ -197,9 +209,11 @@ Possible values: [{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}]", } let dir = String::from(matches.value_of("directory").unwrap()); - let custom_logo: Language = - Language::from_str(&matches.value_of("ascii_language").unwrap().to_lowercase()) - .unwrap_or(Language::Unknown); + let custom_logo: Language = if let Some(ascii_language) = matches.value_of("ascii_language") { + Language::from_str(&ascii_language.to_lowercase()).unwrap() + } else { + Language::Unknown + }; let mut disable_fields = InfoFieldOn { ..Default::default() };