Skip to content

Commit 1dc797c

Browse files
committed
Revert "changed behaviour of --disable flag"
This reverts commit 006d7e8.
1 parent 006d7e8 commit 1dc797c

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

Diff for: src/main.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use std::{
2626
result,
2727
str::FromStr,
2828
};
29+
use strum::{IntoEnumIterator, EnumCount};
2930

3031
type Result<T> = result::Result<T, Error>;
3132

@@ -319,7 +320,7 @@ impl fmt::Display for CommitInfo {
319320
}
320321
}
321322

322-
#[derive(PartialEq, Eq, EnumString, EnumVariantNames)]
323+
#[derive(PartialEq, Eq, EnumString, EnumCount, EnumIter, IntoStaticStr)]
323324
#[strum(serialize_all = "snake_case")]
324325
enum InfoFields {
325326
Project,
@@ -334,6 +335,7 @@ enum InfoFields {
334335
LinesOfCode,
335336
Size,
336337
License,
338+
UnrecognizedField,
337339
}
338340

339341
#[derive(PartialEq, Eq, Hash, Clone, EnumString)]
@@ -447,8 +449,21 @@ fn main() -> Result<()> {
447449
.multiple(true)
448450
.takes_value(true)
449451
.case_insensitive(true)
450-
.possible_values(&InfoFields::variants())
451-
.help("Disable fields to show"))
452+
.possible_values(&InfoFields::iter()
453+
.take(InfoFields::count() - 1)
454+
.map(|field| field.into())
455+
.collect::<Vec<&str>>()
456+
.as_slice())
457+
.possible_value("")
458+
.hide_possible_values(true)
459+
.default_value("")
460+
.hide_default_value(true)
461+
.help(&format!("Disable fields to show\nPossible values: {:?}",
462+
&InfoFields::iter()
463+
.take(InfoFields::count() - 1)
464+
.map(|field| field.into())
465+
.collect::<Vec<&str>>()
466+
.as_slice())))
452467
.arg(Arg::with_name("colors")
453468
.short("c")
454469
.long("colors")
@@ -504,7 +519,11 @@ Possible values: [{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}]",
504519
let disable_fields: Vec<InfoFields> = if let Some(values) = matches.values_of("disable_field") {
505520
values
506521
.map(String::from)
507-
.map(|field: String| InfoFields::from_str(field.to_lowercase().as_str()).unwrap())
522+
.filter_map(|field: String| {
523+
let item = InfoFields::from_str(field.to_lowercase().as_str())
524+
.unwrap_or(InfoFields::UnrecognizedField);
525+
if item == InfoFields::UnrecognizedField { None } else { Some(item) }
526+
})
508527
.collect()
509528
} else {
510529
Vec::new()

0 commit comments

Comments
 (0)