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",
]
[[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]]
name = "anyhow"
version = "1.0.70"
@ -474,31 +523,40 @@ dependencies = [
[[package]]
name = "clap"
version = "4.1.10"
version = "4.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce38afc168d8665cfc75c7b1dd9672e50716a137f433f070991619744a67342a"
checksum = "ca8f255e4b8027970e78db75e78831229c9815fdbfa67eb1a1b777a62e24b4a0"
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",
"clap_lex",
"is-terminal",
"strsim",
"termcolor",
]
[[package]]
name = "clap_complete"
version = "4.1.5"
version = "4.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37686beaba5ac9f3ab01ee3172f792fc6ffdd685bfb9e63cfef02c0571a4e8e1"
checksum = "7f6b5c519bab3ea61843a7923d074b04245624bb84a64a8c150f5deb014e388b"
dependencies = [
"clap",
]
[[package]]
name = "clap_complete_fig"
version = "4.1.2"
version = "4.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2171bc6242ad7a1801422bff039574449b5bd832b715222e500714ce10f91a54"
checksum = "99fee1d30a51305a6c2ed3fc5709be3c8af626c9c958e04dd9ae94e27bcbce9f"
dependencies = [
"clap",
"clap_complete",
@ -506,12 +564,9 @@ dependencies = [
[[package]]
name = "clap_lex"
version = "0.3.3"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "033f6b7a4acb1f358c742aaca805c939ee73b4c6209ae4318ec7aca81c42e646"
dependencies = [
"os_str_bytes",
]
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
[[package]]
name = "clipboard-win"
@ -524,6 +579,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "console_static_text"
version = "0.8.1"
@ -3219,12 +3280,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "os_str_bytes"
version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
name = "output_vt100"
version = "0.1.3"

View file

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

View file

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