Skip to content

Commit

Permalink
Merge pull request #142 from ZapAnton/fix_language_name_mismatch
Browse files Browse the repository at this point in the history
Fix mismatch of language names between output and `-a` input
  • Loading branch information
spenserblack authored Nov 5, 2019
2 parents 493a07f + e419f93 commit ce4756e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ pub enum Language {
C,
Clojure,
CoffeeScript,
#[strum(serialize = "c++")]
Cpp,
#[strum(serialize = "c#")]
Csharp,
CSS,
D,
Expand All @@ -34,6 +36,7 @@ pub enum Language {
Lua,
Markdown,
Nim,
#[strum(serialize = "objective-c")]
ObjectiveC,
Perl,
Php,
Expand Down
26 changes: 20 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ fn main() -> Result<()> {
return Err(Error::GitNotInstalled);
}

let possible_languages: Vec<String> = 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 <[email protected]>")
Expand All @@ -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::<Vec<&str>>(),
)
.case_insensitive(true)
.help("Overrides showing the dominant language ascii logo."),
)
.arg(
Arg::with_name("disable_field")
Expand Down Expand Up @@ -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")
Expand All @@ -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()
};
Expand Down

0 comments on commit ce4756e

Please sign in to comment.