2020-12-27 19:47:30 +00:00
|
|
|
use super::*;
|
|
|
|
|
2020-12-27 22:50:20 +00:00
|
|
|
fn build_app() -> App<'static> {
|
|
|
|
build_app_with_name("myapp")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn build_app_with_name(s: &'static str) -> App<'static> {
|
|
|
|
App::new(s)
|
2021-10-08 17:05:40 +00:00
|
|
|
.version("3.0")
|
2021-10-12 18:59:56 +00:00
|
|
|
.setting(AppSettings::PropagateVersion)
|
2020-12-27 22:50:20 +00:00
|
|
|
.about("Tests completions")
|
|
|
|
.arg(
|
|
|
|
Arg::new("file")
|
|
|
|
.value_hint(ValueHint::FilePath)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("some input file"),
|
2020-12-27 22:50:20 +00:00
|
|
|
)
|
|
|
|
.subcommand(
|
|
|
|
App::new("test").about("tests things").arg(
|
|
|
|
Arg::new("case")
|
|
|
|
.long("case")
|
|
|
|
.takes_value(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("the case to test"),
|
2020-12-27 22:50:20 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-12-27 19:47:30 +00:00
|
|
|
#[test]
|
|
|
|
fn zsh() {
|
|
|
|
let mut app = build_app();
|
2021-08-18 18:25:43 +00:00
|
|
|
common(Zsh, &mut app, "myapp", ZSH);
|
2020-12-27 19:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ZSH: &str = r#"#compdef myapp
|
|
|
|
|
|
|
|
autoload -U is-at-least
|
|
|
|
|
|
|
|
_myapp() {
|
|
|
|
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[@]}" \
|
2021-07-30 03:23:25 +00:00
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
|
|
|
'-V[Print version information]' \
|
|
|
|
'--version[Print version information]' \
|
2020-12-27 19:47:30 +00:00
|
|
|
'::file -- some input file:_files' \
|
|
|
|
":: :_myapp_commands" \
|
|
|
|
"*::: :->myapp" \
|
|
|
|
&& ret=0
|
|
|
|
case $state in
|
|
|
|
(myapp)
|
|
|
|
words=($line[2] "${words[@]}")
|
|
|
|
(( CURRENT += 1 ))
|
|
|
|
curcontext="${curcontext%:*:*}:myapp-command-$line[2]:"
|
|
|
|
case $line[2] in
|
|
|
|
(test)
|
|
|
|
_arguments "${_arguments_options[@]}" \
|
2021-10-07 18:39:45 +00:00
|
|
|
'--case=[the case to test]: : ' \
|
2021-07-30 03:23:25 +00:00
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
|
|
|
'-V[Print version information]' \
|
|
|
|
'--version[Print version information]' \
|
2020-12-27 19:47:30 +00:00
|
|
|
&& ret=0
|
|
|
|
;;
|
|
|
|
(help)
|
|
|
|
_arguments "${_arguments_options[@]}" \
|
|
|
|
&& ret=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
(( $+functions[_myapp_commands] )) ||
|
|
|
|
_myapp_commands() {
|
|
|
|
local commands; commands=(
|
2020-12-28 00:02:30 +00:00
|
|
|
'test:tests things' \
|
2021-07-30 03:23:25 +00:00
|
|
|
'help:Print this message or the help of the given subcommand(s)' \
|
2020-12-27 19:47:30 +00:00
|
|
|
)
|
|
|
|
_describe -t commands 'myapp commands' commands "$@"
|
|
|
|
}
|
|
|
|
(( $+functions[_myapp__help_commands] )) ||
|
|
|
|
_myapp__help_commands() {
|
2020-12-28 00:02:30 +00:00
|
|
|
local commands; commands=()
|
2020-12-27 19:47:30 +00:00
|
|
|
_describe -t commands 'myapp help commands' commands "$@"
|
|
|
|
}
|
|
|
|
(( $+functions[_myapp__test_commands] )) ||
|
|
|
|
_myapp__test_commands() {
|
2020-12-28 00:02:30 +00:00
|
|
|
local commands; commands=()
|
2020-12-27 19:47:30 +00:00
|
|
|
_describe -t commands 'myapp test commands' commands "$@"
|
|
|
|
}
|
|
|
|
|
2022-01-09 12:48:17 +00:00
|
|
|
_myapp "$@"
|
|
|
|
"#;
|
2020-12-27 19:47:30 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn zsh_with_special_commands() {
|
|
|
|
let mut app = build_app_special_commands();
|
2021-08-18 18:25:43 +00:00
|
|
|
common(Zsh, &mut app, "my_app", ZSH_SPECIAL_CMDS);
|
2020-12-27 19:47:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 22:50:20 +00:00
|
|
|
fn build_app_special_commands() -> App<'static> {
|
|
|
|
build_app_with_name("my_app")
|
|
|
|
.subcommand(
|
|
|
|
App::new("some_cmd").about("tests other things").arg(
|
|
|
|
Arg::new("config")
|
|
|
|
.long("--config")
|
|
|
|
.takes_value(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("the other case to test"),
|
2020-12-27 22:50:20 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
.subcommand(App::new("some-cmd-with-hypens").alias("hyphen"))
|
2020-12-27 23:05:27 +00:00
|
|
|
.subcommand(
|
|
|
|
App::new("some_cmd_with_special_characters")
|
|
|
|
.about("This 'is' a \"special\" [character] string \\"),
|
|
|
|
)
|
2020-12-27 22:50:20 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 19:47:30 +00:00
|
|
|
static ZSH_SPECIAL_CMDS: &str = r#"#compdef my_app
|
|
|
|
|
|
|
|
autoload -U is-at-least
|
|
|
|
|
|
|
|
_my_app() {
|
|
|
|
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[@]}" \
|
2021-07-30 03:23:25 +00:00
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
|
|
|
'-V[Print version information]' \
|
|
|
|
'--version[Print version information]' \
|
2020-12-27 19:47:30 +00:00
|
|
|
'::file -- some input file:_files' \
|
|
|
|
":: :_my_app_commands" \
|
|
|
|
"*::: :->my_app" \
|
|
|
|
&& ret=0
|
|
|
|
case $state in
|
|
|
|
(my_app)
|
|
|
|
words=($line[2] "${words[@]}")
|
|
|
|
(( CURRENT += 1 ))
|
|
|
|
curcontext="${curcontext%:*:*}:my_app-command-$line[2]:"
|
|
|
|
case $line[2] in
|
|
|
|
(test)
|
|
|
|
_arguments "${_arguments_options[@]}" \
|
2021-10-07 18:39:45 +00:00
|
|
|
'--case=[the case to test]: : ' \
|
2021-07-30 03:23:25 +00:00
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
|
|
|
'-V[Print version information]' \
|
|
|
|
'--version[Print version information]' \
|
2020-12-27 19:47:30 +00:00
|
|
|
&& ret=0
|
|
|
|
;;
|
|
|
|
(some_cmd)
|
|
|
|
_arguments "${_arguments_options[@]}" \
|
2021-10-07 18:39:45 +00:00
|
|
|
'--config=[the other case to test]: : ' \
|
2021-07-30 03:23:25 +00:00
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
|
|
|
'-V[Print version information]' \
|
|
|
|
'--version[Print version information]' \
|
2020-12-27 19:47:30 +00:00
|
|
|
&& ret=0
|
|
|
|
;;
|
|
|
|
(some-cmd-with-hypens)
|
|
|
|
_arguments "${_arguments_options[@]}" \
|
2021-07-30 03:23:25 +00:00
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
|
|
|
'-V[Print version information]' \
|
|
|
|
'--version[Print version information]' \
|
2020-12-27 19:47:30 +00:00
|
|
|
&& ret=0
|
|
|
|
;;
|
2020-12-27 23:05:27 +00:00
|
|
|
(some_cmd_with_special_characters)
|
|
|
|
_arguments "${_arguments_options[@]}" \
|
2021-07-30 03:23:25 +00:00
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
|
|
|
'-V[Print version information]' \
|
|
|
|
'--version[Print version information]' \
|
2020-12-27 23:05:27 +00:00
|
|
|
&& ret=0
|
|
|
|
;;
|
2020-12-27 19:47:30 +00:00
|
|
|
(help)
|
|
|
|
_arguments "${_arguments_options[@]}" \
|
|
|
|
&& ret=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
(( $+functions[_my_app_commands] )) ||
|
|
|
|
_my_app_commands() {
|
|
|
|
local commands; commands=(
|
2020-12-28 00:02:30 +00:00
|
|
|
'test:tests things' \
|
2020-12-27 22:31:23 +00:00
|
|
|
'some_cmd:tests other things' \
|
|
|
|
'some-cmd-with-hypens:' \
|
2020-12-27 23:05:27 +00:00
|
|
|
'some_cmd_with_special_characters:This '\''is'\'' a "special" \[character\] string \\' \
|
2021-07-30 03:23:25 +00:00
|
|
|
'help:Print this message or the help of the given subcommand(s)' \
|
2020-12-27 19:47:30 +00:00
|
|
|
)
|
|
|
|
_describe -t commands 'my_app commands' commands "$@"
|
|
|
|
}
|
|
|
|
(( $+functions[_my_app__help_commands] )) ||
|
|
|
|
_my_app__help_commands() {
|
2020-12-28 00:02:30 +00:00
|
|
|
local commands; commands=()
|
2020-12-27 19:47:30 +00:00
|
|
|
_describe -t commands 'my_app help commands' commands "$@"
|
|
|
|
}
|
|
|
|
(( $+functions[_my_app__some-cmd-with-hypens_commands] )) ||
|
|
|
|
_my_app__some-cmd-with-hypens_commands() {
|
2020-12-28 00:02:30 +00:00
|
|
|
local commands; commands=()
|
2020-12-27 19:47:30 +00:00
|
|
|
_describe -t commands 'my_app some-cmd-with-hypens commands' commands "$@"
|
|
|
|
}
|
|
|
|
(( $+functions[_my_app__some_cmd_commands] )) ||
|
|
|
|
_my_app__some_cmd_commands() {
|
2020-12-28 00:02:30 +00:00
|
|
|
local commands; commands=()
|
2020-12-27 19:47:30 +00:00
|
|
|
_describe -t commands 'my_app some_cmd commands' commands "$@"
|
|
|
|
}
|
2020-12-27 23:05:27 +00:00
|
|
|
(( $+functions[_my_app__some_cmd_with_special_characters_commands] )) ||
|
|
|
|
_my_app__some_cmd_with_special_characters_commands() {
|
2020-12-28 00:02:30 +00:00
|
|
|
local commands; commands=()
|
2020-12-27 23:05:27 +00:00
|
|
|
_describe -t commands 'my_app some_cmd_with_special_characters commands' commands "$@"
|
|
|
|
}
|
2020-12-27 19:47:30 +00:00
|
|
|
(( $+functions[_my_app__test_commands] )) ||
|
|
|
|
_my_app__test_commands() {
|
2020-12-28 00:02:30 +00:00
|
|
|
local commands; commands=()
|
2020-12-27 19:47:30 +00:00
|
|
|
_describe -t commands 'my_app test commands' commands "$@"
|
|
|
|
}
|
|
|
|
|
2022-01-09 12:48:17 +00:00
|
|
|
_my_app "$@"
|
|
|
|
"#;
|
2020-12-27 19:47:30 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn zsh_with_special_help() {
|
|
|
|
let mut app = build_app_special_help();
|
2021-08-18 18:25:43 +00:00
|
|
|
common(Zsh, &mut app, "my_app", ZSH_SPECIAL_HELP);
|
2020-12-27 19:47:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 22:50:20 +00:00
|
|
|
fn build_app_special_help() -> App<'static> {
|
|
|
|
App::new("my_app")
|
2021-10-08 17:05:40 +00:00
|
|
|
.version("3.0")
|
2020-12-27 22:50:20 +00:00
|
|
|
.arg(
|
|
|
|
Arg::new("single-quotes")
|
|
|
|
.long("single-quotes")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Can be 'always', 'auto', or 'never'"),
|
2020-12-27 22:50:20 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("double-quotes")
|
|
|
|
.long("double-quotes")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Can be \"always\", \"auto\", or \"never\""),
|
2020-12-27 22:50:20 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("backticks")
|
|
|
|
.long("backticks")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("For more information see `echo test`"),
|
2020-12-27 22:50:20 +00:00
|
|
|
)
|
2021-11-18 16:17:15 +00:00
|
|
|
.arg(Arg::new("backslash").long("backslash").help("Avoid '\\n'"))
|
2020-12-27 22:50:20 +00:00
|
|
|
.arg(
|
|
|
|
Arg::new("brackets")
|
|
|
|
.long("brackets")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("List packages [filter]"),
|
2020-12-27 22:50:20 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("expansions")
|
|
|
|
.long("expansions")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Execute the shell command with $SHELL"),
|
2020-12-27 22:50:20 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-12-27 19:47:30 +00:00
|
|
|
static ZSH_SPECIAL_HELP: &str = r#"#compdef my_app
|
|
|
|
|
|
|
|
autoload -U is-at-least
|
|
|
|
|
|
|
|
_my_app() {
|
|
|
|
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[@]}" \
|
2021-07-30 03:23:25 +00:00
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
|
|
|
'-V[Print version information]' \
|
|
|
|
'--version[Print version information]' \
|
2020-12-27 19:47:30 +00:00
|
|
|
'--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]' \
|
|
|
|
&& ret=0
|
|
|
|
}
|
|
|
|
|
|
|
|
(( $+functions[_my_app_commands] )) ||
|
|
|
|
_my_app_commands() {
|
2020-12-28 00:02:30 +00:00
|
|
|
local commands; commands=()
|
2020-12-27 19:47:30 +00:00
|
|
|
_describe -t commands 'my_app commands' commands "$@"
|
|
|
|
}
|
|
|
|
|
2022-01-09 12:48:17 +00:00
|
|
|
_my_app "$@"
|
|
|
|
"#;
|
2020-12-27 19:47:30 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn zsh_with_nested_subcommands() {
|
|
|
|
let mut app = build_app_nested_subcommands();
|
2021-08-18 18:25:43 +00:00
|
|
|
common(Zsh, &mut app, "my_app", ZSH_NESTED_SUBCOMMANDS);
|
2020-12-27 19:47:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 22:50:20 +00:00
|
|
|
fn build_app_nested_subcommands() -> App<'static> {
|
2021-10-08 17:05:40 +00:00
|
|
|
App::new("first")
|
|
|
|
.version("3.0")
|
|
|
|
.subcommand(App::new("second").subcommand(App::new("third")))
|
2020-12-27 22:50:20 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 19:47:30 +00:00
|
|
|
static ZSH_NESTED_SUBCOMMANDS: &str = r#"#compdef my_app
|
|
|
|
|
|
|
|
autoload -U is-at-least
|
|
|
|
|
|
|
|
_my_app() {
|
|
|
|
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[@]}" \
|
2021-07-30 03:23:25 +00:00
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
|
|
|
'-V[Print version information]' \
|
|
|
|
'--version[Print version information]' \
|
2020-12-27 19:47:30 +00:00
|
|
|
":: :_my_app_commands" \
|
|
|
|
"*::: :->first" \
|
|
|
|
&& ret=0
|
|
|
|
case $state in
|
|
|
|
(first)
|
|
|
|
words=($line[1] "${words[@]}")
|
|
|
|
(( CURRENT += 1 ))
|
|
|
|
curcontext="${curcontext%:*:*}:my_app-command-$line[1]:"
|
|
|
|
case $line[1] in
|
|
|
|
(second)
|
|
|
|
_arguments "${_arguments_options[@]}" \
|
2021-07-30 03:23:25 +00:00
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
2020-12-27 19:47:30 +00:00
|
|
|
":: :_my_app__second_commands" \
|
|
|
|
"*::: :->second" \
|
|
|
|
&& ret=0
|
2021-10-11 23:17:09 +00:00
|
|
|
|
|
|
|
case $state in
|
2020-12-27 19:47:30 +00:00
|
|
|
(second)
|
|
|
|
words=($line[1] "${words[@]}")
|
|
|
|
(( CURRENT += 1 ))
|
|
|
|
curcontext="${curcontext%:*:*}:my_app-second-command-$line[1]:"
|
|
|
|
case $line[1] in
|
|
|
|
(third)
|
|
|
|
_arguments "${_arguments_options[@]}" \
|
2021-10-12 18:59:56 +00:00
|
|
|
'--version[Print version information]' \
|
|
|
|
'-h[Print help information]' \
|
2021-07-30 03:23:25 +00:00
|
|
|
'--help[Print help information]' \
|
2021-10-12 18:59:56 +00:00
|
|
|
&& ret=0
|
|
|
|
;;
|
|
|
|
(help)
|
|
|
|
_arguments "${_arguments_options[@]}" \
|
2021-07-30 03:23:25 +00:00
|
|
|
'--version[Print version information]' \
|
2021-10-12 18:59:56 +00:00
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
2020-12-27 19:47:30 +00:00
|
|
|
&& ret=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
(help)
|
|
|
|
_arguments "${_arguments_options[@]}" \
|
|
|
|
&& ret=0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
(( $+functions[_my_app_commands] )) ||
|
|
|
|
_my_app_commands() {
|
|
|
|
local commands; commands=(
|
2020-12-28 00:02:30 +00:00
|
|
|
'second:' \
|
2021-07-30 03:23:25 +00:00
|
|
|
'help:Print this message or the help of the given subcommand(s)' \
|
2020-12-27 19:47:30 +00:00
|
|
|
)
|
|
|
|
_describe -t commands 'my_app commands' commands "$@"
|
|
|
|
}
|
|
|
|
(( $+functions[_my_app__help_commands] )) ||
|
|
|
|
_my_app__help_commands() {
|
2020-12-28 00:02:30 +00:00
|
|
|
local commands; commands=()
|
2020-12-27 19:47:30 +00:00
|
|
|
_describe -t commands 'my_app help commands' commands "$@"
|
|
|
|
}
|
2021-10-12 18:59:56 +00:00
|
|
|
(( $+functions[_my_app__second__help_commands] )) ||
|
|
|
|
_my_app__second__help_commands() {
|
|
|
|
local commands; commands=()
|
|
|
|
_describe -t commands 'my_app second help commands' commands "$@"
|
|
|
|
}
|
2020-12-27 19:47:30 +00:00
|
|
|
(( $+functions[_my_app__second_commands] )) ||
|
|
|
|
_my_app__second_commands() {
|
|
|
|
local commands; commands=(
|
2020-12-28 00:02:30 +00:00
|
|
|
'third:' \
|
2021-10-12 18:59:56 +00:00
|
|
|
'help:Print this message or the help of the given subcommand(s)' \
|
2020-12-27 19:47:30 +00:00
|
|
|
)
|
|
|
|
_describe -t commands 'my_app second commands' commands "$@"
|
|
|
|
}
|
|
|
|
(( $+functions[_my_app__second__third_commands] )) ||
|
|
|
|
_my_app__second__third_commands() {
|
2020-12-28 00:02:30 +00:00
|
|
|
local commands; commands=()
|
2020-12-27 19:47:30 +00:00
|
|
|
_describe -t commands 'my_app second third commands' commands "$@"
|
|
|
|
}
|
|
|
|
|
2022-01-09 12:48:17 +00:00
|
|
|
_my_app "$@"
|
|
|
|
"#;
|
2021-02-15 08:35:25 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn zsh_with_aliases() {
|
|
|
|
let mut app = build_app_with_aliases();
|
2021-08-18 18:25:43 +00:00
|
|
|
common(Zsh, &mut app, "cmd", ZSH_ALIASES);
|
2021-02-15 08:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn build_app_with_aliases() -> App<'static> {
|
|
|
|
App::new("cmd")
|
2021-10-08 17:05:40 +00:00
|
|
|
.version("3.0")
|
2021-02-15 08:35:25 +00:00
|
|
|
.about("testing bash completions")
|
|
|
|
.arg(
|
|
|
|
Arg::new("flag")
|
|
|
|
.short('f')
|
|
|
|
.visible_short_alias('F')
|
|
|
|
.long("flag")
|
|
|
|
.visible_alias("flg")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("cmd flag"),
|
2021-02-15 08:35:25 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("option")
|
|
|
|
.short('o')
|
|
|
|
.visible_short_alias('O')
|
|
|
|
.long("option")
|
|
|
|
.visible_alias("opt")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("cmd option")
|
2021-02-15 08:35:25 +00:00
|
|
|
.takes_value(true),
|
|
|
|
)
|
|
|
|
.arg(Arg::new("positional"))
|
|
|
|
}
|
|
|
|
|
|
|
|
static ZSH_ALIASES: &str = r#"#compdef cmd
|
|
|
|
|
|
|
|
autoload -U is-at-least
|
|
|
|
|
|
|
|
_cmd() {
|
|
|
|
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[@]}" \
|
2021-10-07 18:39:45 +00:00
|
|
|
'-o+[cmd option]: : ' \
|
|
|
|
'-O+[cmd option]: : ' \
|
|
|
|
'--option=[cmd option]: : ' \
|
|
|
|
'--opt=[cmd option]: : ' \
|
2021-07-30 03:23:25 +00:00
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
|
|
|
'-V[Print version information]' \
|
|
|
|
'--version[Print version information]' \
|
2021-02-15 08:35:25 +00:00
|
|
|
'-f[cmd flag]' \
|
|
|
|
'-F[cmd flag]' \
|
|
|
|
'--flag[cmd flag]' \
|
|
|
|
'--flg[cmd flag]' \
|
|
|
|
'::positional:' \
|
|
|
|
&& ret=0
|
|
|
|
}
|
|
|
|
|
|
|
|
(( $+functions[_cmd_commands] )) ||
|
|
|
|
_cmd_commands() {
|
|
|
|
local commands; commands=()
|
|
|
|
_describe -t commands 'cmd commands' commands "$@"
|
|
|
|
}
|
|
|
|
|
2022-01-09 12:48:17 +00:00
|
|
|
_cmd "$@"
|
|
|
|
"#;
|
2021-10-07 18:39:45 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn zsh_with_files_and_dirs() {
|
|
|
|
let mut app = build_app_with_files_and_dirs();
|
|
|
|
common(Zsh, &mut app, "my_app", ZSH_PATHS);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn build_app_with_files_and_dirs() -> App<'static> {
|
|
|
|
App::new("my_app")
|
|
|
|
.version("3.0")
|
|
|
|
.about("testing zsh completions")
|
|
|
|
.arg(
|
|
|
|
Arg::new("directory")
|
|
|
|
.long("dir")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("specify a directory")
|
2021-10-07 18:39:45 +00:00
|
|
|
.value_name("DIR")
|
|
|
|
.number_of_values(3)
|
|
|
|
.value_hint(ValueHint::DirPath),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("file")
|
|
|
|
.long("inputfiles")
|
|
|
|
.value_name("FILE")
|
|
|
|
.multiple_occurrences(true)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("specify a file")
|
2021-10-07 18:39:45 +00:00
|
|
|
.value_hint(ValueHint::FilePath),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
static ZSH_PATHS: &str = r#"#compdef my_app
|
|
|
|
|
|
|
|
autoload -U is-at-least
|
|
|
|
|
|
|
|
_my_app() {
|
|
|
|
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[@]}" \
|
|
|
|
'--dir=[specify a directory]:DIR:_files -/:DIR:_files -/:DIR:_files -/' \
|
|
|
|
'*--inputfiles=[specify a file]:FILE:_files' \
|
|
|
|
'-h[Print help information]' \
|
|
|
|
'--help[Print help information]' \
|
|
|
|
'-V[Print version information]' \
|
|
|
|
'--version[Print version information]' \
|
|
|
|
&& ret=0
|
|
|
|
}
|
|
|
|
|
|
|
|
(( $+functions[_my_app_commands] )) ||
|
|
|
|
_my_app_commands() {
|
|
|
|
local commands; commands=()
|
|
|
|
_describe -t commands 'my_app commands' commands "$@"
|
|
|
|
}
|
|
|
|
|
2022-01-09 12:48:17 +00:00
|
|
|
_my_app "$@"
|
|
|
|
"#;
|