summaryrefslogtreecommitdiff
path: root/cli/args/flags.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/args/flags.rs')
-rw-r--r--cli/args/flags.rs99
1 files changed, 70 insertions, 29 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 9f7b9206f..00df45274 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -131,7 +131,7 @@ pub struct FmtFlags {
pub indent_width: Option<NonZeroU8>,
pub single_quote: Option<bool>,
pub prose_wrap: Option<String>,
- pub semi_colons: Option<String>,
+ pub no_semicolons: Option<bool>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -1178,6 +1178,11 @@ Ignore formatting a file by adding an ignore comment at the top of the file:
.arg(
Arg::new("options-use-tabs")
.long("options-use-tabs")
+ .takes_value(true)
+ .min_values(0)
+ .max_values(1)
+ .require_equals(true)
+ .possible_values(["true", "false"])
.help("Use tabs instead of spaces for indentation. Defaults to false."),
)
.arg(
@@ -1207,6 +1212,11 @@ Ignore formatting a file by adding an ignore comment at the top of the file:
.arg(
Arg::new("options-single-quote")
.long("options-single-quote")
+ .min_values(0)
+ .max_values(1)
+ .takes_value(true)
+ .require_equals(true)
+ .possible_values(["true", "false"])
.help("Use single quotes. Defaults to false."),
)
.arg(
@@ -1217,11 +1227,14 @@ Ignore formatting a file by adding an ignore comment at the top of the file:
.help("Define how prose should be wrapped. Defaults to always."),
)
.arg(
- Arg::new("options-semi")
- .long("options-semi")
+ Arg::new("options-no-semicolons")
+ .long("options-no-semicolons")
+ .min_values(0)
+ .max_values(1)
.takes_value(true)
- .possible_values(["prefer", "asi"])
- .help("Use semi colons. Defaults to prefer."),
+ .require_equals(true)
+ .possible_values(["true", "false"])
+ .help("Don't use semicolons except where necessary."),
)
}
@@ -2546,11 +2559,7 @@ fn fmt_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
};
let ext = matches.value_of("ext").unwrap().to_string();
- let use_tabs = if matches.is_present("options-use-tabs") {
- Some(true)
- } else {
- None
- };
+ let use_tabs = optional_bool_parse(matches, "options-use-tabs");
let line_width = if matches.is_present("options-line-width") {
Some(
matches
@@ -2566,22 +2575,18 @@ fn fmt_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
Some(
matches
.value_of("options-indent-width")
- .unwrap()
+ .unwrap_or("true")
.parse()
.unwrap(),
)
} else {
None
};
- let single_quote = if matches.is_present("options-single-quote") {
- Some(true)
- } else {
- None
- };
+ let single_quote = optional_bool_parse(matches, "options-single-quote");
let prose_wrap = matches
.value_of("options-prose-wrap")
.map(ToString::to_string);
- let semi_colons = matches.value_of("options-semi").map(ToString::to_string);
+ let no_semicolons = optional_bool_parse(matches, "options-no-semicolons");
flags.subcommand = DenoSubcommand::Fmt(FmtFlags {
check: matches.is_present("check"),
@@ -2592,10 +2597,18 @@ fn fmt_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
indent_width,
single_quote,
prose_wrap,
- semi_colons,
+ no_semicolons,
});
}
+fn optional_bool_parse(matches: &ArgMatches, name: &str) -> Option<bool> {
+ if matches.is_present(name) {
+ Some(matches.value_of(name).unwrap_or("true").parse().unwrap())
+ } else {
+ None
+ }
+}
+
fn init_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
flags.subcommand = DenoSubcommand::Init(InitFlags {
dir: matches.value_of("dir").map(|f| f.to_string()),
@@ -3610,7 +3623,7 @@ mod tests {
indent_width: None,
single_quote: None,
prose_wrap: None,
- semi_colons: None,
+ no_semicolons: None,
}),
..Flags::default()
}
@@ -3632,7 +3645,7 @@ mod tests {
indent_width: None,
single_quote: None,
prose_wrap: None,
- semi_colons: None,
+ no_semicolons: None,
}),
..Flags::default()
}
@@ -3654,7 +3667,7 @@ mod tests {
indent_width: None,
single_quote: None,
prose_wrap: None,
- semi_colons: None,
+ no_semicolons: None,
}),
..Flags::default()
}
@@ -3676,7 +3689,7 @@ mod tests {
indent_width: None,
single_quote: None,
prose_wrap: None,
- semi_colons: None,
+ no_semicolons: None,
}),
watch: Some(vec![]),
..Flags::default()
@@ -3700,7 +3713,7 @@ mod tests {
indent_width: None,
single_quote: None,
prose_wrap: None,
- semi_colons: None,
+ no_semicolons: None,
}),
watch: Some(vec![]),
no_clear_screen: true,
@@ -3731,7 +3744,7 @@ mod tests {
indent_width: None,
single_quote: None,
prose_wrap: None,
- semi_colons: None,
+ no_semicolons: None,
}),
watch: Some(vec![]),
..Flags::default()
@@ -3754,7 +3767,7 @@ mod tests {
indent_width: None,
single_quote: None,
prose_wrap: None,
- semi_colons: None,
+ no_semicolons: None,
}),
config_flag: ConfigFlag::Path("deno.jsonc".to_string()),
..Flags::default()
@@ -3784,7 +3797,7 @@ mod tests {
indent_width: None,
single_quote: None,
prose_wrap: None,
- semi_colons: None,
+ no_semicolons: None,
}),
config_flag: ConfigFlag::Path("deno.jsonc".to_string()),
watch: Some(vec![]),
@@ -3803,8 +3816,7 @@ mod tests {
"--options-single-quote",
"--options-prose-wrap",
"never",
- "--options-semi",
- "asi"
+ "--options-no-semicolons",
]);
assert_eq!(
r.unwrap(),
@@ -3821,7 +3833,36 @@ mod tests {
indent_width: Some(NonZeroU8::new(4).unwrap()),
single_quote: Some(true),
prose_wrap: Some("never".to_string()),
- semi_colons: Some("asi".to_string()),
+ no_semicolons: Some(true),
+ }),
+ ..Flags::default()
+ }
+ );
+
+ // try providing =false to the booleans
+ let r = flags_from_vec(svec![
+ "deno",
+ "fmt",
+ "--options-use-tabs=false",
+ "--options-single-quote=false",
+ "--options-no-semicolons=false",
+ ]);
+ assert_eq!(
+ r.unwrap(),
+ Flags {
+ subcommand: DenoSubcommand::Fmt(FmtFlags {
+ check: false,
+ ext: "ts".to_string(),
+ files: FileFlags {
+ include: vec![],
+ ignore: vec![],
+ },
+ use_tabs: Some(false),
+ line_width: None,
+ indent_width: None,
+ single_quote: Some(false),
+ prose_wrap: None,
+ no_semicolons: Some(false),
}),
..Flags::default()
}