diff --git a/CHANGELOG.md b/CHANGELOG.md index 930897855df..1918c1a430c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate +## [4.3.18] - 2023-07-21 + +### Fixes + +- *(parse)* Suggest `--` in fewer places where it won't work + ## [4.3.17] - 2023-07-19 ### Fixes @@ -4371,7 +4377,8 @@ Minimum version of Rust is now v1.13.0 (Stable) * **arg** allow lifetimes other than 'static in arguments ([9e8c1fb9](https://github.com/clap-rs/clap/commit/9e8c1fb9406f8448873ca58bab07fe905f1551e5)) -[Unreleased]: https://github.com/clap-rs/clap/compare/v4.3.17...HEAD +[Unreleased]: https://github.com/clap-rs/clap/compare/v4.3.18...HEAD +[4.3.18]: https://github.com/clap-rs/clap/compare/v4.3.17...v4.3.18 [4.3.17]: https://github.com/clap-rs/clap/compare/v4.3.16...v4.3.17 [4.3.16]: https://github.com/clap-rs/clap/compare/v4.3.15...v4.3.16 [4.3.15]: https://github.com/clap-rs/clap/compare/v4.3.14...v4.3.15 diff --git a/CITATION.cff b/CITATION.cff index fbfca465b0a..cef0e12f376 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -3,8 +3,8 @@ cff-version: 1.2.0 message: Please cite this crate using these information. # Version information. -date-released: 2023-07-19 -version: 4.3.17 +date-released: 2023-07-21 +version: 4.3.18 # Project information. abstract: A full featured, fast Command Line Argument Parser for Rust diff --git a/Cargo.lock b/Cargo.lock index 45313e62b7b..a379e4641db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,7 +104,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "220044e6a1bb31ddee4e3db724d29767f352de47445a6cd75e1a173142136c83" dependencies = [ "nom", - "vte", + "vte 0.10.1", ] [[package]] @@ -481,9 +481,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.17" +version = "4.3.18" dependencies = [ - "clap_builder 4.3.17", + "clap_builder 4.3.18", "clap_derive", "humantime", "once_cell", @@ -500,7 +500,7 @@ dependencies = [ name = "clap_bench" version = "0.0.0" dependencies = [ - "clap 4.3.17", + "clap 4.3.18", "criterion", "lazy_static", ] @@ -518,7 +518,7 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.3.17" +version = "4.3.18" dependencies = [ "anstream", "anstyle", @@ -544,8 +544,9 @@ dependencies = [ name = "clap_complete" version = "4.3.2" dependencies = [ - "clap 4.3.17", + "clap 4.3.18", "clap_lex 0.5.0", + "completest", "is_executable", "pathdiff", "shlex", @@ -558,7 +559,7 @@ dependencies = [ name = "clap_complete_fig" version = "4.3.1" dependencies = [ - "clap 4.3.17", + "clap 4.3.18", "clap_complete", "snapbox", ] @@ -567,7 +568,7 @@ dependencies = [ name = "clap_complete_nushell" version = "4.3.1" dependencies = [ - "clap 4.3.17", + "clap 4.3.18", "clap_complete", "nu-cli", "nu-command", @@ -602,7 +603,7 @@ checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" name = "clap_mangen" version = "0.2.12" dependencies = [ - "clap 4.3.17", + "clap 4.3.18", "roff", "snapbox", ] @@ -643,6 +644,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "completest" +version = "0.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5c57cc5ce58820d1da6538531606500422d4c9cbaea47f6a14d9ed96717a8b" +dependencies = [ + "ptyprocess", + "vte 0.11.1", +] + [[package]] name = "console" version = "0.15.7" @@ -676,6 +687,15 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "content_inspector" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7bda66e858c683005a53a9a60c69a4aca7eeaa45d124526e389f7aec8e62f38" +dependencies = [ + "memchr", +] + [[package]] name = "core-foundation" version = "0.9.3" @@ -776,7 +796,7 @@ dependencies = [ "autocfg", "cfg-if 1.0.0", "crossbeam-utils", - "memoffset", + "memoffset 0.6.5", "scopeguard", ] @@ -915,6 +935,12 @@ dependencies = [ "rust_decimal", ] +[[package]] +name = "dunce" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" + [[package]] name = "either" version = "1.8.0" @@ -1481,9 +1507,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.4" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "joinery" @@ -1667,6 +1693,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memoffset" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +dependencies = [ + "autocfg", +] + [[package]] name = "miette" version = "5.9.0" @@ -1830,6 +1865,8 @@ dependencies = [ "bitflags 1.3.2", "cfg-if 1.0.0", "libc", + "memoffset 0.7.1", + "pin-utils", "static_assertions", ] @@ -2556,6 +2593,12 @@ dependencies = [ "siphasher", ] +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkg-config" version = "0.3.27" @@ -2683,6 +2726,15 @@ dependencies = [ "rustix 0.36.4", ] +[[package]] +name = "ptyprocess" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e05aef7befb11a210468a2d77d978dde2c6381a0381e33beb575e91f57fe8cf" +dependencies = [ + "nix", +] + [[package]] name = "pure-rust-locales" version = "0.5.6" @@ -3208,13 +3260,18 @@ checksum = "f6bccd62078347f89a914e3004d94582e13824d4e3d8a816317862884c423835" dependencies = [ "anstream", "anstyle", + "content_inspector", + "dunce", "escargot", + "filetime", "libc", "normalize-line-endings", "os_pipe", "similar", "snapbox-macros", + "tempfile", "wait-timeout", + "walkdir", "windows-sys 0.45.0", ] @@ -3239,7 +3296,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "011cbb39cf7c1f62871aea3cc46e5817b0937b49e9447370c93cacbe93a766d8" dependencies = [ - "vte", + "vte 0.10.1", ] [[package]] @@ -3843,6 +3900,18 @@ dependencies = [ "vte_generate_state_changes", ] +[[package]] +name = "vte" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5022b5fbf9407086c180e9557be968742d839e68346af7792b8592489732197" +dependencies = [ + "arrayvec 0.7.2", + "log", + "utf8parse", + "vte_generate_state_changes", +] + [[package]] name = "vte_generate_state_changes" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index e39a028f2f0..d7409c6d85f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ include = [ [package] name = "clap" -version = "4.3.17" +version = "4.3.18" description = "A simple to use, efficient, and full-featured Command Line Argument Parser" repository = "https://github.com/clap-rs/clap" categories = ["command-line-interface"] @@ -101,7 +101,7 @@ unstable-styles = ["clap_builder/unstable-styles"] bench = false [dependencies] -clap_builder = { path = "./clap_builder", version = "=4.3.17", default-features = false } +clap_builder = { path = "./clap_builder", version = "=4.3.18", default-features = false } clap_derive = { path = "./clap_derive", version = "=4.3.12", optional = true } once_cell = { version = "1.12.0", optional = true } diff --git a/clap_builder/Cargo.toml b/clap_builder/Cargo.toml index bcfd377f597..7608b3d0b0c 100644 --- a/clap_builder/Cargo.toml +++ b/clap_builder/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clap_builder" -version = "4.3.17" +version = "4.3.18" description = "A simple to use, efficient, and full-featured Command Line Argument Parser" repository = "https://github.com/clap-rs/clap" categories = ["command-line-interface"] diff --git a/clap_builder/src/error/mod.rs b/clap_builder/src/error/mod.rs index 210a1717f1f..772058a5fe9 100644 --- a/clap_builder/src/error/mod.rs +++ b/clap_builder/src/error/mod.rs @@ -446,6 +446,7 @@ impl Error { subcmd: String, did_you_mean: Vec, name: String, + suggested_trailing_arg: bool, usage: Option, ) -> Self { use std::fmt::Write as _; @@ -456,15 +457,19 @@ impl Error { #[cfg(feature = "error-context")] { - let mut styled_suggestion = StyledStr::new(); - let _ = write!( - styled_suggestion, - "to pass '{}{subcmd}{}' as a value, use '{}{name} -- {subcmd}{}'", - invalid.render(), - invalid.render_reset(), - valid.render(), - valid.render_reset() - ); + let mut suggestions = vec![]; + if suggested_trailing_arg { + let mut styled_suggestion = StyledStr::new(); + let _ = write!( + styled_suggestion, + "to pass '{}{subcmd}{}' as a value, use '{}{name} -- {subcmd}{}'", + invalid.render(), + invalid.render_reset(), + valid.render(), + valid.render_reset() + ); + suggestions.push(styled_suggestion); + } err = err.extend_context_unchecked([ (ContextKind::InvalidSubcommand, ContextValue::String(subcmd)), @@ -474,7 +479,7 @@ impl Error { ), ( ContextKind::Suggested, - ContextValue::StyledStrs(vec![styled_suggestion]), + ContextValue::StyledStrs(suggestions), ), ]); if let Some(usage) = usage { diff --git a/clap_builder/src/parser/parser.rs b/clap_builder/src/parser/parser.rs index 3e02d4c0bf7..a4e15fef49d 100644 --- a/clap_builder/src/parser/parser.rs +++ b/clap_builder/src/parser/parser.rs @@ -474,6 +474,10 @@ impl<'cmd> Parser<'cmd> { } } + let suggested_trailing_arg = !trailing_values + && self.cmd.has_positionals() + && (arg_os.is_long() || arg_os.is_short()); + if !(self.cmd.is_args_conflicts_with_subcommands_set() && valid_arg_found) { let candidates = suggestions::did_you_mean( &arg_os.display().to_string(), @@ -489,6 +493,7 @@ impl<'cmd> Parser<'cmd> { .get_bin_name() .unwrap_or_else(|| self.cmd.get_name()) .to_owned(), + suggested_trailing_arg, Usage::new(self.cmd).create_usage_with_title(&[]), ); } @@ -505,9 +510,6 @@ impl<'cmd> Parser<'cmd> { } } - let suggested_trailing_arg = !trailing_values - && self.cmd.has_positionals() - && (arg_os.is_long() || arg_os.is_short()); ClapError::unknown_argument( self.cmd, arg_os.display().to_string(), diff --git a/clap_complete/Cargo.toml b/clap_complete/Cargo.toml index 6bb5f1aa1a6..3eb2cb5d877 100644 --- a/clap_complete/Cargo.toml +++ b/clap_complete/Cargo.toml @@ -40,9 +40,10 @@ shlex = { version = "1.1.0", optional = true } unicode-xid = { version = "0.2.2", optional = true } [dev-dependencies] -snapbox = { version = "0.4.11", features = ["diff"] } +snapbox = { version = "0.4.11", features = ["diff", "path", "examples"] } # Cutting out `filesystem` feature trycmd = { version = "0.14.16", default-features = false, features = ["color-auto", "diff", "examples"] } +completest = "0.0.11" clap = { path = "../", version = "4.0.0", default-features = false, features = ["std", "derive", "help"] } [[example]] diff --git a/clap_complete/examples/test.rs b/clap_complete/examples/test.rs new file mode 100644 index 00000000000..8129fb03cbc --- /dev/null +++ b/clap_complete/examples/test.rs @@ -0,0 +1,177 @@ +use clap_complete::{generate, Generator, Shell}; + +fn main() { + let matches = cli().get_matches(); + if let Some(generator) = matches.get_one::("generate") { + let mut cmd = cli(); + eprintln!("Generating completion file for {generator}..."); + print_completions(*generator, &mut cmd); + } else { + println!("{:?}", matches); + } +} + +fn print_completions(gen: G, cmd: &mut clap::Command) { + generate(gen, cmd, cmd.get_name().to_string(), &mut std::io::stdout()); +} + +fn cli() -> clap::Command { + clap::Command::new("test") + .version("3.0") + .propagate_version(true) + .args([ + clap::Arg::new("global") + .long("global") + .global(true) + .action(clap::ArgAction::SetTrue) + .help("everywhere"), + clap::Arg::new("generate") + .long("generate") + .value_parser(clap::value_parser!(Shell)) + .help("generate"), + ]) + .subcommands([ + clap::Command::new("action").args([ + clap::Arg::new("set-true") + .long("set-true") + .action(clap::ArgAction::SetTrue) + .help("bool"), + clap::Arg::new("set") + .long("set") + .action(clap::ArgAction::Set) + .help("value"), + clap::Arg::new("count") + .long("count") + .action(clap::ArgAction::Count) + .help("number"), + clap::Arg::new("choice") + .long("choice") + .value_parser(["first", "second"]) + .help("enum"), + ]), + clap::Command::new("quote") + .args([ + clap::Arg::new("single-quotes") + .long("single-quotes") + .action(clap::ArgAction::SetTrue) + .help("Can be 'always', 'auto', or 'never'"), + clap::Arg::new("double-quotes") + .long("double-quotes") + .action(clap::ArgAction::SetTrue) + .help("Can be \"always\", \"auto\", or \"never\""), + clap::Arg::new("backticks") + .long("backticks") + .action(clap::ArgAction::SetTrue) + .help("For more information see `echo test`"), + clap::Arg::new("backslash") + .long("backslash") + .action(clap::ArgAction::SetTrue) + .help("Avoid '\\n'"), + clap::Arg::new("brackets") + .long("brackets") + .action(clap::ArgAction::SetTrue) + .help("List packages [filter]"), + clap::Arg::new("expansions") + .long("expansions") + .action(clap::ArgAction::SetTrue) + .help("Execute the shell command with $SHELL"), + ]) + .subcommands([ + clap::Command::new("cmd-single-quotes") + .about("Can be 'always', 'auto', or 'never'"), + clap::Command::new("cmd-double-quotes") + .about("Can be \"always\", \"auto\", or \"never\""), + clap::Command::new("cmd-backticks") + .about("For more information see `echo test`"), + clap::Command::new("cmd-backslash").about("Avoid '\\n'"), + clap::Command::new("cmd-brackets").about("List packages [filter]"), + clap::Command::new("cmd-expansions") + .about("Execute the shell command with $SHELL"), + ]), + clap::Command::new("value").args([ + clap::Arg::new("delim").long("delim").value_delimiter(','), + clap::Arg::new("tuple").long("tuple").num_args(2), + clap::Arg::new("require-eq") + .long("require-eq") + .require_equals(true), + clap::Arg::new("term").num_args(1..).value_terminator(";"), + ]), + clap::Command::new("pacman").subcommands([ + clap::Command::new("one").long_flag("one").short_flag('o'), + clap::Command::new("two").long_flag("two").short_flag('t'), + ]), + clap::Command::new("last") + .args([clap::Arg::new("first"), clap::Arg::new("free").last(true)]), + clap::Command::new("alias").args([ + clap::Arg::new("flag") + .short('f') + .visible_short_alias('F') + .long("flag") + .action(clap::ArgAction::SetTrue) + .visible_alias("flg") + .help("cmd flag"), + clap::Arg::new("option") + .short('o') + .visible_short_alias('O') + .long("option") + .visible_alias("opt") + .help("cmd option") + .action(clap::ArgAction::Set), + clap::Arg::new("positional"), + ]), + clap::Command::new("hint").args([ + clap::Arg::new("choice") + .long("choice") + .action(clap::ArgAction::Set) + .value_parser(["bash", "fish", "zsh"]), + clap::Arg::new("unknown") + .long("unknown") + .value_hint(clap::ValueHint::Unknown), + clap::Arg::new("other") + .long("other") + .value_hint(clap::ValueHint::Other), + clap::Arg::new("path") + .long("path") + .short('p') + .value_hint(clap::ValueHint::AnyPath), + clap::Arg::new("file") + .long("file") + .short('f') + .value_hint(clap::ValueHint::FilePath), + clap::Arg::new("dir") + .long("dir") + .short('d') + .value_hint(clap::ValueHint::DirPath), + clap::Arg::new("exe") + .long("exe") + .short('e') + .value_hint(clap::ValueHint::ExecutablePath), + clap::Arg::new("cmd_name") + .long("cmd-name") + .value_hint(clap::ValueHint::CommandName), + clap::Arg::new("cmd") + .long("cmd") + .short('c') + .value_hint(clap::ValueHint::CommandString), + clap::Arg::new("command_with_args") + .action(clap::ArgAction::Set) + .num_args(1..) + .trailing_var_arg(true) + .value_hint(clap::ValueHint::CommandWithArguments), + clap::Arg::new("user") + .short('u') + .long("user") + .value_hint(clap::ValueHint::Username), + clap::Arg::new("host") + .short('H') + .long("host") + .value_hint(clap::ValueHint::Hostname), + clap::Arg::new("url") + .long("url") + .value_hint(clap::ValueHint::Url), + clap::Arg::new("email") + .long("email") + .value_hint(clap::ValueHint::EmailAddress), + ]), + ]) +} diff --git a/clap_complete/src/shells/bash.rs b/clap_complete/src/shells/bash.rs index 60e6b346cd4..2a97e1de2fe 100644 --- a/clap_complete/src/shells/bash.rs +++ b/clap_complete/src/shells/bash.rs @@ -58,7 +58,7 @@ impl Generator for Bash { esac }} -complete -F _{name} -o bashdefault -o default {name} +complete -F _{name} -o nosort -o bashdefault -o default {name} ", name = bin_name, cmd = bin_name.replace('-', "__"), diff --git a/clap_complete/tests/snapshots/aliases.bash b/clap_complete/tests/snapshots/aliases.bash index 5eb51c82625..15651587242 100644 --- a/clap_complete/tests/snapshots/aliases.bash +++ b/clap_complete/tests/snapshots/aliases.bash @@ -51,4 +51,4 @@ _my-app() { esac } -complete -F _my-app -o bashdefault -o default my-app +complete -F _my-app -o nosort -o bashdefault -o default my-app diff --git a/clap_complete/tests/snapshots/basic.bash b/clap_complete/tests/snapshots/basic.bash index b381b977b9b..6ccd2e9deca 100644 --- a/clap_complete/tests/snapshots/basic.bash +++ b/clap_complete/tests/snapshots/basic.bash @@ -103,4 +103,4 @@ _my-app() { esac } -complete -F _my-app -o bashdefault -o default my-app +complete -F _my-app -o nosort -o bashdefault -o default my-app diff --git a/clap_complete/tests/snapshots/feature_sample.bash b/clap_complete/tests/snapshots/feature_sample.bash index 6289845f152..e5119ae6109 100644 --- a/clap_complete/tests/snapshots/feature_sample.bash +++ b/clap_complete/tests/snapshots/feature_sample.bash @@ -107,4 +107,4 @@ _my-app() { esac } -complete -F _my-app -o bashdefault -o default my-app +complete -F _my-app -o nosort -o bashdefault -o default my-app diff --git a/clap_complete/tests/snapshots/home/.gitignore b/clap_complete/tests/snapshots/home/.gitignore new file mode 100644 index 00000000000..1e0cb3f20e7 --- /dev/null +++ b/clap_complete/tests/snapshots/home/.gitignore @@ -0,0 +1,7 @@ +# Fish +conf.d +fish_variables +functions + +# Zsh +.zcompdump diff --git a/clap_complete/tests/snapshots/home/test/bash/.bashrc b/clap_complete/tests/snapshots/home/test/bash/.bashrc new file mode 100644 index 00000000000..dcb08049e0b --- /dev/null +++ b/clap_complete/tests/snapshots/home/test/bash/.bashrc @@ -0,0 +1,909 @@ +PS1='% ' +. /etc/bash_completion +_test() { + local i cur prev opts cmd + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + cmd="" + opts="" + + for i in ${COMP_WORDS[@]} + do + case "${cmd},${i}" in + ",$1") + cmd="test" + ;; + test,action) + cmd="test__action" + ;; + test,alias) + cmd="test__alias" + ;; + test,help) + cmd="test__help" + ;; + test,hint) + cmd="test__hint" + ;; + test,last) + cmd="test__last" + ;; + test,pacman) + cmd="test__pacman" + ;; + test,quote) + cmd="test__quote" + ;; + test,value) + cmd="test__value" + ;; + test__help,action) + cmd="test__help__action" + ;; + test__help,alias) + cmd="test__help__alias" + ;; + test__help,help) + cmd="test__help__help" + ;; + test__help,hint) + cmd="test__help__hint" + ;; + test__help,last) + cmd="test__help__last" + ;; + test__help,pacman) + cmd="test__help__pacman" + ;; + test__help,quote) + cmd="test__help__quote" + ;; + test__help,value) + cmd="test__help__value" + ;; + test__help__pacman,one) + cmd="test__help__pacman__one" + ;; + test__help__pacman,two) + cmd="test__help__pacman__two" + ;; + test__help__quote,cmd-backslash) + cmd="test__help__quote__cmd__backslash" + ;; + test__help__quote,cmd-backticks) + cmd="test__help__quote__cmd__backticks" + ;; + test__help__quote,cmd-brackets) + cmd="test__help__quote__cmd__brackets" + ;; + test__help__quote,cmd-double-quotes) + cmd="test__help__quote__cmd__double__quotes" + ;; + test__help__quote,cmd-expansions) + cmd="test__help__quote__cmd__expansions" + ;; + test__help__quote,cmd-single-quotes) + cmd="test__help__quote__cmd__single__quotes" + ;; + test__pacman,help) + cmd="test__pacman__help" + ;; + test__pacman,one) + cmd="test__pacman__one" + ;; + test__pacman,two) + cmd="test__pacman__two" + ;; + test__pacman__help,help) + cmd="test__pacman__help__help" + ;; + test__pacman__help,one) + cmd="test__pacman__help__one" + ;; + test__pacman__help,two) + cmd="test__pacman__help__two" + ;; + test__quote,cmd-backslash) + cmd="test__quote__cmd__backslash" + ;; + test__quote,cmd-backticks) + cmd="test__quote__cmd__backticks" + ;; + test__quote,cmd-brackets) + cmd="test__quote__cmd__brackets" + ;; + test__quote,cmd-double-quotes) + cmd="test__quote__cmd__double__quotes" + ;; + test__quote,cmd-expansions) + cmd="test__quote__cmd__expansions" + ;; + test__quote,cmd-single-quotes) + cmd="test__quote__cmd__single__quotes" + ;; + test__quote,help) + cmd="test__quote__help" + ;; + test__quote__help,cmd-backslash) + cmd="test__quote__help__cmd__backslash" + ;; + test__quote__help,cmd-backticks) + cmd="test__quote__help__cmd__backticks" + ;; + test__quote__help,cmd-brackets) + cmd="test__quote__help__cmd__brackets" + ;; + test__quote__help,cmd-double-quotes) + cmd="test__quote__help__cmd__double__quotes" + ;; + test__quote__help,cmd-expansions) + cmd="test__quote__help__cmd__expansions" + ;; + test__quote__help,cmd-single-quotes) + cmd="test__quote__help__cmd__single__quotes" + ;; + test__quote__help,help) + cmd="test__quote__help__help" + ;; + *) + ;; + esac + done + + case "${cmd}" in + test) + opts="-h -V --global --generate --help --version action quote value pacman last alias hint help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + --generate) + COMPREPLY=($(compgen -W "bash elvish fish powershell zsh" -- "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__action) + opts="-h -V --set-true --set --count --choice --global --help --version" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + --set) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --choice) + COMPREPLY=($(compgen -W "first second" -- "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__alias) + opts="-F -f -O -o -h -V --flg --flag --opt --option --global --help --version [positional]" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + --option) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --opt) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -o) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -O) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help) + opts="action quote value pacman last alias hint help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__action) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__alias) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__help) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__hint) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__last) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__pacman) + opts="one two" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__pacman__one) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__pacman__two) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__quote) + opts="cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__quote__cmd__backslash) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__quote__cmd__backticks) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__quote__cmd__brackets) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__quote__cmd__double__quotes) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__quote__cmd__expansions) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__quote__cmd__single__quotes) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__help__value) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__hint) + opts="-p -f -d -e -c -u -H -h -V --choice --unknown --other --path --file --dir --exe --cmd-name --cmd --user --host --url --email --global --help --version [command_with_args]..." + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + --choice) + COMPREPLY=($(compgen -W "bash fish zsh" -- "${cur}")) + return 0 + ;; + --unknown) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --other) + COMPREPLY=("${cur}") + return 0 + ;; + --path) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -p) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --file) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -f) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --dir) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -d) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --exe) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -e) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --cmd-name) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --cmd) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -c) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --user) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -u) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --host) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -H) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --url) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --email) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__last) + opts="-h -V --global --help --version [first] [free]" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__pacman) + opts="-h -V --global --help --version one two help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__pacman__help) + opts="one two help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__pacman__help__help) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__pacman__help__one) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__pacman__help__two) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__pacman__one) + opts="-h -V --global --help --version" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__pacman__two) + opts="-h -V --global --help --version" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote) + opts="-h -V --single-quotes --double-quotes --backticks --backslash --brackets --expansions --global --help --version cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__cmd__backslash) + opts="-h -V --global --help --version" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__cmd__backticks) + opts="-h -V --global --help --version" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__cmd__brackets) + opts="-h -V --global --help --version" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__cmd__double__quotes) + opts="-h -V --global --help --version" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__cmd__expansions) + opts="-h -V --global --help --version" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__cmd__single__quotes) + opts="-h -V --global --help --version" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__help) + opts="cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__help__cmd__backslash) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__help__cmd__backticks) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__help__cmd__brackets) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__help__cmd__double__quotes) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__help__cmd__expansions) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__help__cmd__single__quotes) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__quote__help__help) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 4 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + test__value) + opts="-h -V --delim --tuple --require-eq --global --help --version [term]..." + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + --delim) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --tuple) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --require-eq) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + esac +} + +complete -F _test -o nosort -o bashdefault -o default test + diff --git a/clap_complete/tests/snapshots/home/test/elvish/elvish/rc.elv b/clap_complete/tests/snapshots/home/test/elvish/elvish/rc.elv new file mode 100644 index 00000000000..7b2e8bacc40 --- /dev/null +++ b/clap_complete/tests/snapshots/home/test/elvish/elvish/rc.elv @@ -0,0 +1,281 @@ +set edit:rprompt = (constantly "") +set edit:prompt = (constantly "% ") + +use builtin; +use str; + +set edit:completion:arg-completer[test] = {|@words| + fn spaces {|n| + builtin:repeat $n ' ' | str:join '' + } + fn cand {|text desc| + edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc + } + var command = 'test' + for word $words[1..-1] { + if (str:has-prefix $word '-') { + break + } + set command = $command';'$word + } + var completions = [ + &'test'= { + cand --generate 'generate' + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + cand action 'action' + cand quote 'quote' + cand value 'value' + cand pacman 'pacman' + cand last 'last' + cand alias 'alias' + cand hint 'hint' + cand help 'Print this message or the help of the given subcommand(s)' + } + &'test;action'= { + cand --set 'value' + cand --choice 'enum' + cand --set-true 'bool' + cand --count 'number' + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;quote'= { + cand --single-quotes 'Can be ''always'', ''auto'', or ''never''' + cand --double-quotes 'Can be "always", "auto", or "never"' + cand --backticks 'For more information see `echo test`' + cand --backslash 'Avoid ''\n''' + cand --brackets 'List packages [filter]' + cand --expansions 'Execute the shell command with $SHELL' + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + cand cmd-single-quotes 'Can be ''always'', ''auto'', or ''never''' + cand cmd-double-quotes 'Can be "always", "auto", or "never"' + cand cmd-backticks 'For more information see `echo test`' + cand cmd-backslash 'Avoid ''\n''' + cand cmd-brackets 'List packages [filter]' + cand cmd-expansions 'Execute the shell command with $SHELL' + cand help 'Print this message or the help of the given subcommand(s)' + } + &'test;quote;cmd-single-quotes'= { + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;quote;cmd-double-quotes'= { + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;quote;cmd-backticks'= { + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;quote;cmd-backslash'= { + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;quote;cmd-brackets'= { + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;quote;cmd-expansions'= { + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;quote;help'= { + cand cmd-single-quotes 'Can be ''always'', ''auto'', or ''never''' + cand cmd-double-quotes 'Can be "always", "auto", or "never"' + cand cmd-backticks 'For more information see `echo test`' + cand cmd-backslash 'Avoid ''\n''' + cand cmd-brackets 'List packages [filter]' + cand cmd-expansions 'Execute the shell command with $SHELL' + cand help 'Print this message or the help of the given subcommand(s)' + } + &'test;quote;help;cmd-single-quotes'= { + } + &'test;quote;help;cmd-double-quotes'= { + } + &'test;quote;help;cmd-backticks'= { + } + &'test;quote;help;cmd-backslash'= { + } + &'test;quote;help;cmd-brackets'= { + } + &'test;quote;help;cmd-expansions'= { + } + &'test;quote;help;help'= { + } + &'test;value'= { + cand --delim 'delim' + cand --tuple 'tuple' + cand --require-eq 'require-eq' + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;pacman'= { + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + cand one 'one' + cand two 'two' + cand help 'Print this message or the help of the given subcommand(s)' + } + &'test;pacman;one'= { + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;pacman;two'= { + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;pacman;help'= { + cand one 'one' + cand two 'two' + cand help 'Print this message or the help of the given subcommand(s)' + } + &'test;pacman;help;one'= { + } + &'test;pacman;help;two'= { + } + &'test;pacman;help;help'= { + } + &'test;last'= { + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;alias'= { + cand -o 'cmd option' + cand -O 'cmd option' + cand --option 'cmd option' + cand --opt 'cmd option' + cand -f 'cmd flag' + cand -F 'cmd flag' + cand --flag 'cmd flag' + cand --flg 'cmd flag' + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;hint'= { + cand --choice 'choice' + cand --unknown 'unknown' + cand --other 'other' + cand -p 'p' + cand --path 'path' + cand -f 'f' + cand --file 'file' + cand -d 'd' + cand --dir 'dir' + cand -e 'e' + cand --exe 'exe' + cand --cmd-name 'cmd-name' + cand -c 'c' + cand --cmd 'cmd' + cand -u 'u' + cand --user 'user' + cand -H 'H' + cand --host 'host' + cand --url 'url' + cand --email 'email' + cand --global 'everywhere' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + &'test;help'= { + cand action 'action' + cand quote 'quote' + cand value 'value' + cand pacman 'pacman' + cand last 'last' + cand alias 'alias' + cand hint 'hint' + cand help 'Print this message or the help of the given subcommand(s)' + } + &'test;help;action'= { + } + &'test;help;quote'= { + cand cmd-single-quotes 'Can be ''always'', ''auto'', or ''never''' + cand cmd-double-quotes 'Can be "always", "auto", or "never"' + cand cmd-backticks 'For more information see `echo test`' + cand cmd-backslash 'Avoid ''\n''' + cand cmd-brackets 'List packages [filter]' + cand cmd-expansions 'Execute the shell command with $SHELL' + } + &'test;help;quote;cmd-single-quotes'= { + } + &'test;help;quote;cmd-double-quotes'= { + } + &'test;help;quote;cmd-backticks'= { + } + &'test;help;quote;cmd-backslash'= { + } + &'test;help;quote;cmd-brackets'= { + } + &'test;help;quote;cmd-expansions'= { + } + &'test;help;value'= { + } + &'test;help;pacman'= { + cand one 'one' + cand two 'two' + } + &'test;help;pacman;one'= { + } + &'test;help;pacman;two'= { + } + &'test;help;last'= { + } + &'test;help;alias'= { + } + &'test;help;hint'= { + } + &'test;help;help'= { + } + ] + $completions[$command] +} + diff --git a/clap_complete/tests/snapshots/home/test/fish/fish/completions/test.fish b/clap_complete/tests/snapshots/home/test/fish/fish/completions/test.fish new file mode 100644 index 00000000000..1059fd8c9ef --- /dev/null +++ b/clap_complete/tests/snapshots/home/test/fish/fish/completions/test.fish @@ -0,0 +1,121 @@ +complete -c test -n "__fish_use_subcommand" -l generate -d 'generate' -r -f -a "{bash ,elvish ,fish ,powershell ,zsh }" +complete -c test -n "__fish_use_subcommand" -l global -d 'everywhere' +complete -c test -n "__fish_use_subcommand" -s h -l help -d 'Print help' +complete -c test -n "__fish_use_subcommand" -s V -l version -d 'Print version' +complete -c test -n "__fish_use_subcommand" -f -a "action" +complete -c test -n "__fish_use_subcommand" -f -a "quote" +complete -c test -n "__fish_use_subcommand" -f -a "value" +complete -c test -n "__fish_use_subcommand" -f -a "pacman" +complete -c test -n "__fish_use_subcommand" -f -a "last" +complete -c test -n "__fish_use_subcommand" -f -a "alias" +complete -c test -n "__fish_use_subcommand" -f -a "hint" +complete -c test -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c test -n "__fish_seen_subcommand_from action" -l set -d 'value' -r +complete -c test -n "__fish_seen_subcommand_from action" -l choice -d 'enum' -r -f -a "{first ,second }" +complete -c test -n "__fish_seen_subcommand_from action" -l set-true -d 'bool' +complete -c test -n "__fish_seen_subcommand_from action" -l count -d 'number' +complete -c test -n "__fish_seen_subcommand_from action" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from action" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from action" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -l single-quotes -d 'Can be \'always\', \'auto\', or \'never\'' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -l double-quotes -d 'Can be "always", "auto", or "never"' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -l backticks -d 'For more information see `echo test`' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -l backslash -d 'Avoid \'\\n\'' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -l brackets -d 'List packages [filter]' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -l expansions -d 'Execute the shell command with $SHELL' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-single-quotes" -d 'Can be \'always\', \'auto\', or \'never\'' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-double-quotes" -d 'Can be "always", "auto", or "never"' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-backticks" -d 'For more information see `echo test`' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-backslash" -d 'Avoid \'\\n\'' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-brackets" -d 'List packages [filter]' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-expansions" -d 'Execute the shell command with $SHELL' +complete -c test -n "__fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-single-quotes" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-single-quotes" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-single-quotes" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-double-quotes" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-double-quotes" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-double-quotes" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-backticks" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-backticks" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-backticks" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-backslash" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-backslash" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-backslash" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-brackets" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-brackets" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-brackets" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-expansions" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-expansions" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from cmd-expansions" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-single-quotes" -d 'Can be \'always\', \'auto\', or \'never\'' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-double-quotes" -d 'Can be "always", "auto", or "never"' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-backticks" -d 'For more information see `echo test`' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-backslash" -d 'Avoid \'\\n\'' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-brackets" -d 'List packages [filter]' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-expansions" -d 'Execute the shell command with $SHELL' +complete -c test -n "__fish_seen_subcommand_from quote; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c test -n "__fish_seen_subcommand_from value" -l delim -r +complete -c test -n "__fish_seen_subcommand_from value" -l tuple -r +complete -c test -n "__fish_seen_subcommand_from value" -l require-eq -r +complete -c test -n "__fish_seen_subcommand_from value" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from value" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from value" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two; and not __fish_seen_subcommand_from help" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two; and not __fish_seen_subcommand_from help" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two; and not __fish_seen_subcommand_from help" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two; and not __fish_seen_subcommand_from help" -f -a "one" +complete -c test -n "__fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two; and not __fish_seen_subcommand_from help" -f -a "two" +complete -c test -n "__fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c test -n "__fish_seen_subcommand_from pacman; and __fish_seen_subcommand_from one" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from pacman; and __fish_seen_subcommand_from one" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from pacman; and __fish_seen_subcommand_from one" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from pacman; and __fish_seen_subcommand_from two" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from pacman; and __fish_seen_subcommand_from two" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from pacman; and __fish_seen_subcommand_from two" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from pacman; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two; and not __fish_seen_subcommand_from help" -f -a "one" +complete -c test -n "__fish_seen_subcommand_from pacman; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two; and not __fish_seen_subcommand_from help" -f -a "two" +complete -c test -n "__fish_seen_subcommand_from pacman; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c test -n "__fish_seen_subcommand_from last" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from last" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from last" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from alias" -s o -s O -l option -l opt -d 'cmd option' -r +complete -c test -n "__fish_seen_subcommand_from alias" -s f -s F -l flag -l flg -d 'cmd flag' +complete -c test -n "__fish_seen_subcommand_from alias" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from alias" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from alias" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from hint" -l choice -r -f -a "{bash ,fish ,zsh }" +complete -c test -n "__fish_seen_subcommand_from hint" -l unknown -r +complete -c test -n "__fish_seen_subcommand_from hint" -l other -r -f +complete -c test -n "__fish_seen_subcommand_from hint" -s p -l path -r -F +complete -c test -n "__fish_seen_subcommand_from hint" -s f -l file -r -F +complete -c test -n "__fish_seen_subcommand_from hint" -s d -l dir -r -f -a "(__fish_complete_directories)" +complete -c test -n "__fish_seen_subcommand_from hint" -s e -l exe -r -F +complete -c test -n "__fish_seen_subcommand_from hint" -l cmd-name -r -f -a "(__fish_complete_command)" +complete -c test -n "__fish_seen_subcommand_from hint" -s c -l cmd -r -f -a "(__fish_complete_command)" +complete -c test -n "__fish_seen_subcommand_from hint" -s u -l user -r -f -a "(__fish_complete_users)" +complete -c test -n "__fish_seen_subcommand_from hint" -s H -l host -r -f -a "(__fish_print_hostnames)" +complete -c test -n "__fish_seen_subcommand_from hint" -l url -r -f +complete -c test -n "__fish_seen_subcommand_from hint" -l email -r -f +complete -c test -n "__fish_seen_subcommand_from hint" -l global -d 'everywhere' +complete -c test -n "__fish_seen_subcommand_from hint" -s h -l help -d 'Print help' +complete -c test -n "__fish_seen_subcommand_from hint" -s V -l version -d 'Print version' +complete -c test -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from action; and not __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from value; and not __fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from last; and not __fish_seen_subcommand_from alias; and not __fish_seen_subcommand_from hint; and not __fish_seen_subcommand_from help" -f -a "action" +complete -c test -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from action; and not __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from value; and not __fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from last; and not __fish_seen_subcommand_from alias; and not __fish_seen_subcommand_from hint; and not __fish_seen_subcommand_from help" -f -a "quote" +complete -c test -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from action; and not __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from value; and not __fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from last; and not __fish_seen_subcommand_from alias; and not __fish_seen_subcommand_from hint; and not __fish_seen_subcommand_from help" -f -a "value" +complete -c test -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from action; and not __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from value; and not __fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from last; and not __fish_seen_subcommand_from alias; and not __fish_seen_subcommand_from hint; and not __fish_seen_subcommand_from help" -f -a "pacman" +complete -c test -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from action; and not __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from value; and not __fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from last; and not __fish_seen_subcommand_from alias; and not __fish_seen_subcommand_from hint; and not __fish_seen_subcommand_from help" -f -a "last" +complete -c test -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from action; and not __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from value; and not __fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from last; and not __fish_seen_subcommand_from alias; and not __fish_seen_subcommand_from hint; and not __fish_seen_subcommand_from help" -f -a "alias" +complete -c test -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from action; and not __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from value; and not __fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from last; and not __fish_seen_subcommand_from alias; and not __fish_seen_subcommand_from hint; and not __fish_seen_subcommand_from help" -f -a "hint" +complete -c test -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from action; and not __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from value; and not __fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from last; and not __fish_seen_subcommand_from alias; and not __fish_seen_subcommand_from hint; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c test -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions" -f -a "cmd-single-quotes" -d 'Can be \'always\', \'auto\', or \'never\'' +complete -c test -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions" -f -a "cmd-double-quotes" -d 'Can be "always", "auto", or "never"' +complete -c test -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions" -f -a "cmd-backticks" -d 'For more information see `echo test`' +complete -c test -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions" -f -a "cmd-backslash" -d 'Avoid \'\\n\'' +complete -c test -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions" -f -a "cmd-brackets" -d 'List packages [filter]' +complete -c test -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from quote; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions" -f -a "cmd-expansions" -d 'Execute the shell command with $SHELL' +complete -c test -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two" -f -a "one" +complete -c test -n "__fish_seen_subcommand_from help; and __fish_seen_subcommand_from pacman; and not __fish_seen_subcommand_from one; and not __fish_seen_subcommand_from two" -f -a "two" diff --git a/clap_complete/tests/snapshots/home/test/fish/fish/config.fish b/clap_complete/tests/snapshots/home/test/fish/fish/config.fish new file mode 100644 index 00000000000..a397e14bd50 --- /dev/null +++ b/clap_complete/tests/snapshots/home/test/fish/fish/config.fish @@ -0,0 +1,6 @@ +set -U fish_greeting "" +function fish_title +end +function fish_prompt + printf '%% ' +end; diff --git a/clap_complete/tests/snapshots/home/test/zsh/.zshenv b/clap_complete/tests/snapshots/home/test/zsh/.zshenv new file mode 100644 index 00000000000..f7b0671242c --- /dev/null +++ b/clap_complete/tests/snapshots/home/test/zsh/.zshenv @@ -0,0 +1,5 @@ +fpath=($fpath $ZDOTDIR/zsh) +autoload -U +X compinit && compinit +precmd_functions="" # avoid the prompt being overwritten +PS1='%% ' +PROMPT='%% ' diff --git a/clap_complete/tests/snapshots/home/test/zsh/zsh/_test b/clap_complete/tests/snapshots/home/test/zsh/zsh/_test new file mode 100644 index 00000000000..dff894755ba --- /dev/null +++ b/clap_complete/tests/snapshots/home/test/zsh/zsh/_test @@ -0,0 +1,701 @@ +#compdef test + +autoload -U is-at-least + +_test() { + typeset -A opt_args + typeset -a _arguments_options + local ret=1 + + if is-at-least 5.2; then + _arguments_options=(-s -S -C) + else + _arguments_options=(-s -C) + fi + + local context curcontext="$curcontext" state line + _arguments "${_arguments_options[@]}" \ +'--generate=[generate]: :(bash elvish fish powershell zsh)' \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +":: :_test_commands" \ +"*::: :->test" \ +&& ret=0 + case $state in + (test) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:test-command-$line[1]:" + case $line[1] in + (action) +_arguments "${_arguments_options[@]}" \ +'--set=[value]: : ' \ +'--choice=[enum]: :(first second)' \ +'--set-true[bool]' \ +'*--count[number]' \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +&& ret=0 +;; +(quote) +_arguments "${_arguments_options[@]}" \ +'--single-quotes[Can be '\''always'\'', '\''auto'\'', or '\''never'\'']' \ +'--double-quotes[Can be "always", "auto", or "never"]' \ +'--backticks[For more information see \`echo test\`]' \ +'--backslash[Avoid '\''\\n'\'']' \ +'--brackets[List packages \[filter\]]' \ +'--expansions[Execute the shell command with \$SHELL]' \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +":: :_test__quote_commands" \ +"*::: :->quote" \ +&& ret=0 + + case $state in + (quote) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:test-quote-command-$line[1]:" + case $line[1] in + (cmd-single-quotes) +_arguments "${_arguments_options[@]}" \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +&& ret=0 +;; +(cmd-double-quotes) +_arguments "${_arguments_options[@]}" \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +&& ret=0 +;; +(cmd-backticks) +_arguments "${_arguments_options[@]}" \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +&& ret=0 +;; +(cmd-backslash) +_arguments "${_arguments_options[@]}" \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +&& ret=0 +;; +(cmd-brackets) +_arguments "${_arguments_options[@]}" \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +&& ret=0 +;; +(cmd-expansions) +_arguments "${_arguments_options[@]}" \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +":: :_test__quote__help_commands" \ +"*::: :->help" \ +&& ret=0 + + case $state in + (help) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:test-quote-help-command-$line[1]:" + case $line[1] in + (cmd-single-quotes) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(cmd-double-quotes) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(cmd-backticks) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(cmd-backslash) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(cmd-brackets) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(cmd-expansions) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; + esac + ;; +esac +;; + esac + ;; +esac +;; +(value) +_arguments "${_arguments_options[@]}" \ +'--delim=[]: : ' \ +'--tuple=[]: : : : ' \ +'--require-eq=[]: : ' \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +'*;::term:' \ +&& ret=0 +;; +(pacman) +_arguments "${_arguments_options[@]}" \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +":: :_test__pacman_commands" \ +"*::: :->pacman" \ +&& ret=0 + + case $state in + (pacman) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:test-pacman-command-$line[1]:" + case $line[1] in + (one) +_arguments "${_arguments_options[@]}" \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +&& ret=0 +;; +(two) +_arguments "${_arguments_options[@]}" \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +":: :_test__pacman__help_commands" \ +"*::: :->help" \ +&& ret=0 + + case $state in + (help) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:test-pacman-help-command-$line[1]:" + case $line[1] in + (one) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(two) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; + esac + ;; +esac +;; + esac + ;; +esac +;; +(last) +_arguments "${_arguments_options[@]}" \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +'::first:' \ +'::free:' \ +&& ret=0 +;; +(alias) +_arguments "${_arguments_options[@]}" \ +'-o+[cmd option]: : ' \ +'-O+[cmd option]: : ' \ +'--option=[cmd option]: : ' \ +'--opt=[cmd option]: : ' \ +'-f[cmd flag]' \ +'-F[cmd flag]' \ +'--flag[cmd flag]' \ +'--flg[cmd flag]' \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +'::positional:' \ +&& ret=0 +;; +(hint) +_arguments "${_arguments_options[@]}" \ +'--choice=[]: :(bash fish zsh)' \ +'--unknown=[]: : ' \ +'--other=[]: :( )' \ +'-p+[]: :_files' \ +'--path=[]: :_files' \ +'-f+[]: :_files' \ +'--file=[]: :_files' \ +'-d+[]: :_files -/' \ +'--dir=[]: :_files -/' \ +'-e+[]: :_absolute_command_paths' \ +'--exe=[]: :_absolute_command_paths' \ +'--cmd-name=[]: :_command_names -e' \ +'-c+[]: :_cmdstring' \ +'--cmd=[]: :_cmdstring' \ +'-u+[]: :_users' \ +'--user=[]: :_users' \ +'-H+[]: :_hosts' \ +'--host=[]: :_hosts' \ +'--url=[]: :_urls' \ +'--email=[]: :_email_addresses' \ +'--global[everywhere]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +'*::command_with_args:_cmdambivalent' \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +":: :_test__help_commands" \ +"*::: :->help" \ +&& ret=0 + + case $state in + (help) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:test-help-command-$line[1]:" + case $line[1] in + (action) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(quote) +_arguments "${_arguments_options[@]}" \ +":: :_test__help__quote_commands" \ +"*::: :->quote" \ +&& ret=0 + + case $state in + (quote) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:test-help-quote-command-$line[1]:" + case $line[1] in + (cmd-single-quotes) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(cmd-double-quotes) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(cmd-backticks) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(cmd-backslash) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(cmd-brackets) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(cmd-expansions) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; + esac + ;; +esac +;; +(value) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(pacman) +_arguments "${_arguments_options[@]}" \ +":: :_test__help__pacman_commands" \ +"*::: :->pacman" \ +&& ret=0 + + case $state in + (pacman) + words=($line[1] "${words[@]}") + (( CURRENT += 1 )) + curcontext="${curcontext%:*:*}:test-help-pacman-command-$line[1]:" + case $line[1] in + (one) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(two) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; + esac + ;; +esac +;; +(last) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(alias) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(hint) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; +(help) +_arguments "${_arguments_options[@]}" \ +&& ret=0 +;; + esac + ;; +esac +;; + esac + ;; +esac +} + +(( $+functions[_test_commands] )) || +_test_commands() { + local commands; commands=( +'action:' \ +'quote:' \ +'value:' \ +'pacman:' \ +'last:' \ +'alias:' \ +'hint:' \ +'help:Print this message or the help of the given subcommand(s)' \ + ) + _describe -t commands 'test commands' commands "$@" +} +(( $+functions[_test__action_commands] )) || +_test__action_commands() { + local commands; commands=() + _describe -t commands 'test action commands' commands "$@" +} +(( $+functions[_test__help__action_commands] )) || +_test__help__action_commands() { + local commands; commands=() + _describe -t commands 'test help action commands' commands "$@" +} +(( $+functions[_test__alias_commands] )) || +_test__alias_commands() { + local commands; commands=() + _describe -t commands 'test alias commands' commands "$@" +} +(( $+functions[_test__help__alias_commands] )) || +_test__help__alias_commands() { + local commands; commands=() + _describe -t commands 'test help alias commands' commands "$@" +} +(( $+functions[_test__help__quote__cmd-backslash_commands] )) || +_test__help__quote__cmd-backslash_commands() { + local commands; commands=() + _describe -t commands 'test help quote cmd-backslash commands' commands "$@" +} +(( $+functions[_test__quote__cmd-backslash_commands] )) || +_test__quote__cmd-backslash_commands() { + local commands; commands=() + _describe -t commands 'test quote cmd-backslash commands' commands "$@" +} +(( $+functions[_test__quote__help__cmd-backslash_commands] )) || +_test__quote__help__cmd-backslash_commands() { + local commands; commands=() + _describe -t commands 'test quote help cmd-backslash commands' commands "$@" +} +(( $+functions[_test__help__quote__cmd-backticks_commands] )) || +_test__help__quote__cmd-backticks_commands() { + local commands; commands=() + _describe -t commands 'test help quote cmd-backticks commands' commands "$@" +} +(( $+functions[_test__quote__cmd-backticks_commands] )) || +_test__quote__cmd-backticks_commands() { + local commands; commands=() + _describe -t commands 'test quote cmd-backticks commands' commands "$@" +} +(( $+functions[_test__quote__help__cmd-backticks_commands] )) || +_test__quote__help__cmd-backticks_commands() { + local commands; commands=() + _describe -t commands 'test quote help cmd-backticks commands' commands "$@" +} +(( $+functions[_test__help__quote__cmd-brackets_commands] )) || +_test__help__quote__cmd-brackets_commands() { + local commands; commands=() + _describe -t commands 'test help quote cmd-brackets commands' commands "$@" +} +(( $+functions[_test__quote__cmd-brackets_commands] )) || +_test__quote__cmd-brackets_commands() { + local commands; commands=() + _describe -t commands 'test quote cmd-brackets commands' commands "$@" +} +(( $+functions[_test__quote__help__cmd-brackets_commands] )) || +_test__quote__help__cmd-brackets_commands() { + local commands; commands=() + _describe -t commands 'test quote help cmd-brackets commands' commands "$@" +} +(( $+functions[_test__help__quote__cmd-double-quotes_commands] )) || +_test__help__quote__cmd-double-quotes_commands() { + local commands; commands=() + _describe -t commands 'test help quote cmd-double-quotes commands' commands "$@" +} +(( $+functions[_test__quote__cmd-double-quotes_commands] )) || +_test__quote__cmd-double-quotes_commands() { + local commands; commands=() + _describe -t commands 'test quote cmd-double-quotes commands' commands "$@" +} +(( $+functions[_test__quote__help__cmd-double-quotes_commands] )) || +_test__quote__help__cmd-double-quotes_commands() { + local commands; commands=() + _describe -t commands 'test quote help cmd-double-quotes commands' commands "$@" +} +(( $+functions[_test__help__quote__cmd-expansions_commands] )) || +_test__help__quote__cmd-expansions_commands() { + local commands; commands=() + _describe -t commands 'test help quote cmd-expansions commands' commands "$@" +} +(( $+functions[_test__quote__cmd-expansions_commands] )) || +_test__quote__cmd-expansions_commands() { + local commands; commands=() + _describe -t commands 'test quote cmd-expansions commands' commands "$@" +} +(( $+functions[_test__quote__help__cmd-expansions_commands] )) || +_test__quote__help__cmd-expansions_commands() { + local commands; commands=() + _describe -t commands 'test quote help cmd-expansions commands' commands "$@" +} +(( $+functions[_test__help__quote__cmd-single-quotes_commands] )) || +_test__help__quote__cmd-single-quotes_commands() { + local commands; commands=() + _describe -t commands 'test help quote cmd-single-quotes commands' commands "$@" +} +(( $+functions[_test__quote__cmd-single-quotes_commands] )) || +_test__quote__cmd-single-quotes_commands() { + local commands; commands=() + _describe -t commands 'test quote cmd-single-quotes commands' commands "$@" +} +(( $+functions[_test__quote__help__cmd-single-quotes_commands] )) || +_test__quote__help__cmd-single-quotes_commands() { + local commands; commands=() + _describe -t commands 'test quote help cmd-single-quotes commands' commands "$@" +} +(( $+functions[_test__help_commands] )) || +_test__help_commands() { + local commands; commands=( +'action:' \ +'quote:' \ +'value:' \ +'pacman:' \ +'last:' \ +'alias:' \ +'hint:' \ +'help:Print this message or the help of the given subcommand(s)' \ + ) + _describe -t commands 'test help commands' commands "$@" +} +(( $+functions[_test__help__help_commands] )) || +_test__help__help_commands() { + local commands; commands=() + _describe -t commands 'test help help commands' commands "$@" +} +(( $+functions[_test__pacman__help_commands] )) || +_test__pacman__help_commands() { + local commands; commands=( +'one:' \ +'two:' \ +'help:Print this message or the help of the given subcommand(s)' \ + ) + _describe -t commands 'test pacman help commands' commands "$@" +} +(( $+functions[_test__pacman__help__help_commands] )) || +_test__pacman__help__help_commands() { + local commands; commands=() + _describe -t commands 'test pacman help help commands' commands "$@" +} +(( $+functions[_test__quote__help_commands] )) || +_test__quote__help_commands() { + local commands; commands=( +'cmd-single-quotes:Can be '\''always'\'', '\''auto'\'', or '\''never'\''' \ +'cmd-double-quotes:Can be "always", "auto", or "never"' \ +'cmd-backticks:For more information see \`echo test\`' \ +'cmd-backslash:Avoid '\''\\n'\''' \ +'cmd-brackets:List packages \[filter\]' \ +'cmd-expansions:Execute the shell command with \$SHELL' \ +'help:Print this message or the help of the given subcommand(s)' \ + ) + _describe -t commands 'test quote help commands' commands "$@" +} +(( $+functions[_test__quote__help__help_commands] )) || +_test__quote__help__help_commands() { + local commands; commands=() + _describe -t commands 'test quote help help commands' commands "$@" +} +(( $+functions[_test__help__hint_commands] )) || +_test__help__hint_commands() { + local commands; commands=() + _describe -t commands 'test help hint commands' commands "$@" +} +(( $+functions[_test__hint_commands] )) || +_test__hint_commands() { + local commands; commands=() + _describe -t commands 'test hint commands' commands "$@" +} +(( $+functions[_test__help__last_commands] )) || +_test__help__last_commands() { + local commands; commands=() + _describe -t commands 'test help last commands' commands "$@" +} +(( $+functions[_test__last_commands] )) || +_test__last_commands() { + local commands; commands=() + _describe -t commands 'test last commands' commands "$@" +} +(( $+functions[_test__help__pacman__one_commands] )) || +_test__help__pacman__one_commands() { + local commands; commands=() + _describe -t commands 'test help pacman one commands' commands "$@" +} +(( $+functions[_test__pacman__help__one_commands] )) || +_test__pacman__help__one_commands() { + local commands; commands=() + _describe -t commands 'test pacman help one commands' commands "$@" +} +(( $+functions[_test__pacman__one_commands] )) || +_test__pacman__one_commands() { + local commands; commands=() + _describe -t commands 'test pacman one commands' commands "$@" +} +(( $+functions[_test__help__pacman_commands] )) || +_test__help__pacman_commands() { + local commands; commands=( +'one:' \ +'two:' \ + ) + _describe -t commands 'test help pacman commands' commands "$@" +} +(( $+functions[_test__pacman_commands] )) || +_test__pacman_commands() { + local commands; commands=( +'one:' \ +'two:' \ +'help:Print this message or the help of the given subcommand(s)' \ + ) + _describe -t commands 'test pacman commands' commands "$@" +} +(( $+functions[_test__help__quote_commands] )) || +_test__help__quote_commands() { + local commands; commands=( +'cmd-single-quotes:Can be '\''always'\'', '\''auto'\'', or '\''never'\''' \ +'cmd-double-quotes:Can be "always", "auto", or "never"' \ +'cmd-backticks:For more information see \`echo test\`' \ +'cmd-backslash:Avoid '\''\\n'\''' \ +'cmd-brackets:List packages \[filter\]' \ +'cmd-expansions:Execute the shell command with \$SHELL' \ + ) + _describe -t commands 'test help quote commands' commands "$@" +} +(( $+functions[_test__quote_commands] )) || +_test__quote_commands() { + local commands; commands=( +'cmd-single-quotes:Can be '\''always'\'', '\''auto'\'', or '\''never'\''' \ +'cmd-double-quotes:Can be "always", "auto", or "never"' \ +'cmd-backticks:For more information see \`echo test\`' \ +'cmd-backslash:Avoid '\''\\n'\''' \ +'cmd-brackets:List packages \[filter\]' \ +'cmd-expansions:Execute the shell command with \$SHELL' \ +'help:Print this message or the help of the given subcommand(s)' \ + ) + _describe -t commands 'test quote commands' commands "$@" +} +(( $+functions[_test__help__pacman__two_commands] )) || +_test__help__pacman__two_commands() { + local commands; commands=() + _describe -t commands 'test help pacman two commands' commands "$@" +} +(( $+functions[_test__pacman__help__two_commands] )) || +_test__pacman__help__two_commands() { + local commands; commands=() + _describe -t commands 'test pacman help two commands' commands "$@" +} +(( $+functions[_test__pacman__two_commands] )) || +_test__pacman__two_commands() { + local commands; commands=() + _describe -t commands 'test pacman two commands' commands "$@" +} +(( $+functions[_test__help__value_commands] )) || +_test__help__value_commands() { + local commands; commands=() + _describe -t commands 'test help value commands' commands "$@" +} +(( $+functions[_test__value_commands] )) || +_test__value_commands() { + local commands; commands=() + _describe -t commands 'test value commands' commands "$@" +} + +if [ "$funcstack[1]" = "_test" ]; then + _test "$@" +else + compdef _test test +fi diff --git a/clap_complete/tests/snapshots/quoting.bash b/clap_complete/tests/snapshots/quoting.bash index 940dba1b03e..7f8236061b7 100644 --- a/clap_complete/tests/snapshots/quoting.bash +++ b/clap_complete/tests/snapshots/quoting.bash @@ -273,4 +273,4 @@ _my-app() { esac } -complete -F _my-app -o bashdefault -o default my-app +complete -F _my-app -o nosort -o bashdefault -o default my-app diff --git a/clap_complete/tests/snapshots/special_commands.bash b/clap_complete/tests/snapshots/special_commands.bash index 139b4d55306..12b3d154348 100644 --- a/clap_complete/tests/snapshots/special_commands.bash +++ b/clap_complete/tests/snapshots/special_commands.bash @@ -213,4 +213,4 @@ _my-app() { esac } -complete -F _my-app -o bashdefault -o default my-app +complete -F _my-app -o nosort -o bashdefault -o default my-app diff --git a/clap_complete/tests/snapshots/sub_subcommands.bash b/clap_complete/tests/snapshots/sub_subcommands.bash index 80eed4e847f..0b64301de04 100644 --- a/clap_complete/tests/snapshots/sub_subcommands.bash +++ b/clap_complete/tests/snapshots/sub_subcommands.bash @@ -233,4 +233,4 @@ _my-app() { esac } -complete -F _my-app -o bashdefault -o default my-app +complete -F _my-app -o nosort -o bashdefault -o default my-app diff --git a/clap_complete/tests/snapshots/subcommand_last.bash b/clap_complete/tests/snapshots/subcommand_last.bash index f3ca85b9187..86b9cf47dee 100644 --- a/clap_complete/tests/snapshots/subcommand_last.bash +++ b/clap_complete/tests/snapshots/subcommand_last.bash @@ -137,4 +137,4 @@ _my-app() { esac } -complete -F _my-app -o bashdefault -o default my-app +complete -F _my-app -o nosort -o bashdefault -o default my-app diff --git a/clap_complete/tests/snapshots/two_multi_valued_arguments.bash b/clap_complete/tests/snapshots/two_multi_valued_arguments.bash index 4e6e33c4558..262a1fac955 100644 --- a/clap_complete/tests/snapshots/two_multi_valued_arguments.bash +++ b/clap_complete/tests/snapshots/two_multi_valued_arguments.bash @@ -35,4 +35,4 @@ _my-app() { esac } -complete -F _my-app -o bashdefault -o default my-app +complete -F _my-app -o nosort -o bashdefault -o default my-app diff --git a/clap_complete/tests/snapshots/value_hint.bash b/clap_complete/tests/snapshots/value_hint.bash index e0a39cb8d4b..0fb4696e82d 100644 --- a/clap_complete/tests/snapshots/value_hint.bash +++ b/clap_complete/tests/snapshots/value_hint.bash @@ -115,4 +115,4 @@ _my-app() { esac } -complete -F _my-app -o bashdefault -o default my-app +complete -F _my-app -o nosort -o bashdefault -o default my-app diff --git a/clap_complete/tests/snapshots/value_terminator.bash b/clap_complete/tests/snapshots/value_terminator.bash index f9eef4c21d2..fb2e3d5e9fd 100644 --- a/clap_complete/tests/snapshots/value_terminator.bash +++ b/clap_complete/tests/snapshots/value_terminator.bash @@ -35,4 +35,4 @@ _my-app() { esac } -complete -F _my-app -o bashdefault -o default my-app +complete -F _my-app -o nosort -o bashdefault -o default my-app diff --git a/clap_complete/tests/bash.rs b/clap_complete/tests/testsuite/bash.rs similarity index 81% rename from clap_complete/tests/bash.rs rename to clap_complete/tests/testsuite/bash.rs index b672e1cf4ea..a29803d7afe 100644 --- a/clap_complete/tests/bash.rs +++ b/clap_complete/tests/testsuite/bash.rs @@ -1,4 +1,4 @@ -mod common; +use crate::common; #[test] fn basic() { @@ -135,3 +135,31 @@ fn subcommand_last() { name, ); } + +#[test] +#[cfg(unix)] +fn register_completion() { + if !common::has_command("bash") { + return; + } + + common::register_example("test", completest::Shell::Bash); +} + +#[test] +#[cfg(unix)] +fn complete() { + if !common::has_command("bash") { + return; + } + + let term = completest::Term::new(); + let runtime = common::load_runtime("test", completest::Shell::Bash); + + let input = "test \t\t"; + let expected = r#"% +-h --global --help action value last hint +-V --generate --version quote pacman alias help"#; + let actual = runtime.complete(input, &term).unwrap(); + snapbox::assert_eq(expected, actual); +} diff --git a/clap_complete/tests/common.rs b/clap_complete/tests/testsuite/common.rs similarity index 69% rename from clap_complete/tests/common.rs rename to clap_complete/tests/testsuite/common.rs index 1eb530f1d20..e40e57d8881 100644 --- a/clap_complete/tests/common.rs +++ b/clap_complete/tests/testsuite/common.rs @@ -295,3 +295,137 @@ pub fn assert_matches_path( .normalize_paths(false) .matches_path(expected_path, buf); } + +pub fn has_command(command: &str) -> bool { + let output = match std::process::Command::new(command) + .arg("--version") + .output() + { + Ok(output) => output, + Err(e) => { + // CI is expected to support all of the commands + if is_ci() && cfg!(linux) { + panic!( + "expected command `{}` to be somewhere in PATH: {}", + command, e + ); + } + return false; + } + }; + if !output.status.success() { + panic!( + "expected command `{}` to be runnable, got error {}:\n\ + stderr:{}\n\ + stdout:{}\n", + command, + output.status, + String::from_utf8_lossy(&output.stderr), + String::from_utf8_lossy(&output.stdout) + ); + } + let stdout = String::from_utf8_lossy(&output.stdout); + println!( + "$ {command} --version +{}", + stdout + ); + if cfg!(target_os = "macos") && stdout.starts_with("GNU bash, version 3") { + return false; + } + if cfg!(target_os = "macos") && command == "zsh" { + // HACK: At least on CI, the prompt override is not working + return false; + } + + true +} + +#[cfg(unix)] +pub fn register_example(name: &str, shell: completest::Shell) { + let scratch = snapbox::path::PathFixture::mutable_temp().unwrap(); + let scratch_path = scratch.path().unwrap(); + + let shell_name = shell.name(); + let home = std::path::Path::new("tests/snapshots/home") + .join(name) + .join(shell_name); + let bin_path = snapbox::cmd::compile_example(name, []).unwrap(); + let bin_root = bin_path.parent().unwrap().to_owned(); + + let registration = std::process::Command::new(&bin_path) + .arg(format!("--generate={shell_name}")) + .output() + .unwrap(); + assert!( + registration.status.success(), + "{}", + String::from_utf8_lossy(®istration.stderr) + ); + let registration = std::str::from_utf8(®istration.stdout).unwrap(); + assert!(!registration.is_empty()); + + let runtime = shell.init(bin_root, scratch_path.to_owned()).unwrap(); + + runtime.register(name, registration).unwrap(); + + snapbox::assert_subset_eq(&home, scratch_path); + + scratch.close().unwrap(); +} + +#[cfg(unix)] +pub fn load_runtime(name: &str, shell: completest::Shell) -> Box { + let shell_name = shell.name(); + let home = std::path::Path::new("tests/snapshots/home") + .join(name) + .join(shell_name); + let scratch = snapbox::path::PathFixture::mutable_temp() + .unwrap() + .with_template(&home) + .unwrap(); + let home = scratch.path().unwrap().to_owned(); + let bin_path = snapbox::cmd::compile_example(name, []).unwrap(); + let bin_root = bin_path.parent().unwrap().to_owned(); + + let runtime = shell.with_home(bin_root, home); + + Box::new(ScratchRuntime { + _scratch: scratch, + runtime, + }) +} + +#[cfg(unix)] +struct ScratchRuntime { + _scratch: snapbox::path::PathFixture, + runtime: Box, +} + +#[cfg(unix)] +impl completest::Runtime for ScratchRuntime { + fn home(&self) -> &std::path::Path { + self.runtime.home() + } + + fn register(&self, name: &str, content: &str) -> std::io::Result<()> { + self.runtime.register(name, content) + } + + fn complete(&self, input: &str, term: &completest::Term) -> std::io::Result { + let output = self.runtime.complete(input, term)?; + // HACK: elvish prints and clears this message when a completer takes too long which is + // dependent on a lot of factors, making this show up or no sometimes (especially if we + // aren't clearing the screen properly for fish) + let output = output.replace("\n COMPLETING argument\n", "\n"); + Ok(output) + } +} + +/// Whether or not this running in a Continuous Integration environment. +fn is_ci() -> bool { + // Consider using `tracked_env` instead of option_env! when it is stabilized. + // `tracked_env` will handle changes, but not require rebuilding the macro + // itself like option_env does. + option_env!("CI").is_some() || option_env!("TF_BUILD").is_some() +} diff --git a/clap_complete/tests/dynamic.rs b/clap_complete/tests/testsuite/dynamic.rs similarity index 100% rename from clap_complete/tests/dynamic.rs rename to clap_complete/tests/testsuite/dynamic.rs diff --git a/clap_complete/tests/elvish.rs b/clap_complete/tests/testsuite/elvish.rs similarity index 73% rename from clap_complete/tests/elvish.rs rename to clap_complete/tests/testsuite/elvish.rs index 24e1e95607d..731df02405b 100644 --- a/clap_complete/tests/elvish.rs +++ b/clap_complete/tests/testsuite/elvish.rs @@ -1,4 +1,4 @@ -mod common; +use crate::common; #[test] fn basic() { @@ -119,3 +119,43 @@ fn subcommand_last() { name, ); } + +#[test] +#[cfg(unix)] +fn register_completion() { + if !common::has_command("elvish") { + return; + } + + common::register_example("test", completest::Shell::Elvish); +} + +#[test] +#[cfg(unix)] +fn complete() { + if !common::has_command("elvish") { + return; + } + + let term = completest::Term::new(); + let runtime = common::load_runtime("test", completest::Shell::Elvish); + + let input = "test \t"; + let expected = r#"% test --generate +--generate generate +--global everywhere +--help Print help +--version Print version +-V Print version +-h Print help +action action +alias alias +help Print this message or the help of the given subcommand(s) +hint hint +last last +pacman pacman +quote quote +value value"#; + let actual = runtime.complete(input, &term).unwrap(); + snapbox::assert_eq(expected, actual); +} diff --git a/clap_complete/tests/fish.rs b/clap_complete/tests/testsuite/fish.rs similarity index 77% rename from clap_complete/tests/fish.rs rename to clap_complete/tests/testsuite/fish.rs index e36d8f964c9..287ae263aa5 100644 --- a/clap_complete/tests/fish.rs +++ b/clap_complete/tests/testsuite/fish.rs @@ -1,4 +1,4 @@ -mod common; +use crate::common; #[test] fn basic() { @@ -119,3 +119,31 @@ fn subcommand_last() { name, ); } + +#[test] +#[cfg(unix)] +fn register_completion() { + if !common::has_command("fish") { + return; + } + + common::register_example("test", completest::Shell::Fish); +} + +#[test] +#[cfg(unix)] +fn complete() { + if !common::has_command("fish") { + return; + } + + let term = completest::Term::new(); + let runtime = common::load_runtime("test", completest::Shell::Fish); + + let input = "test \t"; + let expected = r#"% test +action help (Print this message or the help of the given subcommand(s)) last quote +alias hint pacman value"#; + let actual = runtime.complete(input, &term).unwrap(); + snapbox::assert_eq(expected, actual); +} diff --git a/clap_complete/tests/general.rs b/clap_complete/tests/testsuite/general.rs similarity index 100% rename from clap_complete/tests/general.rs rename to clap_complete/tests/testsuite/general.rs diff --git a/clap_complete/tests/testsuite/main.rs b/clap_complete/tests/testsuite/main.rs new file mode 100644 index 00000000000..90ee688a876 --- /dev/null +++ b/clap_complete/tests/testsuite/main.rs @@ -0,0 +1,8 @@ +mod bash; +mod common; +mod dynamic; +mod elvish; +mod fish; +mod general; +mod powershell; +mod zsh; diff --git a/clap_complete/tests/powershell.rs b/clap_complete/tests/testsuite/powershell.rs similarity index 99% rename from clap_complete/tests/powershell.rs rename to clap_complete/tests/testsuite/powershell.rs index 4f4b0a63c9f..afc9b42dc57 100644 --- a/clap_complete/tests/powershell.rs +++ b/clap_complete/tests/testsuite/powershell.rs @@ -1,4 +1,4 @@ -mod common; +use crate::common; #[test] fn basic() { diff --git a/clap_complete/tests/zsh.rs b/clap_complete/tests/testsuite/zsh.rs similarity index 77% rename from clap_complete/tests/zsh.rs rename to clap_complete/tests/testsuite/zsh.rs index 7a3603b5555..c6c4f3a59c2 100644 --- a/clap_complete/tests/zsh.rs +++ b/clap_complete/tests/testsuite/zsh.rs @@ -1,4 +1,4 @@ -mod common; +use crate::common; #[test] fn basic() { @@ -119,3 +119,31 @@ fn subcommand_last() { name, ); } + +#[test] +#[cfg(unix)] +fn register_completion() { + if !common::has_command("zsh") { + return; + } + + common::register_example("test", completest::Shell::Zsh); +} + +#[test] +#[cfg(unix)] +fn complete() { + if !common::has_command("zsh") { + return; + } + + let term = completest::Term::new(); + let runtime = common::load_runtime("test", completest::Shell::Zsh); + + let input = "test \t"; + let expected = r#"% test +help -- Print this message or the help of the given subcommand(s) +pacman action alias value quote hint last --"#; + let actual = runtime.complete(input, &term).unwrap(); + snapbox::assert_eq(expected, actual); +} diff --git a/examples/typed-derive.md b/examples/typed-derive.md index bf7a56a53ce..9221a310da3 100644 --- a/examples/typed-derive.md +++ b/examples/typed-derive.md @@ -12,7 +12,7 @@ Options: --sleep Allow human-readable durations -D Hand-written parser for tuples --port Support for discrete numbers [default: 22] [possible values: 22, 80] - --log-level Support enums from a foreign crate that don't implement `ValueEnum` [default: info] [possible values: info, debug, info, warn, error] + --log-level Support enums from a foreign crate that don't implement `ValueEnum` [default: info] [possible values: trace, debug, info, warn, error] -h, --help Print help ``` @@ -117,14 +117,14 @@ Args { optimization: None, include: None, bind: None, sleep: None, defines: [], $ typed-derive --log-level ? failed error: a value is required for '--log-level ' but none was supplied - [possible values: info, debug, info, warn, error] + [possible values: trace, debug, info, warn, error] For more information, try '--help'. $ typed-derive --log-level critical ? failed error: invalid value 'critical' for '--log-level ' - [possible values: info, debug, info, warn, error] + [possible values: trace, debug, info, warn, error] For more information, try '--help'. diff --git a/examples/typed-derive.rs b/examples/typed-derive.rs index 8d7a84e9672..1a36f11d5b4 100644 --- a/examples/typed-derive.rs +++ b/examples/typed-derive.rs @@ -38,7 +38,7 @@ struct Args { #[arg( long, default_value_t = foreign_crate::LogLevel::Info, - value_parser = clap::builder::PossibleValuesParser::new(["info", "debug", "info", "warn", "error"]) + value_parser = clap::builder::PossibleValuesParser::new(["trace", "debug", "info", "warn", "error"]) .map(|s| s.parse::().unwrap()), )] log_level: foreign_crate::LogLevel, diff --git a/tests/builder/error.rs b/tests/builder/error.rs index 4b0be802e24..c4ab3d2218f 100644 --- a/tests/builder/error.rs +++ b/tests/builder/error.rs @@ -187,3 +187,25 @@ For more information, try '--help'. "; assert_error(err, expected_kind, MESSAGE, true); } + +#[test] +#[cfg(feature = "error-context")] +#[cfg(feature = "suggestions")] +fn cant_use_trailing_subcommand() { + let cmd = Command::new("test").subcommand(Command::new("bar")); + + let res = cmd.try_get_matches_from(["test", "baz"]); + assert!(res.is_err()); + let err = res.unwrap_err(); + let expected_kind = ErrorKind::InvalidSubcommand; + static MESSAGE: &str = "\ +error: unrecognized subcommand 'baz' + + tip: a similar subcommand exists: 'bar' + +Usage: test [COMMAND] + +For more information, try '--help'. +"; + assert_error(err, expected_kind, MESSAGE, true); +} diff --git a/tests/builder/subcommands.rs b/tests/builder/subcommands.rs index db57b2ecae4..a65cb3aca36 100644 --- a/tests/builder/subcommands.rs +++ b/tests/builder/subcommands.rs @@ -103,7 +103,6 @@ fn subcmd_did_you_mean_output() { error: unrecognized subcommand 'subcm' tip: a similar subcommand exists: 'subcmd' - tip: to pass 'subcm' as a value, use 'dym -- subcm' Usage: dym [COMMAND] @@ -123,7 +122,6 @@ fn subcmd_did_you_mean_output_ambiguous() { error: unrecognized subcommand 'te' tip: some similar subcommands exist: 'test', 'temp' - tip: to pass 'te' as a value, use 'dym -- te' Usage: dym [COMMAND] @@ -504,7 +502,6 @@ For more information, try 'help'. error: unrecognized subcommand 'baz' tip: a similar subcommand exists: 'bar' - tip: to pass 'baz' as a value, use ' -- baz' Usage: