diff options
-rw-r--r-- | Cargo.lock | 16 | ||||
-rw-r--r-- | cli/Cargo.toml | 6 | ||||
-rw-r--r-- | cli/flags.rs | 170 | ||||
-rw-r--r-- | cli/main.rs | 4 |
4 files changed, 99 insertions, 97 deletions
diff --git a/Cargo.lock b/Cargo.lock index 3e3799d19..11cd1c798 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -435,9 +435,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.0.7" +version = "3.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12e8611f9ae4e068fa3e56931fded356ff745e70987ff76924a6e0ab1c8ef2e3" +checksum = "d8c93436c21e4698bacadf42917db28b23017027a4deccb35dbe47a7e7840123" dependencies = [ "atty", "bitflags", @@ -450,18 +450,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "3.0.5" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4dabb7e2f006497e1da045feaa512acf0686f76b68d94925da2d9422dcb521" +checksum = "df6f3613c0a3cddfd78b41b10203eb322cb29b600cbdf808a7d3db95691b8e25" dependencies = [ "clap", ] [[package]] name = "clap_complete_fig" -version = "3.0.2" +version = "3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29cc003d824770d10072f4aa4a958e66d33d74a9cb7339595ac2a445d80d50a0" +checksum = "690eb5abb7a98df1a64a3028beaf95af7e0ceb13da3186e6d0a86161af76309e" dependencies = [ "clap", "clap_complete", @@ -4485,9 +4485,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.14.2" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thiserror" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index e3a02e232..4375ce91d 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -57,9 +57,9 @@ atty = "=0.2.14" base64 = "=0.13.0" cache_control = "=0.2.0" chrono = "=0.4.19" -clap = "=3.0.7" -clap_complete = "=3.0.5" -clap_complete_fig = "=3.0.2" +clap = "=3.1.6" +clap_complete = "=3.1.1" +clap_complete_fig = "=3.1.4" data-url = "=0.1.1" dissimilar = "=1.0.2" dprint-plugin-json = "=0.14.1" diff --git a/cli/flags.rs b/cli/flags.rs index 0fe7a81c5..9cb06bace 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -1,11 +1,9 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -use clap::App; -use clap::AppSettings; use clap::Arg; use clap::ArgMatches; -use clap::ArgSettings; use clap::ColorChoice; +use clap::Command; use clap::ValueHint; use deno_core::serde::Deserialize; use deno_core::serde::Serialize; @@ -535,8 +533,8 @@ fn handle_repl_flags(flags: &mut Flags, repl_flags: ReplFlags) { flags.allow_hrtime = true; } -fn clap_root(version: &str) -> App { - clap::App::new("deno") +fn clap_root(version: &str) -> Command { + clap::Command::new("deno") .bin_name("deno") .color(ColorChoice::Never) // Disable clap's auto-detection of terminal width @@ -595,20 +593,20 @@ If the flag is set, restrict these messages to errors.", .after_help(ENV_VARIABLES_HELP) } -fn bench_subcommand<'a>() -> App<'a> { - runtime_args(App::new("bench"), true, false) - .setting(AppSettings::TrailingVarArg) +fn bench_subcommand<'a>() -> Command<'a> { + runtime_args(Command::new("bench"), true, false) + .trailing_var_arg(true) .arg( Arg::new("ignore") .long("ignore") .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .help("Ignore files"), ) .arg( Arg::new("filter") - .setting(ArgSettings::AllowHyphenValues) + .allow_hyphen_values(true) .long("filter") .takes_value(true) .help("Run benchmarks with this string or pattern in the bench name"), @@ -639,8 +637,8 @@ Directory arguments are expanded to all contained files matching the glob ) } -fn bundle_subcommand<'a>() -> App<'a> { - compile_args(App::new("bundle")) +fn bundle_subcommand<'a>() -> Command<'a> { + compile_args(Command::new("bundle")) .arg( Arg::new("source_file") .takes_value(true) @@ -667,8 +665,8 @@ If no output file is given, the output is written to standard output: ) } -fn cache_subcommand<'a>() -> App<'a> { - compile_args(App::new("cache")) +fn cache_subcommand<'a>() -> Command<'a> { + compile_args(Command::new("cache")) .arg( Arg::new("file") .takes_value(true) @@ -690,9 +688,9 @@ Future runs of this module will trigger no downloads or compilation unless ) } -fn compile_subcommand<'a>() -> App<'a> { - runtime_args(App::new("compile"), true, false) - .setting(AppSettings::TrailingVarArg) +fn compile_subcommand<'a>() -> Command<'a> { + runtime_args(Command::new("compile"), true, false) + .trailing_var_arg(true) .arg( script_arg().required(true), ) @@ -737,9 +735,9 @@ aarch64-apple-darwin target is not supported in canary. ) } -fn completions_subcommand<'a>() -> App<'a> { - App::new("completions") - .setting(AppSettings::DisableHelpSubcommand) +fn completions_subcommand<'a>() -> Command<'a> { + Command::new("completions") + .disable_help_subcommand(true) .arg( Arg::new("shell") .possible_values(&["bash", "fish", "powershell", "zsh", "fig"]) @@ -754,8 +752,8 @@ fn completions_subcommand<'a>() -> App<'a> { ) } -fn coverage_subcommand<'a>() -> App<'a> { - App::new("coverage") +fn coverage_subcommand<'a>() -> Command<'a> { + Command::new("coverage") .about("Print coverage reports") .long_about( "Print coverage reports from coverage profiles. @@ -794,7 +792,7 @@ Generate html reports from lcov: Arg::new("ignore") .long("ignore") .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .help("Ignore coverage files") .value_hint(ValueHint::AnyPath), @@ -850,8 +848,8 @@ If no --output arg is specified then the report is written to stdout." ) } -fn doc_subcommand<'a>() -> App<'a> { - App::new("doc") +fn doc_subcommand<'a>() -> Command<'a> { + Command::new("doc") .about("Show documentation for a module") .long_about( "Show documentation for a module. @@ -895,7 +893,7 @@ Show documentation for runtime built-ins: // https://github.com/clap-rs/clap/issues/1794. Currently `--builtin` is // just a possible value of `source_file` so leading hyphens must be // enabled. - .setting(clap::AppSettings::AllowHyphenValues) + .allow_hyphen_values(true) .arg( Arg::new("source_file") .takes_value(true) @@ -910,8 +908,8 @@ Show documentation for runtime built-ins: ) } -fn eval_subcommand<'a>() -> App<'a> { - runtime_args(App::new("eval"), false, true) +fn eval_subcommand<'a>() -> Command<'a> { + runtime_args(Command::new("eval"), false, true) .about("Eval script") .long_about( "Evaluate JavaScript from the command line. @@ -962,8 +960,8 @@ This command has implicit access to all permissions (--allow-all).", ) } -fn fmt_subcommand<'a>() -> App<'a> { - App::new("fmt") +fn fmt_subcommand<'a>() -> Command<'a> { + Command::new("fmt") .about("Format source files") .long_about( "Auto-format JavaScript, TypeScript, Markdown, and JSON files. @@ -1003,7 +1001,7 @@ Ignore formatting a file by adding an ignore comment at the top of the file: Arg::new("ignore") .long("ignore") .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .help("Ignore formatting particular source files") .value_hint(ValueHint::AnyPath), @@ -1061,8 +1059,8 @@ Ignore formatting a file by adding an ignore comment at the top of the file: ) } -fn info_subcommand<'a>() -> App<'a> { - App::new("info") +fn info_subcommand<'a>() -> Command<'a> { + Command::new("info") .about("Show info about cache or info related to source file") .long_about( "Information about a module or the cache directories. @@ -1103,9 +1101,9 @@ TypeScript compiler cache: Subdirectory containing TS compiler output.", ) } -fn install_subcommand<'a>() -> App<'a> { - runtime_args(App::new("install"), true, true) - .setting(AppSettings::TrailingVarArg) +fn install_subcommand<'a>() -> Command<'a> { + runtime_args(Command::new("install"), true, true) + .trailing_var_arg(true) .arg(Arg::new("cmd").required(true).multiple_values(true).value_hint(ValueHint::FilePath)) .arg( Arg::new("name") @@ -1159,9 +1157,9 @@ The installation root is determined, in order of precedence: These must be added to the path manually if required.") } -fn uninstall_subcommand<'a>() -> App<'a> { - App::new("uninstall") - .setting(AppSettings::TrailingVarArg) +fn uninstall_subcommand<'a>() -> Command<'a> { + Command::new("uninstall") + .trailing_var_arg(true) .arg( Arg::new("name") .required(true) @@ -1190,8 +1188,8 @@ The installation root is determined, in order of precedence: - $HOME/.deno") } -fn lsp_subcommand<'a>() -> App<'a> { - App::new("lsp") +fn lsp_subcommand<'a>() -> Command<'a> { + Command::new("lsp") .about("Start the language server") .long_about( "The 'deno lsp' subcommand provides a way for code editors and IDEs to @@ -1203,8 +1201,8 @@ How to connect various editors and IDEs to 'deno lsp': https://deno.land/manual/getting_started/setup_your_environment#editors-and-ides") } -fn lint_subcommand<'a>() -> App<'a> { - App::new("lint") +fn lint_subcommand<'a>() -> Command<'a> { + Command::new("lint") .about("Lint source files") .long_about( "Lint JavaScript/TypeScript source code. @@ -1244,7 +1242,7 @@ Ignore linting a file by adding an ignore comment at the top of the file: .long("rules-tags") .require_equals(true) .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .conflicts_with("rules") .help("Use set of rules with a tag"), ) @@ -1253,7 +1251,7 @@ Ignore linting a file by adding an ignore comment at the top of the file: .long("rules-include") .require_equals(true) .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .conflicts_with("rules") .help("Include lint rules"), ) @@ -1262,7 +1260,7 @@ Ignore linting a file by adding an ignore comment at the top of the file: .long("rules-exclude") .require_equals(true) .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .conflicts_with("rules") .help("Exclude lint rules"), ) @@ -1271,7 +1269,7 @@ Ignore linting a file by adding an ignore comment at the top of the file: Arg::new("ignore") .long("ignore") .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .help("Ignore linting particular source files") .value_hint(ValueHint::AnyPath), @@ -1294,8 +1292,8 @@ Ignore linting a file by adding an ignore comment at the top of the file: .arg(no_clear_screen_arg()) } -fn repl_subcommand<'a>() -> App<'a> { - runtime_args(App::new("repl"), false, true) +fn repl_subcommand<'a>() -> Command<'a> { + runtime_args(Command::new("repl"), false, true) .about("Read Eval Print Loop") .arg( Arg::new("eval") @@ -1307,15 +1305,15 @@ fn repl_subcommand<'a>() -> App<'a> { .arg(unsafely_ignore_certificate_errors_arg()) } -fn run_subcommand<'a>() -> App<'a> { - runtime_args(App::new("run"), true, true) +fn run_subcommand<'a>() -> Command<'a> { + runtime_args(Command::new("run"), true, true) .arg( watch_arg(true) .conflicts_with("inspect") .conflicts_with("inspect-brk"), ) .arg(no_clear_screen_arg()) - .setting(AppSettings::TrailingVarArg) + .trailing_var_arg(true) .arg(script_arg().required(true)) .about("Run a JavaScript or TypeScript program") .long_about( @@ -1344,9 +1342,9 @@ Deno allows specifying the filename '-' to read the file from stdin. ) } -fn task_subcommand<'a>() -> App<'a> { - App::new("task") - .setting(AppSettings::TrailingVarArg) +fn task_subcommand<'a>() -> Command<'a> { + Command::new("task") + .trailing_var_arg(true) .arg(config_arg()) .arg(Arg::new("task").help("Task to be executed")) .arg( @@ -1363,14 +1361,14 @@ fn task_subcommand<'a>() -> App<'a> { ) } -fn test_subcommand<'a>() -> App<'a> { - runtime_args(App::new("test"), true, true) - .setting(AppSettings::TrailingVarArg) +fn test_subcommand<'a>() -> Command<'a> { + runtime_args(Command::new("test"), true, true) + .trailing_var_arg(true) .arg( Arg::new("ignore") .long("ignore") .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .help("Ignore files") .value_hint(ValueHint::AnyPath), @@ -1416,7 +1414,7 @@ fn test_subcommand<'a>() -> App<'a> { ) .arg( Arg::new("filter") - .setting(ArgSettings::AllowHyphenValues) + .allow_hyphen_values(true) .long("filter") .takes_value(true) .help("Run tests with this string or pattern in the test name"), @@ -1489,8 +1487,8 @@ Directory arguments are expanded to all contained files matching the glob ) } -fn types_subcommand<'a>() -> App<'a> { - App::new("types") +fn types_subcommand<'a>() -> Command<'a> { + Command::new("types") .about("Print runtime TypeScript declarations") .long_about( "Print runtime TypeScript declarations. @@ -1501,8 +1499,8 @@ The declaration file could be saved and used for typing information.", ) } -fn upgrade_subcommand<'a>() -> App<'a> { - App::new("upgrade") +fn upgrade_subcommand<'a>() -> Command<'a> { + Command::new("upgrade") .about("Upgrade deno executable to given version") .long_about( "Upgrade deno executable to the given version. @@ -1549,8 +1547,8 @@ update to a different location, use the --output flag .arg(ca_file_arg()) } -fn vendor_subcommand<'a>() -> App<'a> { - App::new("vendor") +fn vendor_subcommand<'a>() -> Command<'a> { + Command::new("vendor") .about("Vendor remote modules into a local directory") .long_about( "Vendor remote modules into a local directory. @@ -1596,7 +1594,7 @@ Remote modules and multiple modules may also be specified: .arg(ca_file_arg()) } -fn compile_args(app: App) -> App { +fn compile_args(app: Command) -> Command { app .arg(import_map_arg()) .arg(no_remote_arg()) @@ -1608,14 +1606,14 @@ fn compile_args(app: App) -> App { .arg(ca_file_arg()) } -fn permission_args(app: App) -> App { +fn permission_args(app: Command) -> Command { app .arg( Arg::new("allow-read") .long("allow-read") .min_values(0) .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .help("Allow file system read access") .value_hint(ValueHint::AnyPath), @@ -1625,7 +1623,7 @@ fn permission_args(app: App) -> App { .long("allow-write") .min_values(0) .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .help("Allow file system write access") .value_hint(ValueHint::AnyPath), @@ -1635,7 +1633,7 @@ fn permission_args(app: App) -> App { .long("allow-net") .min_values(0) .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .help("Allow network access") .validator(crate::flags_allow_net::validator), @@ -1646,7 +1644,7 @@ fn permission_args(app: App) -> App { .long("allow-env") .min_values(0) .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .help("Allow environment access") .validator(|keys| { @@ -1663,7 +1661,7 @@ fn permission_args(app: App) -> App { .long("allow-run") .min_values(0) .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .help("Allow running subprocesses"), ) @@ -1672,7 +1670,7 @@ fn permission_args(app: App) -> App { .long("allow-ffi") .min_values(0) .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .help("Allow loading dynamic libraries") .value_hint(ValueHint::AnyPath), @@ -1698,7 +1696,11 @@ fn permission_args(app: App) -> App { ) } -fn runtime_args(app: App, include_perms: bool, include_inspector: bool) -> App { +fn runtime_args( + app: Command, + include_perms: bool, + include_inspector: bool, +) -> Command { let app = compile_args(app); let app = if include_perms { permission_args(app) @@ -1719,7 +1721,7 @@ fn runtime_args(app: App, include_perms: bool, include_inspector: bool) -> App { .arg(compat_arg()) } -fn inspect_args(app: App) -> App { +fn inspect_args(app: Command) -> Command { app .arg( Arg::new("inspect") @@ -1768,7 +1770,7 @@ fn reload_arg<'a>() -> Arg<'a> { .short('r') .min_values(0) .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .long("reload") .help("Reload source code cache (recompile TypeScript)") @@ -1833,7 +1835,7 @@ fn v8_flags_arg<'a>() -> Arg<'a> { Arg::new("v8-flags") .long("v8-flags") .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .help("Set V8 command line options (for help: --v8-flags=--help)") } @@ -1867,7 +1869,7 @@ fn watch_arg<'a>(takes_files: bool) -> Arg<'a> { .value_name("FILES") .min_values(0) .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .long_help( "UNSTABLE: Watch for file changes and restart process automatically. @@ -1968,7 +1970,7 @@ fn unsafely_ignore_certificate_errors_arg<'a>() -> Arg<'a> { .long("unsafely-ignore-certificate-errors") .min_values(0) .takes_value(true) - .use_delimiter(true) + .use_value_delimiter(true) .require_equals(true) .value_name("HOSTNAMES") .help("DANGER: Disables verification of TLS certificates") @@ -2075,7 +2077,7 @@ fn compile_parse(flags: &mut Flags, matches: &clap::ArgMatches) { fn completions_parse( flags: &mut Flags, matches: &clap::ArgMatches, - mut app: clap::App, + mut app: clap::Command, ) { use clap_complete::generate; use clap_complete::shells::{Bash, Fish, PowerShell, Zsh}; @@ -2845,9 +2847,9 @@ mod tests { #[test] fn version() { let r = flags_from_vec(svec!["deno", "--version"]); - assert_eq!(r.unwrap_err().kind, clap::ErrorKind::DisplayVersion); + assert_eq!(r.unwrap_err().kind(), clap::ErrorKind::DisplayVersion); let r = flags_from_vec(svec!["deno", "-V"]); - assert_eq!(r.unwrap_err().kind, clap::ErrorKind::DisplayVersion); + assert_eq!(r.unwrap_err().kind(), clap::ErrorKind::DisplayVersion); } #[test] @@ -5197,7 +5199,7 @@ mod tests { let error_message = r.unwrap_err().to_string(); assert!(&error_message .contains("error: The following required arguments were not provided:")); - assert!(&error_message.contains("--watch=<FILES>...")); + assert!(&error_message.contains("--watch[=<FILES>...]")); } #[test] diff --git a/cli/main.rs b/cli/main.rs index b1ab5bc8f..214b7c2fe 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -1469,8 +1469,8 @@ pub fn main() { let flags = match flags::flags_from_vec(args) { Ok(flags) => flags, Err(err @ clap::Error { .. }) - if err.kind == clap::ErrorKind::DisplayHelp - || err.kind == clap::ErrorKind::DisplayVersion => + if err.kind() == clap::ErrorKind::DisplayHelp + || err.kind() == clap::ErrorKind::DisplayVersion => { err.print().unwrap(); std::process::exit(0); |