1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

chore: update clap (#19467)

Also switches to use defer for all subcommands besides run.
This commit is contained in:
Leo Kettmeir 2023-06-12 13:54:04 +02:00 committed by GitHub
parent ea97af312f
commit e1be2bb80d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 747 additions and 660 deletions

93
Cargo.lock generated
View file

@ -108,6 +108,55 @@ dependencies = [
"alloc-no-stdlib", "alloc-no-stdlib",
] ]
[[package]]
name = "anstream"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is-terminal",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d"
[[package]]
name = "anstyle-parse"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "anstyle-wincon"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188"
dependencies = [
"anstyle",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.70" version = "1.0.70"
@ -474,31 +523,40 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.1.10" version = "4.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce38afc168d8665cfc75c7b1dd9672e50716a137f433f070991619744a67342a" checksum = "ca8f255e4b8027970e78db75e78831229c9815fdbfa67eb1a1b777a62e24b4a0"
dependencies = [ dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acd4f3c17c83b0ba34ffbc4f8bbd74f079413f747f84a6f89292f138057e36ab"
dependencies = [
"anstream",
"anstyle",
"bitflags 1.3.2", "bitflags 1.3.2",
"clap_lex", "clap_lex",
"is-terminal",
"strsim", "strsim",
"termcolor",
] ]
[[package]] [[package]]
name = "clap_complete" name = "clap_complete"
version = "4.1.5" version = "4.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37686beaba5ac9f3ab01ee3172f792fc6ffdd685bfb9e63cfef02c0571a4e8e1" checksum = "7f6b5c519bab3ea61843a7923d074b04245624bb84a64a8c150f5deb014e388b"
dependencies = [ dependencies = [
"clap", "clap",
] ]
[[package]] [[package]]
name = "clap_complete_fig" name = "clap_complete_fig"
version = "4.1.2" version = "4.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2171bc6242ad7a1801422bff039574449b5bd832b715222e500714ce10f91a54" checksum = "99fee1d30a51305a6c2ed3fc5709be3c8af626c9c958e04dd9ae94e27bcbce9f"
dependencies = [ dependencies = [
"clap", "clap",
"clap_complete", "clap_complete",
@ -506,12 +564,9 @@ dependencies = [
[[package]] [[package]]
name = "clap_lex" name = "clap_lex"
version = "0.3.3" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "033f6b7a4acb1f358c742aaca805c939ee73b4c6209ae4318ec7aca81c42e646" checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
dependencies = [
"os_str_bytes",
]
[[package]] [[package]]
name = "clipboard-win" name = "clipboard-win"
@ -524,6 +579,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]] [[package]]
name = "console_static_text" name = "console_static_text"
version = "0.8.1" version = "0.8.1"
@ -3219,12 +3280,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "os_str_bytes"
version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]] [[package]]
name = "output_vt100" name = "output_vt100"
version = "0.1.3" version = "0.1.3"

View file

@ -60,9 +60,9 @@ base32 = "=0.4.0"
base64.workspace = true base64.workspace = true
cache_control.workspace = true cache_control.workspace = true
chrono = { version = "=0.4.22", default-features = false, features = ["std"] } chrono = { version = "=0.4.22", default-features = false, features = ["std"] }
clap = { version = "=4.1.10", features = ["string"] } clap = { version = "=4.3.3", features = ["string"] }
clap_complete = "=4.1.5" clap_complete = "=4.3.1"
clap_complete_fig = "=4.1.2" clap_complete_fig = "=4.3.1"
console_static_text.workspace = true console_static_text.workspace = true
data-url.workspace = true data-url.workspace = true
dissimilar = "=1.0.4" dissimilar = "=1.0.4"

View file

@ -759,6 +759,9 @@ fn clap_root() -> Command {
.action(ArgAction::SetTrue) .action(ArgAction::SetTrue)
.global(true), .global(true),
) )
.subcommand(run_subcommand())
.defer(|cmd| {
cmd
.subcommand(bench_subcommand()) .subcommand(bench_subcommand())
.subcommand(bundle_subcommand()) .subcommand(bundle_subcommand())
.subcommand(cache_subcommand()) .subcommand(cache_subcommand())
@ -776,18 +779,19 @@ fn clap_root() -> Command {
.subcommand(lsp_subcommand()) .subcommand(lsp_subcommand())
.subcommand(lint_subcommand()) .subcommand(lint_subcommand())
.subcommand(repl_subcommand()) .subcommand(repl_subcommand())
.subcommand(run_subcommand())
.subcommand(task_subcommand()) .subcommand(task_subcommand())
.subcommand(test_subcommand()) .subcommand(test_subcommand())
.subcommand(types_subcommand()) .subcommand(types_subcommand())
.subcommand(upgrade_subcommand()) .subcommand(upgrade_subcommand())
.subcommand(vendor_subcommand()) .subcommand(vendor_subcommand())
})
.long_about(DENO_HELP) .long_about(DENO_HELP)
.after_help(ENV_VARIABLES_HELP) .after_help(ENV_VARIABLES_HELP)
} }
fn bench_subcommand() -> Command { fn bench_subcommand() -> Command {
runtime_args(Command::new("bench"), true, false) Command::new("bench").defer(|cmd| {
runtime_args(cmd, true, false)
.arg(check_arg(true)) .arg(check_arg(true))
.arg( .arg(
Arg::new("json") Arg::new("json")
@ -840,10 +844,12 @@ glob {*_,*.,}bench.{js,mjs,ts,mts,jsx,tsx}:
deno bench src/", deno bench src/",
) )
})
} }
fn bundle_subcommand() -> Command { fn bundle_subcommand() -> Command {
compile_args(Command::new("bundle")) Command::new("bundle").defer(|cmd| {
compile_args(cmd)
.hide(true) .hide(true)
.arg(check_arg(true)) .arg(check_arg(true))
.arg( .arg(
@ -869,10 +875,12 @@ If no output file is given, the output is written to standard output:
deno bundle https://deno.land/std/examples/colors.ts", deno bundle https://deno.land/std/examples/colors.ts",
) )
})
} }
fn cache_subcommand() -> Command { fn cache_subcommand() -> Command {
compile_args(Command::new("cache")) Command::new("cache").defer(|cmd| {
compile_args(cmd)
.arg(check_arg(false)) .arg(check_arg(false))
.arg( .arg(
Arg::new("file") Arg::new("file")
@ -892,11 +900,12 @@ them in the local cache, without running any code:
Future runs of this module will trigger no downloads or compilation unless Future runs of this module will trigger no downloads or compilation unless
--reload is specified.", --reload is specified.",
) )
})
} }
fn check_subcommand() -> Command { fn check_subcommand() -> Command {
compile_args_without_check_args(Command::new("check")) Command::new("check")
.arg( .defer(|cmd| compile_args_without_check_args(cmd).arg(
Arg::new("all") Arg::new("all")
.long("all") .long("all")
.help("Type-check all code, including remote modules and npm packages") .help("Type-check all code, including remote modules and npm packages")
@ -925,11 +934,12 @@ fn check_subcommand() -> Command {
deno check https://deno.land/std/http/file_server.ts deno check https://deno.land/std/http/file_server.ts
Unless --reload is specified, this command will not re-download already cached dependencies.", Unless --reload is specified, this command will not re-download already cached dependencies.",
) ))
} }
fn compile_subcommand() -> Command { fn compile_subcommand() -> Command {
runtime_args(Command::new("compile"), true, false) Command::new("compile").defer(|cmd| {
runtime_args(cmd, true, false)
.arg(script_arg().required(true)) .arg(script_arg().required(true))
.arg(check_arg(true)) .arg(check_arg(true))
.arg( .arg(
@ -988,10 +998,12 @@ binary and cache it in $DENO_DIR. The aarch64-apple-darwin target is not
supported in canary. supported in canary.
", ",
) )
})
} }
fn completions_subcommand() -> Command { fn completions_subcommand() -> Command {
Command::new("completions") Command::new("completions").defer(|cmd| {
cmd
.disable_help_subcommand(true) .disable_help_subcommand(true)
.arg( .arg(
Arg::new("shell") Arg::new("shell")
@ -1005,10 +1017,12 @@ fn completions_subcommand() -> Command {
deno completions bash > /usr/local/etc/bash_completion.d/deno.bash deno completions bash > /usr/local/etc/bash_completion.d/deno.bash
source /usr/local/etc/bash_completion.d/deno.bash", source /usr/local/etc/bash_completion.d/deno.bash",
) )
})
} }
fn coverage_subcommand() -> Command { fn coverage_subcommand() -> Command {
Command::new("coverage") Command::new("coverage").defer(|cmd| {
cmd
.about("Print coverage reports") .about("Print coverage reports")
.long_about( .long_about(
"Print coverage reports from coverage profiles. "Print coverage reports from coverage profiles.
@ -1101,10 +1115,12 @@ Generate html reports from lcov:
.required(true) .required(true)
.value_hint(ValueHint::AnyPath), .value_hint(ValueHint::AnyPath),
) )
})
} }
fn doc_subcommand() -> Command { fn doc_subcommand() -> Command {
Command::new("doc") Command::new("doc").defer(|cmd| {
cmd
.about("Show documentation for a module") .about("Show documentation for a module")
.long_about( .long_about(
"Show documentation for a module. "Show documentation for a module.
@ -1160,10 +1176,12 @@ Show documentation for runtime built-ins:
.required(false) .required(false)
.conflicts_with("json"), .conflicts_with("json"),
) )
})
} }
fn eval_subcommand() -> Command { fn eval_subcommand() -> Command {
runtime_args(Command::new("eval"), false, true) Command::new("eval").defer(|cmd| {
runtime_args(cmd, false, true)
.about("Eval script") .about("Eval script")
.long_about( .long_about(
"Evaluate JavaScript from the command line. "Evaluate JavaScript from the command line.
@ -1203,10 +1221,12 @@ This command has implicit access to all permissions (--allow-all).",
.value_name("CODE_ARG") .value_name("CODE_ARG")
.required(true), .required(true),
) )
})
} }
fn fmt_subcommand() -> Command { fn fmt_subcommand() -> Command {
Command::new("fmt") Command::new("fmt").defer(|cmd| {
cmd
.about("Format source files") .about("Format source files")
.long_about( .long_about(
"Auto-format JavaScript, TypeScript, Markdown, and JSON files. "Auto-format JavaScript, TypeScript, Markdown, and JSON files.
@ -1271,7 +1291,9 @@ Ignore formatting a file by adding an ignore comment at the top of the file:
.value_parser(value_parser!(bool)) .value_parser(value_parser!(bool))
.default_missing_value("true") .default_missing_value("true")
.require_equals(true) .require_equals(true)
.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("line-width") Arg::new("line-width")
@ -1314,19 +1336,22 @@ Ignore formatting a file by adding an ignore comment at the top of the file:
.require_equals(true) .require_equals(true)
.help("Don't use semicolons except where necessary."), .help("Don't use semicolons except where necessary."),
) )
})
} }
fn init_subcommand() -> Command { fn init_subcommand() -> Command {
Command::new("init").about("Initialize a new project").arg( Command::new("init").defer(|cmd| {
cmd.about("Initialize a new project").arg(
Arg::new("dir") Arg::new("dir")
.required(false) .required(false)
.value_hint(ValueHint::DirPath), .value_hint(ValueHint::DirPath),
) )
})
} }
fn info_subcommand() -> Command { fn info_subcommand() -> Command {
Command::new("info") Command::new("info")
.about("Show info about cache or info related to source file") .defer(|cmd| cmd.about("Show info about cache or info related to source file")
.long_about( .long_about(
"Information about a module or the cache directories. "Information about a module or the cache directories.
@ -1369,12 +1394,12 @@ TypeScript compiler cache: Subdirectory containing TS compiler output.",
.long("json") .long("json")
.help("UNSTABLE: Outputs the information in JSON format") .help("UNSTABLE: Outputs the information in JSON format")
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) ))
} }
fn install_subcommand() -> Command { fn install_subcommand() -> Command {
runtime_args(Command::new("install"), true, true) Command::new("install")
.arg(Arg::new("cmd").required(true).num_args(1..).value_hint(ValueHint::FilePath)) .defer(|cmd| runtime_args(cmd, true, true).arg(Arg::new("cmd").required(true).num_args(1..).value_hint(ValueHint::FilePath))
.arg(check_arg(true)) .arg(check_arg(true))
.arg( .arg(
Arg::new("name") Arg::new("name")
@ -1422,12 +1447,12 @@ The installation root is determined, in order of precedence:
- DENO_INSTALL_ROOT environment variable - DENO_INSTALL_ROOT environment variable
- $HOME/.deno - $HOME/.deno
These must be added to the path manually if required.") These must be added to the path manually if required."))
} }
fn uninstall_subcommand() -> Command { fn uninstall_subcommand() -> Command {
Command::new("uninstall") Command::new("uninstall")
.arg(Arg::new("name").required(true)) .defer(|cmd| cmd.arg(Arg::new("name").required(true))
.arg( .arg(
Arg::new("root") Arg::new("root")
.long("root") .long("root")
@ -1447,7 +1472,7 @@ To change the installation root, use --root:
The installation root is determined, in order of precedence: The installation root is determined, in order of precedence:
- --root option - --root option
- DENO_INSTALL_ROOT environment variable - DENO_INSTALL_ROOT environment variable
- $HOME/.deno") - $HOME/.deno"))
} }
static LSP_HELP: &str = concat!( static LSP_HELP: &str = concat!(
@ -1464,12 +1489,12 @@ https://deno.land/manual@v",
fn lsp_subcommand() -> Command { fn lsp_subcommand() -> Command {
Command::new("lsp") Command::new("lsp")
.about("Start the language server") .defer(|cmd| cmd.about("Start the language server").long_about(LSP_HELP))
.long_about(LSP_HELP)
} }
fn lint_subcommand() -> Command { fn lint_subcommand() -> Command {
Command::new("lint") Command::new("lint").defer(|cmd| {
cmd
.about("Lint source files") .about("Lint source files")
.long_about( .long_about(
"Lint JavaScript/TypeScript source code. "Lint JavaScript/TypeScript source code.
@ -1572,11 +1597,12 @@ Ignore linting 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())
})
} }
fn repl_subcommand() -> Command { fn repl_subcommand() -> Command {
runtime_args(Command::new("repl"), true, true) Command::new("repl")
.about("Read Eval Print Loop") .defer(|cmd| runtime_args(cmd, true, true).about("Read Eval Print Loop")
.arg(check_arg(false)) .arg(check_arg(false))
.arg( .arg(
Arg::new("eval-file") Arg::new("eval-file")
@ -1592,7 +1618,7 @@ fn repl_subcommand() -> Command {
.long("eval") .long("eval")
.help("Evaluates the provided code when the REPL starts.") .help("Evaluates the provided code when the REPL starts.")
.value_name("code"), .value_name("code"),
) ))
} }
fn run_subcommand() -> Command { fn run_subcommand() -> Command {
@ -1639,7 +1665,8 @@ Specifying the filename '-' to read the file from stdin.
} }
fn task_subcommand() -> Command { fn task_subcommand() -> Command {
Command::new("task") Command::new("task").defer(|cmd| {
cmd
.allow_external_subcommands(true) .allow_external_subcommands(true)
.subcommand_value_name("TASK") .subcommand_value_name("TASK")
.arg(config_arg()) .arg(config_arg())
@ -1656,10 +1683,11 @@ fn task_subcommand() -> Command {
deno task build", deno task build",
) )
})
} }
fn test_subcommand() -> Command { fn test_subcommand() -> Command {
runtime_args(Command::new("test"), true, true) Command::new("test").defer(|cmd| runtime_args(cmd, true, true)
.arg(check_arg(true)) .arg(check_arg(true))
.arg( .arg(
Arg::new("ignore") Arg::new("ignore")
@ -1774,11 +1802,12 @@ Directory arguments are expanded to all contained files matching the glob
{*_,*.,}test.{js,mjs,ts,mts,jsx,tsx}: {*_,*.,}test.{js,mjs,ts,mts,jsx,tsx}:
deno test src/", deno test src/",
) ))
} }
fn types_subcommand() -> Command { fn types_subcommand() -> Command {
Command::new("types") Command::new("types").defer(|cmd| {
cmd
.about("Print runtime TypeScript declarations") .about("Print runtime TypeScript declarations")
.long_about( .long_about(
"Print runtime TypeScript declarations. "Print runtime TypeScript declarations.
@ -1787,10 +1816,12 @@ fn types_subcommand() -> Command {
The declaration file could be saved and used for typing information.", The declaration file could be saved and used for typing information.",
) )
})
} }
fn upgrade_subcommand() -> Command { fn upgrade_subcommand() -> Command {
Command::new("upgrade") Command::new("upgrade").defer(|cmd| {
cmd
.about("Upgrade deno executable to given version") .about("Upgrade deno executable to given version")
.long_about( .long_about(
"Upgrade deno executable to the given version. "Upgrade deno executable to the given version.
@ -1837,11 +1868,12 @@ update to a different location, use the --output flag
.action(ArgAction::SetTrue), .action(ArgAction::SetTrue),
) )
.arg(ca_file_arg()) .arg(ca_file_arg())
})
} }
fn vendor_subcommand() -> Command { fn vendor_subcommand() -> Command {
Command::new("vendor") Command::new("vendor")
.about("Vendor remote modules into a local directory") .defer(|cmd| cmd.about("Vendor remote modules into a local directory")
.long_about( .long_about(
"Vendor remote modules into a local directory. "Vendor remote modules into a local directory.
@ -1884,7 +1916,7 @@ Remote modules and multiple modules may also be specified:
.arg(lock_arg()) .arg(lock_arg())
.arg(node_modules_dir_arg()) .arg(node_modules_dir_arg())
.arg(reload_arg()) .arg(reload_arg())
.arg(ca_file_arg()) .arg(ca_file_arg()))
} }
fn compile_args(app: Command) -> Command { fn compile_args(app: Command) -> Command {