0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

fix(fmt): make fmt options CLI args less verbose (#17550)

Make deno fmt options CLI args less verbose #17546
This commit is contained in:
aryan02420 2023-02-11 23:09:56 +05:30 committed by GitHub
parent 13493d9121
commit bbcb144a6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1176,8 +1176,9 @@ Ignore formatting a file by adding an ignore comment at the top of the file:
.arg(watch_arg(false)) .arg(watch_arg(false))
.arg(no_clear_screen_arg()) .arg(no_clear_screen_arg())
.arg( .arg(
Arg::new("options-use-tabs") Arg::new("use-tabs")
.long("options-use-tabs") .long("use-tabs")
.alias("options-use-tabs")
.takes_value(true) .takes_value(true)
.min_values(0) .min_values(0)
.max_values(1) .max_values(1)
@ -1186,32 +1187,33 @@ Ignore formatting a file by adding an ignore comment at the top of the file:
.help("Use tabs instead of spaces for indentation. Defaults to false."), .help("Use tabs instead of spaces for indentation. Defaults to false."),
) )
.arg( .arg(
Arg::new("options-line-width") Arg::new("line-width")
.long("options-line-width") .long("line-width")
.alias("options-line-width")
.help("Define maximum line width. Defaults to 80.") .help("Define maximum line width. Defaults to 80.")
.takes_value(true) .takes_value(true)
.validator(|val: &str| match val.parse::<NonZeroUsize>() { .validator(|val: &str| match val.parse::<NonZeroUsize>() {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(_) => { Err(_) => Err("line-width should be a non zero integer".to_string()),
Err("options-line-width should be a non zero integer".to_string())
}
}), }),
) )
.arg( .arg(
Arg::new("options-indent-width") Arg::new("indent-width")
.long("options-indent-width") .long("indent-width")
.alias("options-indent-width")
.help("Define indentation width. Defaults to 2.") .help("Define indentation width. Defaults to 2.")
.takes_value(true) .takes_value(true)
.validator(|val: &str| match val.parse::<NonZeroUsize>() { .validator(|val: &str| match val.parse::<NonZeroUsize>() {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(_) => { Err(_) => {
Err("options-indent-width should be a non zero integer".to_string()) Err("indent-width should be a non zero integer".to_string())
} }
}), }),
) )
.arg( .arg(
Arg::new("options-single-quote") Arg::new("single-quote")
.long("options-single-quote") .long("single-quote")
.alias("options-single-quote")
.min_values(0) .min_values(0)
.max_values(1) .max_values(1)
.takes_value(true) .takes_value(true)
@ -1220,15 +1222,17 @@ Ignore formatting a file by adding an ignore comment at the top of the file:
.help("Use single quotes. Defaults to false."), .help("Use single quotes. Defaults to false."),
) )
.arg( .arg(
Arg::new("options-prose-wrap") Arg::new("prose-wrap")
.long("options-prose-wrap") .long("prose-wrap")
.alias("options-prose-wrap")
.takes_value(true) .takes_value(true)
.possible_values(["always", "never", "preserve"]) .possible_values(["always", "never", "preserve"])
.help("Define how prose should be wrapped. Defaults to always."), .help("Define how prose should be wrapped. Defaults to always."),
) )
.arg( .arg(
Arg::new("options-no-semicolons") Arg::new("no-semicolons")
.long("options-no-semicolons") .long("no-semicolons")
.alias("options-no-semicolons")
.min_values(0) .min_values(0)
.max_values(1) .max_values(1)
.takes_value(true) .takes_value(true)
@ -2559,22 +2563,16 @@ fn fmt_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
}; };
let ext = matches.value_of("ext").unwrap().to_string(); let ext = matches.value_of("ext").unwrap().to_string();
let use_tabs = optional_bool_parse(matches, "options-use-tabs"); let use_tabs = optional_bool_parse(matches, "use-tabs");
let line_width = if matches.is_present("options-line-width") { let line_width = if matches.is_present("line-width") {
Some( Some(matches.value_of("line-width").unwrap().parse().unwrap())
matches
.value_of("options-line-width")
.unwrap()
.parse()
.unwrap(),
)
} else { } else {
None None
}; };
let indent_width = if matches.is_present("options-indent-width") { let indent_width = if matches.is_present("indent-width") {
Some( Some(
matches matches
.value_of("options-indent-width") .value_of("indent-width")
.unwrap_or("true") .unwrap_or("true")
.parse() .parse()
.unwrap(), .unwrap(),
@ -2582,11 +2580,9 @@ fn fmt_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
} else { } else {
None None
}; };
let single_quote = optional_bool_parse(matches, "options-single-quote"); let single_quote = optional_bool_parse(matches, "single-quote");
let prose_wrap = matches let prose_wrap = matches.value_of("prose-wrap").map(ToString::to_string);
.value_of("options-prose-wrap") let no_semicolons = optional_bool_parse(matches, "no-semicolons");
.map(ToString::to_string);
let no_semicolons = optional_bool_parse(matches, "options-no-semicolons");
flags.subcommand = DenoSubcommand::Fmt(FmtFlags { flags.subcommand = DenoSubcommand::Fmt(FmtFlags {
check: matches.is_present("check"), check: matches.is_present("check"),
@ -3808,15 +3804,15 @@ mod tests {
let r = flags_from_vec(svec![ let r = flags_from_vec(svec![
"deno", "deno",
"fmt", "fmt",
"--options-use-tabs", "--use-tabs",
"--options-line-width", "--line-width",
"60", "60",
"--options-indent-width", "--indent-width",
"4", "4",
"--options-single-quote", "--single-quote",
"--options-prose-wrap", "--prose-wrap",
"never", "never",
"--options-no-semicolons", "--no-semicolons",
]); ]);
assert_eq!( assert_eq!(
r.unwrap(), r.unwrap(),
@ -3843,9 +3839,9 @@ mod tests {
let r = flags_from_vec(svec![ let r = flags_from_vec(svec![
"deno", "deno",
"fmt", "fmt",
"--options-use-tabs=false", "--use-tabs=false",
"--options-single-quote=false", "--single-quote=false",
"--options-no-semicolons=false", "--no-semicolons=false",
]); ]);
assert_eq!( assert_eq!(
r.unwrap(), r.unwrap(),