Skip to content

Commit 006d7e8

Browse files
committed
changed behaviour of --disable flag
if flag specified without value, CLI will now error out
1 parent fb62e9d commit 006d7e8

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

Diff for: src/main.rs

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

3130
type Result<T> = result::Result<T, Error>;
3231

@@ -320,7 +319,7 @@ impl fmt::Display for CommitInfo {
320319
}
321320
}
322321

323-
#[derive(PartialEq, Eq, EnumString, EnumCount, EnumIter, IntoStaticStr)]
322+
#[derive(PartialEq, Eq, EnumString, EnumVariantNames)]
324323
#[strum(serialize_all = "snake_case")]
325324
enum InfoFields {
326325
Project,
@@ -335,7 +334,6 @@ enum InfoFields {
335334
LinesOfCode,
336335
Size,
337336
License,
338-
UnrecognizedField,
339337
}
340338

341339
#[derive(PartialEq, Eq, Hash, Clone, EnumString)]
@@ -449,21 +447,8 @@ fn main() -> Result<()> {
449447
.multiple(true)
450448
.takes_value(true)
451449
.case_insensitive(true)
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())))
450+
.possible_values(&InfoFields::variants())
451+
.help("Disable fields to show"))
467452
.arg(Arg::with_name("colors")
468453
.short("c")
469454
.long("colors")
@@ -519,11 +504,7 @@ Possible values: [{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}]",
519504
let disable_fields: Vec<InfoFields> = if let Some(values) = matches.values_of("disable_field") {
520505
values
521506
.map(String::from)
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-
})
507+
.map(|field: String| InfoFields::from_str(field.to_lowercase().as_str()).unwrap())
527508
.collect()
528509
} else {
529510
Vec::new()

0 commit comments

Comments
 (0)