mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-23 00:03:27 +01: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:
parent
4e3c57cc7c
commit
ac32dd17c9
22
src/main.rs
22
src/main.rs
@ -454,9 +454,8 @@ fn run() -> Result<()> {
|
||||
.help("When to use the pager"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("list languages")
|
||||
Arg::with_name("list-languages")
|
||||
.long("list-languages")
|
||||
.takes_value(false)
|
||||
.help("Displays supported languages")
|
||||
)
|
||||
.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 longest = match languages.iter()
|
||||
let longest = languages.iter()
|
||||
.map(|s| s.name.len())
|
||||
.max() {
|
||||
Some(length) => length,
|
||||
None => 32, // Fallback width if they have no language definitions.
|
||||
};
|
||||
.max()
|
||||
.unwrap_or(32); // Fallback width if they have no language definitions.
|
||||
|
||||
for lang in languages {
|
||||
print!("{:width$} | ", lang.name, width = longest);
|
||||
for i in 0..lang.file_extensions.len() {
|
||||
print!("{}", lang.file_extensions[i]);
|
||||
|
||||
if i < lang.file_extensions.len() - 1 {
|
||||
print!(", ");
|
||||
}
|
||||
}
|
||||
println!();
|
||||
println!("{}", lang.file_extensions.join(", "));
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
|
Loading…
Reference in New Issue
Block a user