2
0
mirror of https://github.com/sharkdp/bat synced 2024-11-18 15:26:16 +00:00

Adds requested revisions.

* removes redundant `.takes_value(false)`.
* changes Arg name to "list-languages" to be consistent with long-form.
* replaces unnecessary match statement with is_present().
* replaces unnecessary match statement on iter and uses unwrap_or()
instead.
* replaces for-loop with a call to join().
This commit is contained in:
Connor Kuehl 2018-05-07 13:00:23 -07:00 committed by David Peter
parent 4e3c57cc7c
commit ac32dd17c9

View File

@ -454,9 +454,8 @@ fn run() -> Result<()> {
.help("When to use the pager"), .help("When to use the pager"),
) )
.arg( .arg(
Arg::with_name("list languages") Arg::with_name("list-languages")
.long("list-languages") .long("list-languages")
.takes_value(false)
.help("Displays supported languages") .help("Displays supported languages")
) )
.subcommand( .subcommand(
@ -565,26 +564,17 @@ fn run() -> Result<()> {
) )
})?; })?;
if let Some(_) = app_matches.values_of("list languages") { if app_matches.is_present("list-languages") {
let languages = assets.syntax_set.syntaxes(); let languages = assets.syntax_set.syntaxes();
let longest = match languages.iter() let longest = languages.iter()
.map(|s| s.name.len()) .map(|s| s.name.len())
.max() { .max()
Some(length) => length, .unwrap_or(32); // Fallback width if they have no language definitions.
None => 32, // Fallback width if they have no language definitions.
};
for lang in languages { for lang in languages {
print!("{:width$} | ", lang.name, width = longest); print!("{:width$} | ", lang.name, width = longest);
for i in 0..lang.file_extensions.len() { println!("{}", lang.file_extensions.join(", "));
print!("{}", lang.file_extensions[i]);
if i < lang.file_extensions.len() - 1 {
print!(", ");
}
}
println!();
} }
return Ok(()); return Ok(());