├── .github └── workflows │ ├── ci.yaml │ └── release.yaml ├── .gitignore ├── Argcfile.sh ├── Cargo.lock ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── docs ├── command-runner.md ├── specification.md └── variables.md ├── examples ├── README.md ├── args.sh ├── bind-envs.sh ├── combine-shorts.sh ├── default-subcommand.sh ├── demo.sh ├── envs.sh ├── hooks.sh ├── inherit-flag-options.sh ├── multiline.sh ├── nested-commands.sh ├── options.sh ├── parallel.sh ├── require-tools.sh ├── strict.sh └── symbol.sh ├── install.sh ├── src ├── argc_value.rs ├── bin │ └── argc │ │ ├── completion.sh │ │ ├── main.rs │ │ └── parallel.rs ├── build.rs ├── command │ ├── mod.rs │ ├── names_checker.rs │ └── share_data.rs ├── compgen.rs ├── completions │ ├── argc.bash │ ├── argc.elv │ ├── argc.fish │ ├── argc.nu │ ├── argc.ps1 │ ├── argc.xsh │ ├── argc.zsh │ └── mod.rs ├── lib.rs ├── mangen.rs ├── matcher.rs ├── param.rs ├── parser.rs ├── runtime │ ├── mod.rs │ └── navite.rs ├── shell.rs └── utils.rs └── tests ├── bind_env.rs ├── cli.rs ├── compgen.rs ├── env.rs ├── fail.rs ├── fixtures.rs ├── hook_fn.rs ├── macros.rs ├── main_fn.rs ├── meta.rs ├── misc.rs ├── multiline.rs ├── param_fn.rs ├── snapshots ├── integration__bind_env__bind_env_arg1.snap ├── integration__bind_env__bind_env_arg2.snap ├── integration__bind_env__bind_env_arg_choice_err.snap ├── integration__bind_env__bind_env_arg_choice_fn_err.snap ├── integration__bind_env__bind_env_cmd_three_required_args.snap ├── integration__bind_env__bind_env_cmd_three_required_args_err.snap ├── integration__bind_env__bind_env_flags.snap ├── integration__bind_env__bind_env_flags_bool_err.snap ├── integration__bind_env__bind_env_flags_bool_ok.snap ├── integration__bind_env__bind_env_flags_help.snap ├── integration__bind_env__bind_env_flags_ok.snap ├── integration__bind_env__bind_env_multi_arg_with_choice_fn_and_comma_sep.snap ├── integration__bind_env__bind_env_options.snap ├── integration__bind_env__bind_env_options_choice_err.snap ├── integration__bind_env__bind_env_options_choice_fn_err.snap ├── integration__bind_env__bind_env_options_choice_ok.snap ├── integration__bind_env__bind_env_options_help.snap ├── integration__bind_env__bind_env_options_required_err.snap ├── integration__bind_env__bind_env_with_notation.snap ├── integration__bind_env__bind_env_with_notation_help.snap ├── integration__cli__export.snap ├── integration__cli__parallel.snap ├── integration__compgen__arg_terminated.snap ├── integration__compgen__assign_option_value.snap ├── integration__compgen__auto_alias_subcommand.snap ├── integration__compgen__bash_shell.snap ├── integration__compgen__break_chars_bash.snap ├── integration__compgen__break_chars_powershell.snap ├── integration__compgen__choice.snap ├── integration__compgen__choice_check_vars.snap ├── integration__compgen__choice_multi.snap ├── integration__compgen__choice_slash.snap ├── integration__compgen__cmd_aliases.snap ├── integration__compgen__color.snap ├── integration__compgen__dashes_at.snap ├── integration__compgen__default_subcommand.snap ├── integration__compgen__delegated.snap ├── integration__compgen__desc.snap ├── integration__compgen__desc2.snap ├── integration__compgen__escape.snap ├── integration__compgen__fallback_comp_file.snap ├── integration__compgen__filedir__cd.snap ├── integration__compgen__filedir__cd_win.snap ├── integration__compgen__filedir__value_name.snap ├── integration__compgen__filedir__value_name_win.snap ├── integration__compgen__filter_quote.snap ├── integration__compgen__flag_cmds.snap ├── integration__compgen__inherit_flag_options.snap ├── integration__compgen__just_match.snap ├── integration__compgen__kinds_of.snap ├── integration__compgen__last_arg_option_assign.snap ├── integration__compgen__multi_char.snap ├── integration__compgen__multi_char2.snap ├── integration__compgen__multi_parts.snap ├── integration__compgen__multi_parts2.snap ├── integration__compgen__multiline_doc.snap ├── integration__compgen__multiple.snap ├── integration__compgen__nested_subcmds.snap ├── integration__compgen__no_comp_subcmds.snap ├── integration__compgen__no_flags_options.snap ├── integration__compgen__no_flags_options2.snap ├── integration__compgen__no_param.snap ├── integration__compgen__no_space.snap ├── integration__compgen__one_combine_shorts.snap ├── integration__compgen__one_subcmd_with_options.snap ├── integration__compgen__option_assigned.snap ├── integration__compgen__option_prefixed.snap ├── integration__compgen__option_terminated.snap ├── integration__compgen__plus_sign.snap ├── integration__compgen__positionals.snap ├── integration__compgen__redirect_symbols.snap ├── integration__compgen__shorts.snap ├── integration__compgen__special_arg_name.snap ├── integration__compgen__starts_quote.snap ├── integration__compgen__starts_quote2.snap ├── integration__compgen__subcmds.snap ├── integration__compgen__suffix.snap ├── integration__compgen__symbol.snap ├── integration__compgen__value.snap ├── integration__compgen__value_display.snap ├── integration__env__env_choice.snap ├── integration__env__env_choice_fn.snap ├── integration__env__env_help.snap ├── integration__env__env_help_subcmd.snap ├── integration__env__env_missing.snap ├── integration__env__env_run.snap ├── integration__hook_fn__hook_only_after.snap ├── integration__hook_fn__hook_only_before.snap ├── integration__hook_fn__hook_param_fn.snap ├── integration__hook_fn__hook_with_main.snap ├── integration__hook_fn__hook_with_subcmd.snap ├── integration__hook_fn__hook_without_subcmd.snap ├── integration__main_fn__global_with_arg.snap ├── integration__main_fn__global_without_arg.snap ├── integration__main_fn__nested_subcmd_main.snap ├── integration__main_fn__nested_subcmd_main2.snap ├── integration__main_fn__nested_subcmd_no_main.snap ├── integration__main_fn__no_main.snap ├── integration__main_fn__subcmd_main.snap ├── integration__main_fn__subcmd_no_main.snap ├── integration__main_fn__with_main.snap ├── integration__main_fn__with_main2.snap ├── integration__meta__dotenv.snap ├── integration__meta__dotenv_custom_path.snap ├── integration__misc__escape.snap ├── integration__multiline__nowrap.snap ├── integration__multiline__wrap.snap ├── integration__multiline__wrap2.snap ├── integration__param_fn__case1.snap ├── integration__param_fn__case2.snap ├── integration__param_fn__case3.snap ├── integration__spec__arg_eval.snap ├── integration__spec__arg_no_option.snap ├── integration__spec__arg_no_param.snap ├── integration__spec__arg_subcmd_help.snap ├── integration__spec__arg_terminated.snap ├── integration__spec__arg_two_multi.snap ├── integration__spec__auto_alias_subcommand.snap ├── integration__spec__cmd_combine_shorts.snap ├── integration__spec__cmd_with_hyphen.snap ├── integration__spec__dash_split.snap ├── integration__spec__default_subcommand.snap ├── integration__spec__inherit_flag_options.snap ├── integration__spec__name_with_special_chars.snap ├── integration__spec__notation_modifier.snap ├── integration__spec__option_assigned.snap ├── integration__spec__option_eval.snap ├── integration__spec__option_help.snap ├── integration__spec__option_multiple.snap ├── integration__spec__option_prefixed.snap ├── integration__spec__option_shorts.snap ├── integration__spec__option_single_dash.snap ├── integration__spec__option_terminated.snap ├── integration__spec__option_to_variable.snap ├── integration__spec__option_value_dash.snap ├── integration__spec__plus_sign.snap ├── integration__spec__same_option_positional.snap ├── integration__spec__symbol.snap ├── integration__spec__undefine_positionals.snap ├── integration__validate__arg_choice.snap ├── integration__validate__arg_choice_fn.snap ├── integration__validate__arg_choice_fn_pass.snap ├── integration__validate__arg_choice_fn_skip.snap ├── integration__validate__arg_choice_multi.snap ├── integration__validate__arg_help_subcmd.snap ├── integration__validate__arg_invalid_subcmd.snap ├── integration__validate__arg_missing.snap ├── integration__validate__arg_unknown.snap ├── integration__validate__choice_access_vars.snap ├── integration__validate__choice_slash.snap ├── integration__validate__cmd_name_sanitize.snap ├── integration__validate__delimiter.snap ├── integration__validate__empty_choices.snap ├── integration__validate__escape_at_symbol.snap ├── integration__validate__flag_not_multiple.snap ├── integration__validate__flag_with_value.snap ├── integration__validate__help_notations.snap ├── integration__validate__help_version.snap ├── integration__validate__help_version_exist.snap ├── integration__validate__help_version_legacy.snap ├── integration__validate__help_version_shadow.snap ├── integration__validate__option_choice.snap ├── integration__validate__option_choice_fn.snap ├── integration__validate__option_choice_fn_pass.snap ├── integration__validate__option_choice_fn_skip.snap ├── integration__validate__option_choice_multi.snap ├── integration__validate__option_mismatch_values.snap ├── integration__validate__option_missing.snap ├── integration__validate__option_not_multiple.snap ├── integration__validate__option_unknown.snap ├── integration__validate__param_missing.snap ├── integration__validate__param_missing_parent.snap ├── integration__validate__require_tools.snap └── integration__validate__version_missing.snap ├── spec.rs ├── tests.rs └── validate.rs /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - '*' 7 | push: 8 | branches: 9 | - main 10 | 11 | defaults: 12 | run: 13 | shell: bash 14 | 15 | jobs: 16 | all: 17 | name: All 18 | 19 | strategy: 20 | matrix: 21 | os: 22 | - ubuntu-latest 23 | - macos-latest 24 | - windows-latest 25 | 26 | runs-on: ${{matrix.os}} 27 | 28 | env: 29 | RUSTFLAGS: --deny warnings 30 | 31 | steps: 32 | - uses: actions/checkout@v4 33 | 34 | - name: Install Rust Toolchain Components 35 | uses: dtolnay/rust-toolchain@stable 36 | 37 | - uses: Swatinem/rust-cache@v2 38 | 39 | - name: Install Bash 5 on macOS 40 | if: runner.os == 'macOS' 41 | run: | 42 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" 43 | brew install bash 44 | bash --version 45 | 46 | - name: Test 47 | run: cargo test --all 48 | 49 | - name: Clippy 50 | run: cargo clippy --all --all-targets 51 | 52 | - name: Format 53 | run: cargo fmt --all --check 54 | 55 | features: 56 | runs-on: ubuntu-latest 57 | 58 | steps: 59 | - uses: actions/checkout@v4 60 | 61 | - name: Install Rust Toolchain Components 62 | uses: dtolnay/rust-toolchain@stable 63 | 64 | - uses: Swatinem/rust-cache@v2 65 | 66 | - uses: taiki-e/install-action@cargo-hack 67 | 68 | - run: cargo hack --no-dev-deps check --feature-powerset --depth 2 --lib -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .vscode -------------------------------------------------------------------------------- /Argcfile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | # @cmd Test the project 5 | # @alias t 6 | test() { 7 | cargo test "$@" 8 | } 9 | 10 | # @cmd Test features matrix 11 | test-features() { 12 | cargo hack --no-dev-deps check --feature-powerset --depth 2 --lib 13 | } 14 | 15 | # @cmd Check the project 16 | # @alias c 17 | check() { 18 | cargo fmt --all --check 19 | cargo clippy --all 20 | cargo test 21 | } 22 | 23 | # @cmd Fix the project 24 | # @alias f 25 | fix() { 26 | cargo fmt --all 27 | cargo clippy --fix --all --allow-dirty 28 | } 29 | 30 | # @cmd Code for setup shell to load argc completion script 31 | # @option -s --shell[=bash|elvish|fish|nushell|powershell|xonsh|zsh|tcsh] shell type 32 | # @arg cmds* any other scripts based on argc 33 | setup-shell() { 34 | case $argc_shell in 35 | bash) echo "source <(argc --argc-completions bash ${argc_cmds[@]})" ;; 36 | elvish) echo "eval (argc --argc-completions elvish ${argc_cmds[@]} | slurp)" ;; 37 | fish) echo "argc --argc-completions fish ${argc_cmds[@]} | source" ;; 38 | nushell) echo "argc --argc-completions nushell | save -f argc.nu"$'\n'"source argc.nu" ;; 39 | powershell) echo "argc --argc-completions powershell ${argc_cmds[@]} | Out-String | Invoke-Expression" ;; 40 | xonsh) echo "exec(\$(argc --argc-completions xonsh ${argc_cmds[@]}))" ;; 41 | zsh) echo "source <(argc --argc-completions zsh ${argc_cmds[@]})" ;; 42 | tcsh) echo "eval \`argc --argc-completions tcsh ${argc_cmds[@]}\`" ;; 43 | esac 44 | } 45 | 46 | eval "$(argc --argc-eval "$0" "$@")" -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "argc" 3 | version = "1.22.0" 4 | edition = "2021" 5 | authors = ["sigoden "] 6 | description = "A bash cli framework, also a bash-based command runner" 7 | license = "MIT OR Apache-2.0" 8 | homepage = "https://github.com/sigoden/argc" 9 | repository = "https://github.com/sigoden/argc" 10 | autotests = false 11 | categories = ["command-line-utilities", "development-tools"] 12 | keywords = ["cli", "bash", "runner", "arg", "parser"] 13 | 14 | [features] 15 | default = ["application"] 16 | # Feature required for argc the application. Should be disabled when depending on 17 | # argc as a library. 18 | application = [ 19 | "native-runtime", 20 | "eval-bash", 21 | "build", 22 | "mangen", 23 | "completions", 24 | "compgen", 25 | "export", 26 | "wrap-help", 27 | 28 | # deps 29 | "num_cpus", 30 | "threadpool", 31 | "base64", 32 | "path-absolutize" 33 | ] 34 | native-runtime = ["which"] 35 | eval = [] 36 | eval-bash = ["eval"] 37 | build = [] 38 | mangen = ["roff"] 39 | completions = [] 40 | compgen = ["dirs", "natord"] 41 | export = ["serde_json", "indexmap/serde"] 42 | wrap-help = ["textwrap"] 43 | 44 | [dependencies] 45 | anyhow = "1" 46 | convert_case = "0.6" 47 | indexmap = { version = "2.1" } 48 | nom = "7.1" 49 | either = "1.8" 50 | serde = { version = "1.0", features = ["derive"] } 51 | serde_json = { version = "1.0", features = ["preserve_order"], optional = true } 52 | which = { version = "7.0", optional = true } 53 | shell-words = "1.1" 54 | textwrap = { version = "0.16", optional = true } 55 | dirs = { version = "5.0", optional = true } 56 | num_cpus = { version = "1.16", optional = true } 57 | threadpool = { version = "1.8", optional = true } 58 | base64 = { version = "0.22", optional = true } 59 | natord = { version = "1.0", optional = true } 60 | roff = { version = "0.2", optional = true } 61 | path-absolutize = { version = "3.1.1", optional = true } 62 | 63 | [dev-dependencies] 64 | insta = "1.30" 65 | assert_cmd = "2" 66 | assert_fs = "1" 67 | rstest = "0.23" 68 | predicates = "3" 69 | 70 | [target.'cfg(unix)'.dev-dependencies] 71 | libc = "0.2" 72 | 73 | [profile.release] 74 | lto = true 75 | strip = true 76 | opt-level = "z" 77 | 78 | [[test]] 79 | name = "integration" 80 | path = "tests/tests.rs" 81 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) sigoden 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/variables.md: -------------------------------------------------------------------------------- 1 | # Variables 2 | 3 | Argc streamlines argument parsing in your shell scripts, allowing you to utilize variables seamlessly. 4 | 5 | ## Shell Variables 6 | 7 | You can employ shell variables within your argc-based scripts just like you normally would in Bash. Argc doesn't interfere with their behavior. 8 | 9 | ```sh 10 | # @cmd 11 | cmd() { 12 | echo $1 $2 # Accessing positional arguments 13 | echo "$*" # All arguments as a single string 14 | echo "$@" # All arguments as separate strings 15 | } 16 | ``` 17 | 18 | ## Argc-Generated Variables 19 | 20 | Argc automatically creates variables corresponding to the options, flags, and positional arguments defined in your script using the `@option`, `@flag`, and `@arg` directives. 21 | 22 | ```sh 23 | # @option --oa 24 | # @option --ob* # Multiple values allowed 25 | # @flag --fa 26 | # @arg va 27 | # @arg vb* 28 | 29 | eval "$(argc --argc-eval "$0" "$@")" # Initializes Argc variables 30 | 31 | echo '--oa:' $argc_oa 32 | echo '--ob:' ${argc_ob[@]} # Accessing multiple values as an array 33 | echo '--fa:' $argc_fa 34 | echo ' va:' $argc_va 35 | echo ' vb:' ${argc_vb[@]} 36 | ``` 37 | 38 | Running `./script.sh --oa a --ob=b1 --ob=b2 --fa foo bar baz` would output: 39 | 40 | ``` 41 | --oa: a 42 | --ob: b1 b2 43 | --fa: 1 44 | va: foo 45 | vb: bar baz 46 | ``` 47 | 48 | ## Built-in Variables 49 | 50 | Argc also provides built-in variables that offer information about the parsing process: 51 | 52 | * **`argc__args`**: An array holding all command-line arguments. 53 | * **`argc__positionals`**: An array containing only the positional arguments. 54 | * **`argc__fn`**: The name of the function that will be executed. 55 | 56 | **Additional Variables for Completion (Used internally by Argc-Completions):** 57 | 58 | * **`argc__cmd_arg_index`**: Index of the command argument within `argc__args`. 59 | * **`argc__cmd_fn`**: Name of the command function. 60 | * **`argc__dash`**: Index of the first em-dash (`--`) within the positional arguments. 61 | * **`argc__option`**: Variable name of the option currently being completed. 62 | 63 | These variables are particularly useful when creating custom completion scripts. 64 | 65 | ## Environment Variables 66 | 67 | Several environment variables allow you to tailor Argc's behavior: 68 | 69 | **User-Defined:** 70 | 71 | * **`ARGC_SHELL_PATH`**: Specifies the path to the shell/bash executable used by Argc. 72 | * **`ARGC_SCRIPT_NAME`**: Overrides the default script filename (Argcfile.sh). 73 | * **`ARGC_COMPGEN_DESCRIPTION`**: Disables descriptions for completion candidates if set to 0 or false. 74 | * **`ARGC_COMPLETIONS_PATH`**: Defines the search path for Argc-based completion scripts. 75 | 76 | **Argc-Injected:** 77 | 78 | * **`ARGC_PWD`**: Current working directory (available only in Argcfile.sh). 79 | 80 | **Argc-Injected (for completion):** 81 | * **`ARGC_OS`**: Operating system type. 82 | * **`ARGC_COMPGEN`**: Indicates whether the script is being used for generating completion candidates (1) or not (0). 83 | * **`ARGC_CWORD`**: The last word in the processed command line. 84 | 85 | It's important to distinguish between these two variables: 86 | 87 | * **`ARGC_CWORD`**: This variable isolates the final word, regardless of any preceding flags or options. For example, in the command `git --git-dir=git`, `ARGC_CWORD` would be `git`. 88 | * **`ARGC_LAST_ARG`**: This variable captures the entire last argument, including any flags or options attached to it. In the same example, `ARGC_LAST_ARG` would be `--git-dir=git`. 89 | 90 | Understanding these variables is key to effectively leveraging Argc's capabilities and creating robust and user-friendly command-line interfaces. 91 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Argc Examples 2 | 3 | Each of these examples demonstrates one aspect or feature of argc. 4 | 5 | - [demo.sh](./demo.sh) - A simple demo script. 6 | - [multiline.sh](./multiline.sh) - how to use multiline help text. 7 | - [nested-commands](./nested-commands.sh) - how to use nested commands. 8 | - [hooks.sh](./hooks.sh) - how to use argc hooks. 9 | - [strict.sh](./strict.sh) - how to use strict mode 10 | - [parallel.sh](./parallel.sh) - how to use `--argc-parallel`. 11 | 12 | - [args.sh](./args.sh) - all kinds of `@arg`. 13 | - [options.sh](./options.sh) - all kinds of `@option` and `@flag`. 14 | - [bind-env](./bind-envs.sh) - how to bind env to param. 15 | - [envs.sh](./envs.sh) - all kind of `@env`. 16 | 17 | - [default-subcommand](./default-subcommand.sh) - how to use `@meta default-subcommand`. 18 | - [require-tools](./require-tools.sh) - how to use `@meta require-tools`. 19 | - [inherit-flag-options](./inherit-flag-options.sh) - how to use `@meta inherit-flag-options`. 20 | - [combine-short](./combine-shorts.sh) - how to use `@meta combine-shorts`. 21 | - [symbol](./symbol.sh): how to use `@meta symbol`. -------------------------------------------------------------------------------- /examples/args.sh: -------------------------------------------------------------------------------- 1 | # @describe All kinds of @arg 2 | 3 | # @cmd 4 | cmd() { 5 | _debug "$@" 6 | } 7 | 8 | # @cmd 9 | # @alias a 10 | cmd_alias() { 11 | _debug "$@" 12 | } 13 | 14 | # @cmd 15 | # @arg val 16 | cmd_arg() { 17 | _debug "$@" 18 | } 19 | 20 | # @cmd 21 | # @arg val* 22 | cmd_multi_arg() { 23 | _debug "$@" 24 | } 25 | 26 | # @cmd 27 | # @arg val+ 28 | cmd_required_multi_arg() { 29 | _debug "$@" 30 | } 31 | 32 | # @cmd 33 | # @arg val! 34 | cmd_required_arg() { 35 | _debug "$@" 36 | } 37 | 38 | # @cmd 39 | # @arg val=xyz 40 | cmd_arg_with_default() { 41 | _debug "$@" 42 | } 43 | 44 | # @cmd 45 | # @arg val=`_default_fn` 46 | cmd_arg_with_default_fn() { 47 | _debug "$@" 48 | } 49 | 50 | # @cmd 51 | # @arg val[x|y|z] 52 | cmd_arg_with_choices() { 53 | _debug "$@" 54 | } 55 | 56 | # @cmd 57 | # @arg val[=x|y|z] 58 | cmd_arg_with_choices_and_default() { 59 | _debug "$@" 60 | } 61 | 62 | # @cmd 63 | # @arg val*[x|y|z] 64 | cmd_multi_arg_with_choices() { 65 | _debug "$@" 66 | } 67 | 68 | # @cmd 69 | # @arg val+[x|y|z] 70 | cmd_required_multi_arg_with_choices() { 71 | _debug "$@" 72 | } 73 | 74 | # @cmd 75 | # @arg val[`_choice_fn`] 76 | cmd_arg_with_choice_fn() { 77 | _debug "$@" 78 | } 79 | 80 | # @cmd 81 | # @arg val[?`_choice_fn`] 82 | cmd_arg_with_choice_fn_and_skip_check() { 83 | _debug "$@" 84 | } 85 | 86 | 87 | # @cmd 88 | # @arg val![`_choice_fn`] 89 | cmd_required_arg_with_choice_fn() { 90 | _debug "$@" 91 | } 92 | 93 | # @cmd 94 | # @arg val*[`_choice_fn`] 95 | cmd_multi_arg_with_choice_fn() { 96 | _debug "$@" 97 | } 98 | 99 | # @cmd 100 | # @arg val+[`_choice_fn`] 101 | cmd_required_multi_arg_with_choice_fn() { 102 | _debug "$@" 103 | } 104 | 105 | 106 | # @cmd 107 | # @arg val*,[`_choice_fn`] 108 | cmd_multi_arg_with_choice_fn_and_comma_sep() { 109 | _debug "$@" 110 | } 111 | 112 | 113 | # @cmd 114 | # @arg vals~ 115 | cmd_terminaled() { 116 | _debug "$@" 117 | } 118 | 119 | # @cmd 120 | # @arg val 121 | cmd_arg_with_notation() { 122 | _debug "$@" 123 | } 124 | 125 | # @cmd 126 | # @arg val1* 127 | # @arg val2* 128 | cmd_two_multi_args() { 129 | _debug "$@" 130 | } 131 | 132 | # @cmd 133 | # @arg val1! 134 | # @arg val2+ 135 | cmd_one_required_second_required_multi() { 136 | _debug "$@" 137 | } 138 | 139 | # @cmd 140 | # @arg val1! 141 | # @arg val2! 142 | # @arg val3! 143 | cmd_three_required_args() { 144 | _debug "$@" 145 | } 146 | 147 | _debug() { 148 | ( set -o posix ; set ) | grep ^argc_ 149 | echo "$argc__fn" "$@" 150 | } 151 | 152 | _default_fn() { 153 | echo abc 154 | } 155 | 156 | _choice_fn() { 157 | echo abc 158 | echo def 159 | echo ghi 160 | } 161 | 162 | eval "$(argc --argc-eval "$0" "$@")" 163 | -------------------------------------------------------------------------------- /examples/bind-envs.sh: -------------------------------------------------------------------------------- 1 | # @cmd How to bind env to param 2 | 3 | # @flag --fa1 $$ 4 | # @flag --fa2 $$ 5 | # @flag --fa3 $FA 6 | # @flag --fc* $$ 7 | # @flag --fd $$ 8 | flags() { 9 | _debug "$@" 10 | } 11 | 12 | # @cmd 13 | # @option --oa1 $$ 14 | # @option --oa2 $$ 15 | # @option --oa3 $OA 16 | # @option --ob! $OB 17 | # @option --oc*, $$ 18 | # @option --oda=a $$ 19 | # @option --odb=`_default_fn` $$ 20 | # @option --oca[a|b] $$ 21 | # @option --occ*[a|b] $$ 22 | # @option --ofa[`_choice_fn`] $$ 23 | # @option --ofd*,[`_choice_fn`] $$ 24 | # @option --oxa~ $$ 25 | options() { 26 | _debug "$@" 27 | } 28 | 29 | # @cmd 30 | # @arg val $$ 31 | cmd_arg1() { 32 | _debug "$@" 33 | } 34 | 35 | # @cmd 36 | # @arg val $VA 37 | cmd_arg2() { 38 | _debug "$@" 39 | } 40 | 41 | # @cmd 42 | # @arg val=xyz $$ 43 | cmd_arg_with_default() { 44 | _debug "$@" 45 | } 46 | 47 | # @cmd 48 | # @arg val[x|y|z] $$ 49 | cmd_arg_with_choice() { 50 | _debug "$@" 51 | } 52 | 53 | # @cmd 54 | # @arg val[`_choice_fn`] $$ 55 | cmd_arg_with_choice_fn() { 56 | _debug "$@" 57 | } 58 | 59 | # @cmd 60 | # @arg val*,[`_choice_fn`] $$ 61 | cmd_multi_arg_with_choice_fn_and_comma_sep() { 62 | _debug "$@" 63 | } 64 | 65 | # @cmd 66 | # @arg val1! $$ 67 | # @arg val2! $$ 68 | # @arg val3! $$ 69 | cmd_three_required_args() { 70 | _debug "$@" 71 | } 72 | 73 | # @cmd 74 | # @option --OA $$ 75 | # @arg val $$ 76 | cmd_for_notation() { 77 | _debug "$@" 78 | } 79 | 80 | _debug() { 81 | ( set -o posix ; set ) | grep ^argc_ 82 | echo "$argc__fn" "$@" 83 | } 84 | 85 | _default_fn() { 86 | echo argc 87 | } 88 | 89 | _choice_fn() { 90 | echo abc 91 | echo def 92 | echo ghi 93 | } 94 | 95 | eval "$(argc --argc-eval "$0" "$@")" -------------------------------------------------------------------------------- /examples/combine-shorts.sh: -------------------------------------------------------------------------------- 1 | # @describe How to use `@meta combine-shorts` 2 | # 3 | # Mock rm cli 4 | # Examples: 5 | # prog -rf dir1 dir2 6 | # 7 | # @meta combine-shorts 8 | # @flag -r --recursive remove directories and their contents recursively 9 | # @flag -f --force ignore nonexistent files and arguments, never prompt 10 | # @arg path* the path to remove 11 | 12 | eval "$(argc --argc-eval "$0" "$@")" 13 | 14 | _debug() { 15 | ( set -o posix ; set ) | grep ^argc_ 16 | echo "$argc__fn" "$@" 17 | } 18 | 19 | _debug -------------------------------------------------------------------------------- /examples/default-subcommand.sh: -------------------------------------------------------------------------------- 1 | # describe How to use `@meta default-subcommand` 2 | 3 | # @cmd Upload a file 4 | # @meta default-subcommand 5 | upload() { 6 | echo upload "$@" 7 | } 8 | 9 | # @cmd Download a file 10 | download() { 11 | echo download "$@" 12 | } 13 | 14 | eval "$(argc --argc-eval "$0" "$@")" -------------------------------------------------------------------------------- /examples/demo.sh: -------------------------------------------------------------------------------- 1 | # @describe A demo cli 2 | 3 | # @cmd Upload a file 4 | # @alias u 5 | # @arg target! File to upload 6 | upload() { 7 | echo "cmd upload" 8 | echo "arg: target $argc_target" 9 | } 10 | 11 | # @cmd Download a file 12 | # @alias d 13 | # @flag -f --force Override existing file 14 | # @option -t --tries Set number of retries to NUM 15 | # @arg source! Url to download from 16 | # @arg target Save file to 17 | download() { 18 | echo "cmd: download" 19 | echo "flag: --force $argc_force" 20 | echo "option: --tries $argc_tries" 21 | echo "arg: source $argc_source" 22 | echo "arg: target $argc_target" 23 | } 24 | 25 | eval "$(argc --argc-eval "$0" "$@")" 26 | -------------------------------------------------------------------------------- /examples/envs.sh: -------------------------------------------------------------------------------- 1 | # @describe All kinds of @env 2 | 3 | # @meta dotenv 4 | # @env TEST_EA optional 5 | # @env TEST_EB! required 6 | # @env TEST_EDA=a default 7 | # @env TEST_EDB=`_default_fn` default from fn 8 | # @env TEST_ECA[a|b] choice 9 | # @env TEST_ECB[=a|b] choice + default 10 | # @env TEST_EFA[`_choice_fn`] choice from fn 11 | 12 | # @cmd 13 | # @env TEST_EA override 14 | # @env TEST_NEW append 15 | run() { 16 | _debug 17 | } 18 | 19 | main() { 20 | _debug 21 | } 22 | 23 | _debug() { 24 | printenv | grep ^TEST_ | sort 25 | } 26 | 27 | _default_fn() { 28 | echo argc 29 | } 30 | 31 | _choice_fn() { 32 | echo abc 33 | echo def 34 | echo ghi 35 | } 36 | 37 | eval "$(argc --argc-eval "$0" "$@")" -------------------------------------------------------------------------------- /examples/hooks.sh: -------------------------------------------------------------------------------- 1 | #/usr/bin/env node 2 | set -e 3 | 4 | # @describe How to use argc hooks 5 | # 6 | # Argc supports two hooks: 7 | # _argc_before: call before running the command function (after initialized variables) 8 | # _argc_after: call after running the command function 9 | 10 | _argc_before() { 11 | echo before 12 | } 13 | 14 | _argc_after() { 15 | echo after 16 | } 17 | 18 | main() { 19 | echo main 20 | } 21 | 22 | eval "$(argc --argc-eval "$0" "$@")" -------------------------------------------------------------------------------- /examples/inherit-flag-options.sh: -------------------------------------------------------------------------------- 1 | # @describe How to use `@meta inherit-flag-options` 2 | # 3 | # Mock systemctl cli 4 | # Examples: 5 | # prog --user start my-service 6 | # prog --user stop my-service 7 | # 8 | # @meta inherit-flag-options 9 | # @flag --user Connect to user service manager 10 | # @flag --no-pager Do not pipe output into a pager 11 | # @option -t --type List units of a particular type 12 | # @option --state List units with particular LOAD or SUB or ACTIVE state 13 | 14 | # @cmd Start (activate) one or more units 15 | # @arg UNIT... The unit files to start 16 | start() { 17 | :; 18 | } 19 | 20 | # @cmd Stop (deactivate) one or more units 21 | # @arg UNIT... The unit files to stop 22 | stop() { 23 | :; 24 | } 25 | 26 | eval "$(argc --argc-eval "$0" "$@")" -------------------------------------------------------------------------------- /examples/multiline.sh: -------------------------------------------------------------------------------- 1 | # @describe How to use multiline help text 2 | # 3 | # Extra lines after the comment tag accepts description, which don't start with an `@`, 4 | # are treated as the long description. A line which is not a comment ends the block. 5 | 6 | # @meta version 1.0.0 7 | # @meta author nobody 8 | 9 | # @option --foo[=default|full|auto] Sunshine gleams over hills afar, bringing warmth and hope to every soul, yet challenges await as we journey forth, striving for dreams and joy in abundance. Peaceful rivers whisper secrets gently heard. 10 | # * default: enables recommended style components. 11 | # * full: enables all available components. 12 | # * auto: same as 'default', unless the output is piped. 13 | # @option --bar Eager dogs jump quickly over the lazy brown fox, swiftly running past green fields, but only until the night turns dark. Bright stars sparkle clearly above us now. 14 | # @arg target Eager dogs jump over quick, lazy foxes behind brown wooden fences around dark, old houses. Happy children laugh as they run through golden wheat fields under blue, sunny skies. 15 | # Use '-' for standard input. 16 | # @cmd Eager dogs jump quickly over lazy foxes, creating wonderful chaos amid peaceful fields, but few noticed their swift escape beyond tall fences. Swift breezes sway gently through green. 17 | # 18 | # Extra lines after the comment tag accepts description, which don't start with an `@`, 19 | # are treated as the long description. A line which is not a comment ends the block. 20 | cmd() { :; } 21 | 22 | eval "$(TERM_WIDTH=${TERM_WIDTH:-`tput cols`} argc --argc-eval "$0" "$@")" -------------------------------------------------------------------------------- /examples/nested-commands.sh: -------------------------------------------------------------------------------- 1 | # @describe How to use nested subcommands 2 | # 3 | # Mock docker cli 4 | 5 | # @cmd 6 | builder() { :; } 7 | # @cmd 8 | builder::ls() { :; } 9 | # @cmd 10 | builder::prune() { :; } 11 | # @cmd 12 | builder::rm() { :; } 13 | # @cmd 14 | builder::imagetools() { :; } 15 | # @cmd 16 | builder::imagetools::create() { :; } 17 | # @cmd 18 | builder::imagetools::inspect() { :; } 19 | 20 | eval "$(argc --argc-eval "$0" "$@")" -------------------------------------------------------------------------------- /examples/parallel.sh: -------------------------------------------------------------------------------- 1 | #/usr/bin/env bash 2 | set -e 3 | 4 | # @describe How to use `--argc-parallel` 5 | # 6 | # Compared with GNU parallel, the biggest advantage of argc-parallel is that it preserves `argc_*` variables. 7 | 8 | # @cmd 9 | cmd1() { 10 | sleep 3 11 | echo cmd1 "$@" 12 | echo argc_oa: $argc_oa 13 | echo cmd1 stderr >&2 14 | } 15 | 16 | # @cmd 17 | cmd2() { 18 | sleep 3 19 | echo cmd2 "$@" 20 | echo argc_oa: $argc_oa 21 | echo cmd2 stderr >&2 22 | } 23 | 24 | # @cmd 25 | # @option --oa 26 | foo() { 27 | argc --argc-parallel "$0" cmd1 abc ::: func ::: cmd2 28 | } 29 | 30 | # @cmd 31 | # @option --oa 32 | bar() { 33 | cmd1 abc 34 | func 35 | cmd2 36 | } 37 | 38 | func() { 39 | echo func 40 | } 41 | 42 | eval "$(argc --argc-eval "$0" "$@")" -------------------------------------------------------------------------------- /examples/require-tools.sh: -------------------------------------------------------------------------------- 1 | # @describe how to use `@meta require-tools` 2 | 3 | # @meta require-tools awk,sed 4 | 5 | # @cmd 6 | # @meta require-tools git 7 | require-git() { 8 | :; 9 | } 10 | 11 | # @cmd 12 | # @meta require-tools not-found 13 | require-not-found() { 14 | :; 15 | } 16 | 17 | eval "$(argc --argc-eval "$0" "$@")" 18 | -------------------------------------------------------------------------------- /examples/strict.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | 5 | 6 | # @flag --fa 7 | # @option --oa 8 | # @option --of*, multi-occurs + comma-separated list 9 | # @option --oda=a default 10 | # @option --oca[a|b] choice 11 | # @option --ofa[`_choice_fn`] choice from fn 12 | # @option --oxa~ capture all remaining args 13 | 14 | main() { 15 | ( set -o posix ; set ) | grep ^argc_ 16 | echo "${argc__fn:-}" "$@" 17 | } 18 | 19 | _choice_fn() { 20 | echo abc 21 | echo def 22 | echo ghi 23 | } 24 | 25 | eval "$(argc --argc-eval "$0" "$@")" -------------------------------------------------------------------------------- /examples/symbol.sh: -------------------------------------------------------------------------------- 1 | # @describe How to use `@meta symbol` 2 | # 3 | # Mock cargo cli 4 | # @meta symbol +toolchain[`_choice_toolchain`] 5 | 6 | # @cmd Compile the current package 7 | # @alias b 8 | build () { 9 | :; 10 | } 11 | 12 | # @cmd Analyze the current package and report errors, but don't build object files 13 | # @alias c 14 | check() { 15 | :; 16 | } 17 | 18 | _choice_toolchain() { 19 | cat <<-'EOF' 20 | stable 21 | beta 22 | nightly 23 | EOF 24 | } 25 | 26 | eval "$(argc --argc-eval "$0" "$@")" -------------------------------------------------------------------------------- /src/bin/argc/completion.sh: -------------------------------------------------------------------------------- 1 | # @option --argc-eval~ Use `eval "$(argc --argc-eval "$0" "$@")"` 2 | # @option --argc-create~ Create a boilerplate argcfile 3 | # @option --argc-run~ Run an argc-based script 4 | # @option --argc-build Generate bashscript without argc dependency 5 | # @option --argc-mangen Generate man pages 6 | # @option --argc-completions Generate shell completion scripts 7 | # @option --argc-compgen Generate completion candidates 8 | # @option --argc-export Export command line definitions as json 9 | # @option --argc-parallel~ Run functions in parallel 10 | # @flag --argc-script-path Print current argcfile path 11 | # @flag --argc-shell-path Print current shell path 12 | # @flag --argc-help Print help information 13 | # @flag --argc-version Print version information 14 | 15 | eval "$(argc --argc-eval "$0" "$@")" -------------------------------------------------------------------------------- /src/bin/argc/parallel.rs: -------------------------------------------------------------------------------- 1 | use anyhow::Result; 2 | use argc::{NativeRuntime, Runtime}; 3 | use std::collections::HashMap; 4 | use std::process::{self, Command}; 5 | use std::sync::mpsc::channel; 6 | use threadpool::ThreadPool; 7 | 8 | pub const PARALLEL_SYMBOL: &str = "___parallel___"; 9 | 10 | pub fn parallel( 11 | runtime: NativeRuntime, 12 | shell: &str, 13 | script_file: &str, 14 | args: &[String], 15 | ) -> Result<()> { 16 | let jobs = to_jobs(args); 17 | let jobs_len = jobs.len(); 18 | let pool = ThreadPool::new(num_cpus::get()); 19 | let (tx, rx) = channel(); 20 | let path_env = runtime.path_env_with_current_exe(); 21 | let mut shell_extra_args = runtime.shell_args(shell); 22 | shell_extra_args.push(script_file.to_string()); 23 | shell_extra_args.push(PARALLEL_SYMBOL.to_string()); 24 | for (i, job_args) in jobs.into_iter().enumerate() { 25 | let tx = tx.clone(); 26 | let shell = shell.to_string(); 27 | let path_env = path_env.clone(); 28 | let shell_extra_args = shell_extra_args.clone(); 29 | pool.execute(move || { 30 | Command::new(shell) 31 | .args(shell_extra_args) 32 | .args(job_args) 33 | .env("ARGC_PARALLEL", "1") 34 | .env("PATH", path_env) 35 | .output() 36 | .ok() 37 | .and_then(|output| tx.send((i, output)).ok()); 38 | }); 39 | } 40 | pool.join(); 41 | drop(tx); 42 | let mut job_outputs = HashMap::new(); 43 | let mut exit = 0; 44 | for (i, job_output) in rx { 45 | if !job_output.status.success() { 46 | exit = 1; 47 | } 48 | job_outputs.insert( 49 | i, 50 | ( 51 | String::from_utf8_lossy(&job_output.stdout).to_string(), 52 | String::from_utf8_lossy(&job_output.stderr).to_string(), 53 | ), 54 | ); 55 | } 56 | for i in 0..jobs_len { 57 | if let Some((stdout, stderr)) = job_outputs.get(&i) { 58 | if !stdout.is_empty() { 59 | print!("{stdout}") 60 | } 61 | if !stderr.is_empty() { 62 | eprint!("{stderr}") 63 | } 64 | } 65 | } 66 | process::exit(exit) 67 | } 68 | 69 | fn to_jobs(args: &[String]) -> Vec> { 70 | let mut jobs = Vec::new(); 71 | let mut current = vec![]; 72 | for arg in args { 73 | if arg == ":::" { 74 | if current.is_empty() { 75 | continue; 76 | } 77 | jobs.push(std::mem::take(&mut current).to_vec()) 78 | } else { 79 | current.push(arg.to_string()) 80 | } 81 | } 82 | if !current.is_empty() { 83 | jobs.push(std::mem::take(&mut current).to_vec()) 84 | } 85 | jobs 86 | } 87 | -------------------------------------------------------------------------------- /src/command/names_checker.rs: -------------------------------------------------------------------------------- 1 | use crate::param::{EnvParam, FlagOptionParam, Param, PositionalParam}; 2 | use crate::parser::Position; 3 | 4 | use anyhow::{bail, Result}; 5 | use std::collections::HashMap; 6 | 7 | #[derive(Debug, Default, Clone)] 8 | pub(crate) struct NamesChecker { 9 | pub(crate) flag_options: HashMap, 10 | pub(crate) envs: HashMap, 11 | pub(crate) positionals: HashMap, 12 | } 13 | 14 | impl NamesChecker { 15 | pub(crate) fn check_flag_option( 16 | &mut self, 17 | param: &FlagOptionParam, 18 | pos: Position, 19 | ) -> Result<()> { 20 | let tag_name = param.tag_name(); 21 | let names = param.list_names(); 22 | for name in names.iter() { 23 | if let Some((exist_pos, _)) = self.flag_options.get(name) { 24 | bail!("{}", Self::conflict_error(tag_name, pos, name, *exist_pos)); 25 | } 26 | self.flag_options 27 | .insert(name.to_string(), (pos, format!("{} {}", tag_name, name))); 28 | } 29 | Ok(()) 30 | } 31 | 32 | pub(crate) fn check_env(&mut self, param: &EnvParam, pos: Position) -> Result<()> { 33 | let name = param.id(); 34 | if let Some(exist_pos) = self.envs.get(name) { 35 | bail!( 36 | "{}", 37 | Self::conflict_error(param.tag_name(), pos, name, *exist_pos) 38 | ); 39 | } 40 | self.envs.insert(name.to_string(), pos); 41 | Ok(()) 42 | } 43 | 44 | pub(crate) fn check_positional( 45 | &mut self, 46 | param: &PositionalParam, 47 | pos: Position, 48 | ) -> Result<()> { 49 | let name = param.id(); 50 | if let Some(exist_pos) = self.positionals.get(name) { 51 | bail!( 52 | "{}", 53 | Self::conflict_error(param.tag_name(), pos, name, *exist_pos) 54 | ); 55 | } 56 | self.positionals.insert(name.to_string(), pos); 57 | Ok(()) 58 | } 59 | 60 | fn conflict_error( 61 | tag_name: &str, 62 | pos: Position, 63 | name_desc: &str, 64 | exist_pos: Position, 65 | ) -> String { 66 | format!( 67 | "{}(line {}) has '{}' already exists at line {}", 68 | tag_name, pos, name_desc, exist_pos, 69 | ) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/command/share_data.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | parser::{EventScope, Position}, 3 | utils::ROOT_NAME, 4 | }; 5 | 6 | use anyhow::{bail, Result}; 7 | use std::collections::HashMap; 8 | 9 | #[derive(Default, Debug)] 10 | pub(crate) struct ShareData { 11 | pub(crate) scope: EventScope, 12 | pub(crate) name: Option, 13 | pub(crate) fns: HashMap, 14 | pub(crate) cmd_fns: HashMap, 15 | pub(crate) cmd_pos: usize, 16 | pub(crate) default_fns: Vec<(String, Position)>, 17 | pub(crate) choice_fns: Vec<(String, Position)>, 18 | } 19 | 20 | impl ShareData { 21 | pub(crate) fn name(&self) -> String { 22 | match &self.name { 23 | Some(v) => v.clone(), 24 | None => ROOT_NAME.to_string(), 25 | } 26 | } 27 | 28 | pub(crate) fn add_param_fn( 29 | &mut self, 30 | position: usize, 31 | default_fn: Option<&String>, 32 | choice_fn: Option<(&String, &bool)>, 33 | ) { 34 | if let Some(f) = default_fn { 35 | self.default_fns.push((f.to_string(), position)); 36 | } 37 | if let Some((f, _)) = choice_fn { 38 | self.choice_fns.push((f.to_string(), position)); 39 | } 40 | } 41 | 42 | pub(crate) fn check_param_fn(&self) -> Result<()> { 43 | for (name, pos) in self.default_fns.iter() { 44 | if !self.fns.contains_key(name) { 45 | bail!("{}(line {}) is missing", name, pos,) 46 | } 47 | } 48 | for (name, pos) in self.choice_fns.iter() { 49 | if !self.fns.contains_key(name) { 50 | bail!("{}(line {}) is missing", name, pos,) 51 | } 52 | } 53 | Ok(()) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/completions/argc.bash: -------------------------------------------------------------------------------- 1 | _argc_completer() { 2 | declare -a _argc_completer_words 3 | _argc_completer_parse_line 4 | 5 | export COMP_WORDBREAKS 6 | while IFS=$'\n' read -r line; do 7 | COMPREPLY+=( "$line" ) 8 | done < <(argc --argc-compgen bash "" "${_argc_completer_words[@]}" 2>/dev/null) 9 | } 10 | 11 | _argc_completer_parse_line() { 12 | local line len i char prev_char word unbalance 13 | line="${COMP_LINE:0:$COMP_POINT}" 14 | len="${#line}" 15 | 16 | for ((i=0; i] { 2 | argc --argc-compgen nushell "" ...$args 3 | | split row "\n" 4 | | each { |line| $line | split column "\t" value description } 5 | | flatten 6 | } 7 | 8 | let external_completer = {|spans| 9 | _argc_completer $spans 10 | } 11 | 12 | $env.config.completions.external.enable = true 13 | $env.config.completions.external.completer = $external_completer 14 | -------------------------------------------------------------------------------- /src/completions/argc.ps1: -------------------------------------------------------------------------------- 1 | using namespace System.Management.Automation 2 | 3 | $_argc_completer = { 4 | param($wordToComplete, $commandAst, $cursorPosition) 5 | $words = @($commandAst.CommandElements | Where { $_.Extent.StartOffset -lt $cursorPosition } | ForEach-Object { 6 | $word = $_.ToString() 7 | if ($word.Length -gt 2) { 8 | if (($word.StartsWith('"') -and $word.EndsWith('"')) -or ($word.StartsWith("'") -and $word.EndsWith("'"))) { 9 | $word = $word.Substring(1, $word.Length - 2) 10 | } 11 | } 12 | return $word 13 | }) 14 | $emptyS = '' 15 | if ($PSVersionTable.PSVersion.Major -eq 5) { 16 | $emptyS = '""' 17 | } 18 | $lastElemIndex = -1 19 | if ($words.Count -lt $commandAst.CommandElements.Count) { 20 | $lastElemIndex = $words.Count - 1 21 | } 22 | if ($commandAst.CommandElements[$lastElemIndex].Extent.EndOffset -lt $cursorPosition) { 23 | $words += $emptyS 24 | } 25 | @((argc --argc-compgen powershell $emptyS $words) -split "`n") | ForEach-Object { 26 | $parts = ($_ -split "`t") 27 | if ($parts[1] -eq "1") { 28 | $value = $parts[0] + " " 29 | } else { 30 | $value = $parts[0] 31 | } 32 | if ($parts[3] -eq "") { 33 | $description = "$([char]0x1b)[" + $parts[4] + "m" + $parts[2] + "$([char]0x1b)[0m" 34 | } else { 35 | $description = "$([char]0x1b)[" + $parts[4] + "m" + $parts[2] + "$([char]0x1b)[38;5;244m (" + $parts[3] + ")$([char]0x1b)[0m" 36 | } 37 | [CompletionResult]::new($value, $description, [CompletionResultType]::ParameterValue, " ") 38 | } 39 | } 40 | 41 | @(__COMMANDS__) | 42 | ForEach-Object { 43 | Register-ArgumentCompleter -Native -ScriptBlock $_argc_completer -CommandName $_ 44 | } 45 | -------------------------------------------------------------------------------- /src/completions/argc.xsh: -------------------------------------------------------------------------------- 1 | from subprocess import Popen, PIPE 2 | from xonsh.completers.tools import * 3 | from xonsh.completers._aliases import _add_one_completer 4 | 5 | @contextual_command_completer 6 | def _argc_completer(context): 7 | if len(context.args) == 0: 8 | return 9 | args = [v.value for v in context.args[0:context.arg_index]] 10 | args.append(context.raw_prefix) 11 | 12 | if args[0] not in __xonsh__.env['ARGC_XONSH_SCRIPTS']: 13 | return 14 | 15 | output, _ = Popen(['argc', '--argc-compgen', 'xonsh', '', *args], stdout=PIPE, stderr=PIPE).communicate() 16 | candidates = output.decode().split('\n') 17 | candidates.pop() 18 | result = set() 19 | skip = 0 20 | if len(candidates) == 0: 21 | result.add(RichCompletion("")) 22 | return result 23 | 24 | for v in candidates: 25 | parts = v.split('\t') 26 | value = parts[0] 27 | if parts[1] == "1": 28 | value = value + " " 29 | result.add(RichCompletion(value, display=parts[2], description=parts[3], prefix_len=len(args[-1]), append_closing_quote=False)) 30 | 31 | return result 32 | 33 | if 'ARGC_XONSH_SCRIPTS' not in __xonsh__.env: 34 | __xonsh__.env['ARGC_XONSH_SCRIPTS'] = [] 35 | 36 | if 'argc' not in __xonsh__.completers: 37 | _add_one_completer('argc', _argc_completer, 'start') 38 | -------------------------------------------------------------------------------- /src/completions/argc.zsh: -------------------------------------------------------------------------------- 1 | _argc_completer() { 2 | local new_words 3 | _argc_completer_reassemble_words 4 | 5 | local candidates=() values=() displays=() colors display_value 6 | while IFS=$'\n' read -r line; do 7 | if [[ "$line" == "" ]]; then line=$'\0'; fi 8 | candidates+=( "$line" ) 9 | done < <(argc --argc-compgen zsh $'\0' $new_words 2>/dev/null) 10 | for candidate in ${candidates[@]}; do 11 | IFS=$'\t' read -r value display color_key color <<< "$candidate" 12 | colors="$colors:=(#b)($color_key)( * -- *)=0=$color=2;37:=(#b)($color_key)()=0=$color=2;37" 13 | values+=( "${value}" ) 14 | displays+=( "$display" ) 15 | done 16 | zstyle ":completion:${curcontext}:*" list-colors "${colors:1}:=(#b)(-- *)=0=2;37:=(#b)(--[A-Za-z0-9_-]#)( * -- *)=0==2;37" 17 | _describe "" displays values -Q -S '' -o nosort 18 | } 19 | 20 | _argc_completer_reassemble_words() { 21 | local i cword 22 | new_words=() 23 | for ((i=1; i<=$CURRENT; i++)); do 24 | cword="$words[$i]" 25 | if [[ "$cword" == "" ]]; then 26 | new_words+=( $'\0' ) 27 | else 28 | if [[ "$cword" == *"\\"* ]]; then 29 | local j char next_char cword_len word 30 | cword_len="${#cword}" 31 | for ((j=0; j<$cword_len; j++)); do 32 | char="${cword:$j:1}" 33 | if [[ "$char" == "\\" ]]; then 34 | next_char="${cword:$((j+1)):1}" 35 | if [[ "$next_char" == "\\" ]]; then 36 | word="$word$char" 37 | j=$((j+1)) 38 | fi 39 | else 40 | word="$word$char" 41 | fi 42 | done 43 | cword="$word" 44 | fi 45 | new_words+=( "$cword" ) 46 | fi 47 | done 48 | } 49 | 50 | compdef _argc_completer \ 51 | __COMMANDS__ 52 | -------------------------------------------------------------------------------- /src/completions/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::Shell; 2 | 3 | const BASH_SCRIPT: &str = include_str!("argc.bash"); 4 | const ELVISH_SCRIPT: &str = include_str!("argc.elv"); 5 | const FISH_SCRIPT: &str = include_str!("argc.fish"); 6 | const NUSHELL_SCRIPT: &str = include_str!("argc.nu"); 7 | const POWERSHELL_SCRIPT: &str = include_str!("argc.ps1"); 8 | const XONSH_SCRIPT: &str = include_str!("argc.xsh"); 9 | const ZSH_SCRIPT: &str = include_str!("argc.zsh"); 10 | 11 | pub fn generate_completions(shell: Shell, commands: &[String]) -> String { 12 | match shell { 13 | Shell::Bash => { 14 | let commands = commands.join(" "); 15 | BASH_SCRIPT.replace("__COMMANDS__", &commands) 16 | } 17 | Shell::Elvish => { 18 | let commands = commands 19 | .iter() 20 | .map(|v| format!("\"{v}\"")) 21 | .collect::>() 22 | .join(" "); 23 | ELVISH_SCRIPT.replace("__COMMANDS__", &commands) 24 | } 25 | Shell::Fish => { 26 | let commands = commands.join(" "); 27 | FISH_SCRIPT.replace("__COMMANDS__", &commands) 28 | } 29 | Shell::Generic => String::new(), 30 | Shell::Nushell => NUSHELL_SCRIPT.to_string(), 31 | Shell::Powershell => { 32 | let commands = commands 33 | .iter() 34 | .map(|v| format!("\"{v}\"")) 35 | .collect::>() 36 | .join(","); 37 | POWERSHELL_SCRIPT.replace("__COMMANDS__", &commands) 38 | } 39 | Shell::Xonsh => { 40 | format!("{XONSH_SCRIPT}\n__xonsh__.env['ARGC_XONSH_SCRIPTS'].extend({commands:?})") 41 | } 42 | Shell::Zsh => { 43 | let commands = commands.join(" "); 44 | ZSH_SCRIPT.replace("__COMMANDS__", &commands) 45 | } 46 | Shell::Tcsh => { 47 | commands 48 | .iter() 49 | .map(|v| format!(r#"complete {v} 'p@*@`echo "$COMMAND_LINE'"''"'" | xargs argc --argc-compgen tcsh ""`@@';{}"#, "\n")) 50 | .collect::>().join("") 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | mod argc_value; 2 | #[cfg(feature = "build")] 3 | mod build; 4 | mod command; 5 | #[cfg(feature = "compgen")] 6 | mod compgen; 7 | #[cfg(feature = "completions")] 8 | mod completions; 9 | #[cfg(feature = "mangen")] 10 | mod mangen; 11 | #[cfg(any(feature = "eval", feature = "compgen"))] 12 | mod matcher; 13 | mod param; 14 | mod parser; 15 | mod runtime; 16 | #[cfg(any(feature = "compgen", feature = "completions"))] 17 | mod shell; 18 | pub mod utils; 19 | 20 | use anyhow::Result; 21 | pub use argc_value::ArgcValue; 22 | #[cfg(feature = "build")] 23 | pub use build::build; 24 | #[cfg(feature = "export")] 25 | pub use command::CommandValue; 26 | #[cfg(feature = "compgen")] 27 | pub use compgen::{compgen, compgen_kind, CompKind, COMPGEN_KIND_SYMBOL}; 28 | #[cfg(feature = "completions")] 29 | pub use completions::generate_completions; 30 | #[cfg(feature = "mangen")] 31 | pub use mangen::mangen; 32 | pub use param::{ChoiceValue, DefaultValue}; 33 | #[cfg(feature = "export")] 34 | pub use param::{EnvValue, FlagOptionValue, PositionalValue}; 35 | #[cfg(feature = "native-runtime")] 36 | pub use runtime::navite::NativeRuntime; 37 | #[cfg(any(feature = "eval", feature = "compgen"))] 38 | pub use runtime::Runtime; 39 | #[cfg(any(feature = "compgen", feature = "completions"))] 40 | pub use shell::Shell; 41 | 42 | #[cfg(feature = "eval")] 43 | pub fn eval( 44 | runtime: T, 45 | script_content: &str, 46 | args: &[String], 47 | script_path: Option<&str>, 48 | wrap_width: Option, 49 | ) -> Result> { 50 | let mut cmd = command::Command::new(script_content, &args[0])?; 51 | cmd.eval(runtime, args, script_path, wrap_width) 52 | } 53 | 54 | #[cfg(feature = "export")] 55 | pub fn export(source: &str, root_name: &str) -> Result { 56 | let cmd = command::Command::new(source, root_name)?; 57 | Ok(cmd.export()) 58 | } 59 | -------------------------------------------------------------------------------- /tests/bind_env.rs: -------------------------------------------------------------------------------- 1 | use rstest::rstest; 2 | 3 | #[rstest] 4 | fn bind_env_flags_help() { 5 | snapshot_bind_env!(args: ["flags", "-h"], envs: {}); 6 | } 7 | 8 | #[rstest] 9 | fn bind_env_flags() { 10 | snapshot_bind_env!(args: ["flags"], envs: { 11 | "FA1": "true", 12 | "FB2": "false", 13 | "FA": "true", 14 | "FC": "true", 15 | "FD": "true", 16 | }); 17 | } 18 | 19 | #[rstest] 20 | fn bind_env_flags_bool_err() { 21 | snapshot_bind_env!(args: ["flags"], envs: { 22 | "FA1": "v1", 23 | }); 24 | } 25 | 26 | #[rstest] 27 | fn bind_env_flags_bool_ok() { 28 | snapshot_bind_env!(args: ["flags", "--fa1"], envs: { 29 | "FA1": "v1", 30 | }); 31 | } 32 | 33 | #[rstest] 34 | fn bind_env_options_help() { 35 | snapshot_bind_env!(args: ["options", "-h"], envs: {}); 36 | } 37 | 38 | #[rstest] 39 | fn bind_env_options() { 40 | snapshot_bind_env!(args: ["options"], envs: { 41 | "OA1": "oa1", 42 | "OA2": "oa2", 43 | "OA": "oa3", 44 | "OB": "ob", 45 | "OC": "v1,v2", 46 | "ODA": "oda", 47 | "ODD": "odd", 48 | "OCA": "a", 49 | "OCC": "a", 50 | "OFA": "abc", 51 | "OFD": "abc,def", 52 | "OXA": "oxa", 53 | }); 54 | } 55 | 56 | #[rstest] 57 | fn bind_env_options_choice_err() { 58 | snapshot_bind_env!(args: ["options"], envs: { 59 | "OB": "ob", 60 | "OCA": "oca", 61 | }); 62 | } 63 | 64 | #[rstest] 65 | fn bind_env_options_choice_ok() { 66 | snapshot_bind_env!(args: ["options", "--oca", "a"], envs: { 67 | "OB": "ob", 68 | "OCA": "oca", 69 | }); 70 | } 71 | 72 | #[rstest] 73 | fn bind_env_options_choice_fn_err() { 74 | snapshot_bind_env!(args: ["options"], envs: { 75 | "OB": "ob", 76 | "OFA": "ofa", 77 | }); 78 | } 79 | 80 | #[rstest] 81 | fn bind_env_options_required_err() { 82 | snapshot_bind_env!(args: ["options"], envs: {}); 83 | } 84 | 85 | #[rstest] 86 | fn bind_env_arg1() { 87 | snapshot_bind_env!(args: ["cmd_arg1"], envs: { 88 | "VAL": "v1", 89 | }); 90 | } 91 | 92 | #[rstest] 93 | fn bind_env_arg2() { 94 | snapshot_bind_env!(args: ["cmd_arg2"], envs: { 95 | "VA": "v1", 96 | }); 97 | } 98 | 99 | #[rstest] 100 | fn bind_env_arg_choice_err() { 101 | snapshot_bind_env!(args: ["cmd_arg_with_choice"], envs: { 102 | "VAL": "v1", 103 | }); 104 | } 105 | 106 | #[rstest] 107 | fn bind_env_arg_choice_fn_err() { 108 | snapshot_bind_env!(args: ["cmd_arg_with_choice_fn"], envs: { 109 | "VAL": "v1", 110 | }); 111 | } 112 | 113 | #[rstest] 114 | fn bind_env_multi_arg_with_choice_fn_and_comma_sep() { 115 | snapshot_bind_env!(args: ["cmd_multi_arg_with_choice_fn_and_comma_sep"], envs: { 116 | "VAL": "abc,def", 117 | }); 118 | } 119 | 120 | #[rstest] 121 | fn bind_env_cmd_three_required_args() { 122 | snapshot_bind_env!(args: ["cmd_three_required_args"], envs: { 123 | "VAL1": "v1", 124 | "VAL2": "v2", 125 | "VAL3": "v3", 126 | }); 127 | } 128 | 129 | #[rstest] 130 | fn bind_env_cmd_three_required_args_err() { 131 | snapshot_bind_env!(args: ["cmd_three_required_args"], envs: { 132 | "VAL1": "v1", 133 | "VAL2": "v2", 134 | }); 135 | } 136 | 137 | #[rstest] 138 | fn bind_env_with_notation() { 139 | snapshot_bind_env!(args: ["cmd_for_notation"], envs: { 140 | "OA": "oa", 141 | "VAL": "v1", 142 | }); 143 | } 144 | #[rstest] 145 | fn bind_env_with_notation_help() { 146 | snapshot_bind_env!(args: ["cmd_for_notation", "-h"], envs: {}); 147 | } 148 | -------------------------------------------------------------------------------- /tests/env.rs: -------------------------------------------------------------------------------- 1 | use rstest::rstest; 2 | 3 | #[rstest] 4 | fn env_help() { 5 | snapshot_meta_env!(["-h"], {}); 6 | } 7 | 8 | #[rstest] 9 | fn env_help_subcmd() { 10 | snapshot_meta_env!(["run", "-h"], {}); 11 | } 12 | 13 | #[rstest] 14 | fn env_missing() { 15 | snapshot_meta_env!([], {}); 16 | } 17 | 18 | #[rstest] 19 | fn env_choice() { 20 | snapshot_meta_env!([], {"TEST_EB": "1", "TEST_ECA": "val"}); 21 | } 22 | 23 | #[rstest] 24 | fn env_choice_fn() { 25 | snapshot_meta_env!([], {"TEST_EB": "1", "TEST_EFA": "val"}); 26 | } 27 | 28 | #[rstest] 29 | fn env_run() { 30 | snapshot_meta_env!([], {"TEST_EB": "1"}); 31 | } 32 | -------------------------------------------------------------------------------- /tests/hook_fn.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[test] 4 | fn hook_without_subcmd() { 5 | let script = r###" 6 | _argc_before() { echo before; } 7 | _argc_after() { echo after; } 8 | "###; 9 | snapshot!(script, &["prog"]); 10 | } 11 | 12 | #[test] 13 | fn hook_with_main() { 14 | let script = r###" 15 | _argc_before() { echo before; } 16 | _argc_after() { echo after; } 17 | main() { :; } 18 | "###; 19 | snapshot!(script, &["prog"]); 20 | } 21 | 22 | #[test] 23 | fn hook_with_subcmd() { 24 | let script = r###" 25 | _argc_before() { echo before; } 26 | _argc_after() { echo after; } 27 | # @cmd 28 | cmd() { :; } 29 | "###; 30 | snapshot!(script, &["prog", "cmd"]); 31 | } 32 | 33 | #[test] 34 | fn hook_only_before() { 35 | let script = r###" 36 | _argc_before() { echo before; } 37 | main() { :; } 38 | "###; 39 | snapshot!(script, &["prog"]); 40 | } 41 | 42 | #[test] 43 | fn hook_only_after() { 44 | let script = r###" 45 | _argc_after() { echo after; } 46 | main() { :; } 47 | "###; 48 | snapshot!(script, &["prog"]); 49 | } 50 | 51 | #[test] 52 | fn hook_param_fn() { 53 | let script = r###" 54 | _argc_before() { echo before; } 55 | _argc_after() { echo after; } 56 | _choice_fn() { :; } 57 | "###; 58 | snapshot!(script, &["prog", "___internal___", "_choice_fn"]); 59 | } 60 | -------------------------------------------------------------------------------- /tests/main_fn.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[test] 4 | fn with_main() { 5 | let script = r###" 6 | # @arg val 7 | main() { :; } 8 | "###; 9 | snapshot!(script, &["prog"]); 10 | } 11 | 12 | #[test] 13 | fn with_main2() { 14 | let script = r###" 15 | # @option --foo 16 | # @arg val 17 | main() { :; } 18 | "###; 19 | snapshot_multi!(script, [vec!["prog"], vec!["prog", "abc", "--foo", "123"]]); 20 | } 21 | 22 | #[test] 23 | fn no_main() { 24 | let script = r###" 25 | # @arg val 26 | "###; 27 | snapshot!(script, &["prog"]); 28 | } 29 | 30 | #[test] 31 | fn subcmd_main() { 32 | let script = r###" 33 | # @cmd 34 | cmd() { :; } 35 | main() { :; } 36 | "###; 37 | snapshot!(script, &["prog"]); 38 | } 39 | 40 | #[test] 41 | fn subcmd_no_main() { 42 | let script = r###" 43 | # @cmd 44 | cmd() { :; } 45 | "###; 46 | snapshot!(script, &["prog"]); 47 | } 48 | 49 | #[test] 50 | fn nested_subcmd_main() { 51 | let script = r###" 52 | # @cmd 53 | cmd() { :; } 54 | cmd::main() { :; } 55 | # @cmd 56 | cmd::foo() { :; } 57 | "###; 58 | snapshot!(script, &["prog", "cmd"]); 59 | } 60 | 61 | #[test] 62 | fn nested_subcmd_main2() { 63 | let script = r###" 64 | # @cmd 65 | # @option --foo 66 | # @arg val 67 | cmd() { :; } 68 | cmd::main() { :; } 69 | # @cmd 70 | cmd::foo() { :; } 71 | "###; 72 | snapshot_multi!( 73 | script, 74 | [ 75 | vec!["prog", "cmd"], 76 | vec!["prog", "cmd", "abc", "--foo", "123"] 77 | ] 78 | ); 79 | } 80 | 81 | #[test] 82 | fn nested_subcmd_no_main() { 83 | let script = r###" 84 | # @cmd 85 | cmd() { :; } 86 | # @cmd 87 | cmd::foo() { :; } 88 | "###; 89 | snapshot!(script, &["prog", "cmd"]); 90 | } 91 | 92 | #[test] 93 | fn global_with_arg() { 94 | let script = r###" 95 | # @arg val 96 | # @cmd 97 | cmd() { :; } 98 | main() { :; } 99 | "###; 100 | snapshot!(script, &["prog", "abc"]); 101 | } 102 | 103 | #[test] 104 | fn global_without_arg() { 105 | let script = r###" 106 | # @cmd 107 | cmd() { :; } 108 | main() { :; } 109 | "###; 110 | snapshot!(script, &["prog", "abc"]); 111 | } 112 | -------------------------------------------------------------------------------- /tests/meta.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[test] 4 | fn dotenv() { 5 | let script = r###" 6 | # @meta dotenv 7 | "###; 8 | snapshot!(script, &["prog"]); 9 | } 10 | 11 | #[test] 12 | fn dotenv_custom_path() { 13 | let script = r###" 14 | # @meta dotenv .env.local 15 | "###; 16 | snapshot!(script, &["prog"]); 17 | } 18 | -------------------------------------------------------------------------------- /tests/misc.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[test] 4 | fn escape() { 5 | snapshot!( 6 | SCRIPT_ARGS, 7 | &["prog", "cmd", "$foo", "`pwd`", "$(pwd)", "'", "\\1", "", "\n", "世界", " "] 8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /tests/multiline.rs: -------------------------------------------------------------------------------- 1 | use super::SCRIPT_MULTILINE; 2 | 3 | #[test] 4 | fn wrap() { 5 | snapshot!(SCRIPT_MULTILINE, &["prog", "-h"], None, Some(80)); 6 | } 7 | 8 | #[test] 9 | fn wrap2() { 10 | snapshot!(SCRIPT_MULTILINE, &["prog", "foo", "-h"], None, Some(80)); 11 | } 12 | 13 | #[test] 14 | fn nowrap() { 15 | snapshot!(SCRIPT_MULTILINE, &["prog", "-h"], None, None); 16 | } 17 | -------------------------------------------------------------------------------- /tests/param_fn.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[test] 4 | fn case1() { 5 | snapshot_multi!( 6 | SCRIPT_OPTIONS, 7 | [ 8 | vec!["prog", "___internal___", "_choice_fn"], 9 | vec![ 10 | "prog", 11 | "___internal___", 12 | "_choice_fn", 13 | "prog", 14 | "test1", 15 | "--cc", 16 | "" 17 | ], 18 | vec![ 19 | "prog", 20 | "___internal___", 21 | "_choice_fn", 22 | "prog", 23 | "test1", 24 | "-a", 25 | "--oa", 26 | "oa", 27 | "--cc", 28 | "" 29 | ], 30 | ] 31 | ); 32 | } 33 | 34 | #[test] 35 | fn case2() { 36 | snapshot_multi!( 37 | SCRIPT_ARGS, 38 | [ 39 | vec!["prog", "___internal___", "_choice_fn"], 40 | vec![ 41 | "prog", 42 | "___internal___", 43 | "_choice_fn", 44 | "prog", 45 | "cmd_multi_arg_with_choice_fn", 46 | "" 47 | ], 48 | vec![ 49 | "prog", 50 | "___internal___", 51 | "_choice_fn", 52 | "prog", 53 | "cmd_multi_arg_with_choice_fn", 54 | "v1" 55 | ], 56 | vec![ 57 | "prog", 58 | "___internal___", 59 | "_choice_fn", 60 | "prog", 61 | "cmd_multi_arg_with_choice_fn", 62 | "v1", 63 | "" 64 | ], 65 | vec![ 66 | "prog", 67 | "___internal___", 68 | "_choice_fn", 69 | "prog", 70 | "cmd_multi_arg_with_choice_fn", 71 | "v1", 72 | "v2" 73 | ], 74 | vec![ 75 | "prog", 76 | "___internal___", 77 | "_choice_fn", 78 | "prog", 79 | "cmd_multi_arg_with_choice_fn", 80 | "v1", 81 | "v2", 82 | "" 83 | ], 84 | ] 85 | ); 86 | } 87 | 88 | #[test] 89 | fn case3() { 90 | let script = r###" 91 | # @arg v1![`_choice_fn`] 92 | # @arg v2![`_choice_fn`] 93 | _choice_fn() { 94 | echo a 95 | echo b 96 | } 97 | "###; 98 | snapshot_multi!( 99 | script, 100 | [ 101 | vec!["prog", "___internal___", "_choice_fn"], 102 | vec!["prog", "___internal___", "_choice_fn", "prog", ""], 103 | vec!["prog", "___internal___", "_choice_fn", "prog", "v1"], 104 | vec!["prog", "___internal___", "_choice_fn", "prog", "v1", ""], 105 | vec!["prog", "___internal___", "_choice_fn", "prog", "v1", "v2"], 106 | vec![ 107 | "prog", 108 | "___internal___", 109 | "_choice_fn", 110 | "prog", 111 | "v1", 112 | "v2", 113 | "" 114 | ], 115 | ] 116 | ); 117 | } 118 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_arg1.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | argc__args=([0]="bind-envs" [1]="cmd_arg1") 7 | argc__fn=cmd_arg1 8 | argc__positionals=([0]="v1") 9 | argc_val=v1 10 | cmd_arg1 v1 11 | 12 | 13 | # BUILD_OUTPUT 14 | argc__args=([0]="prog" [1]="cmd_arg1") 15 | argc__fn=cmd_arg1 16 | argc__positionals=([0]="v1") 17 | argc_val=v1 18 | cmd_arg1 v1 19 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_arg2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | argc__args=([0]="bind-envs" [1]="cmd_arg2") 7 | argc__fn=cmd_arg2 8 | argc__positionals=([0]="v1") 9 | argc_val=v1 10 | cmd_arg2 v1 11 | 12 | 13 | # BUILD_OUTPUT 14 | argc__args=([0]="prog" [1]="cmd_arg2") 15 | argc__fn=cmd_arg2 16 | argc__positionals=([0]="v1") 17 | argc_val=v1 18 | cmd_arg2 v1 19 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_arg_choice_err.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | error: invalid value `v1` for environment variable `VAL` that bound to `[VAL]` 7 | [possible values: x, y, z] 8 | 9 | 10 | # BUILD_OUTPUT 11 | error: invalid value `v1` for environment variable `VAL` that bound to `[VAL]` 12 | [possible values: x, y, z] 13 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_arg_choice_fn_err.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | error: invalid value `v1` for environment variable `VAL` that bound to `[VAL]` 7 | [possible values: abc, def, ghi] 8 | 9 | 10 | # BUILD_OUTPUT 11 | error: invalid value `v1` for environment variable `VAL` that bound to `[VAL]` 12 | [possible values: abc, def, ghi] 13 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_cmd_three_required_args.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | argc__args=([0]="bind-envs" [1]="cmd_three_required_args") 7 | argc__fn=cmd_three_required_args 8 | argc__positionals=([0]="v1" [1]="v2" [2]="v3") 9 | argc_val1=v1 10 | argc_val2=v2 11 | argc_val3=v3 12 | cmd_three_required_args v1 v2 v3 13 | 14 | 15 | # BUILD_OUTPUT 16 | argc__args=([0]="prog" [1]="cmd_three_required_args") 17 | argc__fn=cmd_three_required_args 18 | argc__positionals=([0]="v1" [1]="v2" [2]="v3") 19 | argc_val1=v1 20 | argc_val2=v2 21 | argc_val3=v3 22 | cmd_three_required_args v1 v2 v3 23 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_cmd_three_required_args_err.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | error: the following required arguments were not provided: 7 | 8 | 9 | 10 | # BUILD_OUTPUT 11 | error: the required environments `` were not provided 12 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_flags.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | argc__args=([0]="bind-envs" [1]="flags") 7 | argc__fn=flags 8 | argc__positionals=() 9 | argc_fa1=1 10 | argc_fa3=1 11 | argc_fc=1 12 | argc_fd=1 13 | flags 14 | 15 | 16 | # BUILD_OUTPUT 17 | argc__args=([0]="prog" [1]="flags") 18 | argc__fn=flags 19 | argc__positionals=() 20 | argc_fa1=1 21 | argc_fa3=1 22 | argc_fc=1 23 | argc_fd=1 24 | flags 25 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_flags_bool_err.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | error: environment variable `FA1` has invalid value for param '--fa1' 7 | 8 | 9 | # BUILD_OUTPUT 10 | error: environment variable 'FA1' has invalid value for param '--fa1' 11 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_flags_bool_ok.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | argc__args=([0]="bind-envs" [1]="flags" [2]="--fa1") 7 | argc__fn=flags 8 | argc__positionals=() 9 | argc_fa1=1 10 | flags 11 | 12 | 13 | # BUILD_OUTPUT 14 | argc__args=([0]="prog" [1]="flags" [2]="--fa1") 15 | argc__fn=flags 16 | argc__positionals=() 17 | argc_fa1=1 18 | flags 19 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_flags_help.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | How to bind env to param 7 | 8 | USAGE: bind-envs flags [OPTIONS] 9 | 10 | OPTIONS: 11 | --fa1 [env: FA1] 12 | --fa2 [env: FA2] 13 | --fa3 [env: FA] 14 | --fc... [env: FC] 15 | --fd [env: FD] 16 | -h, --help 17 | 18 | 19 | 20 | # BUILD_OUTPUT 21 | How to bind env to param 22 | 23 | USAGE: prog flags [OPTIONS] 24 | 25 | OPTIONS: 26 | --fa1 [env: FA1] 27 | --fa2 [env: FA2] 28 | --fa3 [env: FA] 29 | --fc... [env: FC] 30 | --fd [env: FD] 31 | -h, --help 32 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_flags_ok.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | USAGE: bind-envs 7 | 8 | COMMANDS: 9 | flags 10 | options 11 | cmd_arg1 12 | cmd_arg2 13 | cmd_arg_with_default 14 | cmd_arg_with_choice 15 | cmd_arg_with_choice_fn 16 | cmd_multi_arg_with_choice_fn_and_comma_sep 17 | cmd_three_required_args 18 | 19 | 20 | 21 | # BUILD_OUTPUT 22 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_multi_arg_with_choice_fn_and_comma_sep.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | argc__args=([0]="bind-envs" [1]="cmd_multi_arg_with_choice_fn_and_comma_sep") 7 | argc__fn=cmd_multi_arg_with_choice_fn_and_comma_sep 8 | argc__positionals=([0]="abc" [1]="def") 9 | argc_val=([0]="abc" [1]="def") 10 | cmd_multi_arg_with_choice_fn_and_comma_sep abc def 11 | 12 | 13 | # BUILD_OUTPUT 14 | argc__args=([0]="prog" [1]="cmd_multi_arg_with_choice_fn_and_comma_sep") 15 | argc__fn=cmd_multi_arg_with_choice_fn_and_comma_sep 16 | argc__positionals=([0]="abc" [1]="def") 17 | argc_val=([0]="abc" [1]="def") 18 | cmd_multi_arg_with_choice_fn_and_comma_sep abc def 19 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_options.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | argc__args=([0]="bind-envs" [1]="options") 7 | argc__fn=options 8 | argc__positionals=() 9 | argc_oa1=oa1 10 | argc_oa2=oa2 11 | argc_oa3=oa3 12 | argc_ob=ob 13 | argc_oc=([0]="v1" [1]="v2") 14 | argc_oca=a 15 | argc_occ=([0]="a") 16 | argc_oda=oda 17 | argc_odb=argc 18 | argc_ofa=abc 19 | argc_ofd=([0]="abc" [1]="def") 20 | argc_oxa=([0]="oxa") 21 | options 22 | 23 | 24 | # BUILD_OUTPUT 25 | argc__args=([0]="prog" [1]="options") 26 | argc__fn=options 27 | argc__positionals=() 28 | argc_oa1=oa1 29 | argc_oa2=oa2 30 | argc_oa3=oa3 31 | argc_ob=ob 32 | argc_oc=([0]="v1" [1]="v2") 33 | argc_oca=a 34 | argc_occ=([0]="a") 35 | argc_oda=oda 36 | argc_odb=argc 37 | argc_ofa=abc 38 | argc_ofd=([0]="abc" [1]="def") 39 | argc_oxa=([0]="oxa") 40 | options 41 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_options_choice_err.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | error: invalid value `oca` for environment variable `OCA` that bound to `--oca` 7 | [possible values: a, b] 8 | 9 | 10 | # BUILD_OUTPUT 11 | error: invalid value `oca` for environment variable `OCA` that bound to `--oca ` 12 | [possible values: a, b] 13 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_options_choice_fn_err.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | error: invalid value `ofa` for environment variable `OFA` that bound to `--ofa` 7 | [possible values: abc, def, ghi] 8 | 9 | 10 | # BUILD_OUTPUT 11 | error: invalid value `ofa` for environment variable `OFA` that bound to `--ofa ` 12 | [possible values: abc, def, ghi] 13 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_options_choice_ok.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | argc__args=([0]="bind-envs" [1]="options" [2]="--oca" [3]="a") 7 | argc__fn=options 8 | argc__positionals=() 9 | argc_ob=ob 10 | argc_oca=a 11 | argc_oda=a 12 | argc_odb=argc 13 | options 14 | 15 | 16 | # BUILD_OUTPUT 17 | argc__args=([0]="prog" [1]="options" [2]="--oca" [3]="a") 18 | argc__fn=options 19 | argc__positionals=() 20 | argc_ob=ob 21 | argc_oca=a 22 | argc_oda=a 23 | argc_odb=argc 24 | options 25 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_options_help.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | USAGE: bind-envs options [OPTIONS] --ob 7 | 8 | OPTIONS: 9 | --oa1 [env: OA1] 10 | --oa2 [env: OA2] 11 | --oa3 [env: OA] 12 | --ob [env: OB] 13 | --oc [OC]... [env: OC] 14 | --oda [default: a] [env: ODA] 15 | --odb [env: ODB] 16 | --oca [possible values: a, b] [env: OCA] 17 | --occ [OCC]... [possible values: a, b] [env: OCC] 18 | --ofa [env: OFA] 19 | --ofd [OFD]... [env: OFD] 20 | --oxa [env: OXA] 21 | -h, --help 22 | 23 | 24 | 25 | # BUILD_OUTPUT 26 | USAGE: prog options [OPTIONS] --ob 27 | 28 | OPTIONS: 29 | --oa1 [env: OA1] 30 | --oa2 [env: OA2] 31 | --oa3 [env: OA] 32 | --ob [env: OB] 33 | --oc [OC]... [env: OC] 34 | --oda [default: a] [env: ODA] 35 | --odb [env: ODB] 36 | --oca [possible values: a, b] [env: OCA] 37 | --occ [OCC]... [possible values: a, b] [env: OCC] 38 | --ofa [env: OFA] 39 | --ofd [OFD]... [env: OFD] 40 | --oxa [env: OXA] 41 | -h, --help 42 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_options_required_err.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | error: the following required arguments were not provided: 7 | --ob 8 | 9 | 10 | # BUILD_OUTPUT 11 | error: the following required arguments were not provided: 12 | --ob 13 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_with_notation.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | argc_OA=oa 7 | argc__args=([0]="bind-envs" [1]="cmd_for_notation") 8 | argc__fn=cmd_for_notation 9 | argc__positionals=([0]="v1") 10 | argc_val=v1 11 | cmd_for_notation v1 12 | 13 | 14 | # BUILD_OUTPUT 15 | argc_OA=oa 16 | argc__args=([0]="prog" [1]="cmd_for_notation") 17 | argc__fn=cmd_for_notation 18 | argc__positionals=([0]="v1") 19 | argc_val=v1 20 | cmd_for_notation v1 21 | -------------------------------------------------------------------------------- /tests/snapshots/integration__bind_env__bind_env_with_notation_help.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/bind_env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | USAGE: bind-envs cmd_for_notation [OPTIONS] [XYZ] 7 | 8 | ARGS: 9 | [XYZ] [env: VAL] 10 | 11 | OPTIONS: 12 | --OA [env: OA] 13 | -h, --help 14 | 15 | 16 | 17 | # BUILD_OUTPUT 18 | USAGE: prog cmd_for_notation [OPTIONS] [XYZ] 19 | 20 | ARGS: 21 | [XYZ] [env: VAL] 22 | 23 | OPTIONS: 24 | --OA [env: OA] 25 | -h, --help 26 | -------------------------------------------------------------------------------- /tests/snapshots/integration__cli__parallel.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/cli.rs 3 | expression: text 4 | --- 5 | ARGS: ["task2", "--oa", "3"] 6 | 7 | STDOUT: 8 | cmd1 abc 9 | argc__args=([0]="Argcfile" [1]="task2" [2]="--oa" [3]="3") 10 | argc__fn=task2 11 | argc__positionals=() 12 | argc_oa=3 13 | ARGC_PARALLEL=1 14 | ARGC_VARS=YXJnY19vYT0zO2FyZ2NfX2FyZ3M9KCBBcmdjZmlsZSB0YXNrMiAtLW9hIDMgKTthcmdjX19mbj10YXNrMjthcmdjX19wb3NpdGlvbmFscz0oICApOw== 15 | cmd2 16 | argc__args=([0]="Argcfile" [1]="task2" [2]="--oa" [3]="3") 17 | argc__fn=task2 18 | argc__positionals=() 19 | argc_oa=3 20 | ARGC_PARALLEL=1 21 | ARGC_VARS=YXJnY19vYT0zO2FyZ2NfX2FyZ3M9KCBBcmdjZmlsZSB0YXNrMiAtLW9hIDMgKTthcmdjX19mbj10YXNrMjthcmdjX19wb3NpdGlvbmFscz0oICApOw== 22 | 23 | 24 | STDERR: 25 | cmd1 abc 26 | cmd2 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__arg_terminated.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `sudo cmd ` ************ 6 | __argc_filter= /color:default 7 | cmd /color:default 8 | ok /color:default 9 | 10 | ************ COMPGEN `sudo cmd -` ************ 11 | __argc_filter= /color:default 12 | cmd - /color:default 13 | ok /color:default 14 | 15 | ************ COMPGEN `sudo cmd --` ************ 16 | __argc_filter= /color:default 17 | cmd -- /color:default 18 | ok /color:default 19 | 20 | ************ COMPGEN `sudo cmd --foo` ************ 21 | __argc_filter= /color:default 22 | cmd --foo /color:default 23 | ok /color:default 24 | 25 | ************ COMPGEN `sudo cmd foo` ************ 26 | __argc_filter= /color:default 27 | cmd foo /color:default 28 | ok /color:default 29 | 30 | 31 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__assign_option_value.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog --oa=abc` ************ 6 | __argc_filter= /color:default 7 | ARGC_COMPGEN=1 /color:default 8 | ARGC_CWORD=abc /color:default 9 | ARGC_LAST_ARG=--oa=abc /color:default 10 | ARGC_VARS=YXJnY19vYT1hYmM7YXJnY19fYXJncz0oIHByb2cgJy0tb2E9YWJjJyApO2FyZ2NfX2NtZF9hcmdfaW5kZXg9MDthcmdjX19vcHRpb249YXJnY19vYTthcmdjX19wb3NpdGlvbmFscz0oICApOw== /color:default 11 | argc__args=([0]="prog" [1]="--oa=abc") /color:default 12 | argc__cmd_arg_index=0 /color:default 13 | argc__option=argc_oa /color:default 14 | argc__positionals=() /color:default 15 | argc_oa=abc /color:default 16 | 17 | ************ COMPGEN `prog oa=abc` ************ 18 | __argc_filter= /color:default 19 | ARGC_COMPGEN=1 /color:default 20 | ARGC_CWORD=oa=abc /color:default 21 | ARGC_LAST_ARG=oa=abc /color:default 22 | ARGC_VARS=YXJnY192YWw9J29hPWFiYyc7YXJnY19fYXJncz0oIHByb2cgJ29hPWFiYycgKTthcmdjX19jbWRfYXJnX2luZGV4PTA7YXJnY19fcG9zaXRpb25hbHM9KCAnb2E9YWJjJyApOw== /color:default 23 | argc__args=([0]="prog" [1]="oa=abc") /color:default 24 | argc__cmd_arg_index=0 /color:default 25 | argc__positionals=([0]="oa=abc") /color:default 26 | argc_val=oa=abc /color:default 27 | 28 | ************ COMPGEN `prog -- --oa=abc` ************ 29 | __argc_filter= /color:default 30 | ARGC_COMPGEN=1 /color:default 31 | ARGC_CWORD=--oa=abc /color:default 32 | ARGC_LAST_ARG=--oa=abc /color:default 33 | ARGC_VARS=YXJnY192YWw9Jy0tb2E9YWJjJzthcmdjX19hcmdzPSggcHJvZyAtLSAnLS1vYT1hYmMnICk7YXJnY19fY21kX2FyZ19pbmRleD0wO2FyZ2NfX2Rhc2g9MDthcmdjX19wb3NpdGlvbmFscz0oICctLW9hPWFiYycgKTs= /color:default 34 | argc__args=([0]="prog" [1]="--" [2]="--oa=abc") /color:default 35 | argc__cmd_arg_index=0 /color:default 36 | argc__dash=0 /color:default 37 | argc__positionals=([0]="--oa=abc") /color:default 38 | argc_val=--oa=abc /color:default 39 | 40 | 41 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__auto_alias_subcommand.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog ` ************ 6 | cmd_a /color:magenta 7 | cmd-a /color:magenta 8 | help /color:magenta 9 | 10 | ************ COMPGEN `prog cmd` ************ 11 | cmd_a /color:magenta 12 | cmd-a /color:magenta 13 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__bash_shell.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog --oa ` ************ 6 | abc: 7 | 8 | ************ COMPGEN `prog --oa abc:` ************ 9 | def:xyz 10 | def:tsr 11 | ijk:abc 12 | ijk:xyz 13 | 14 | ************ COMPGEN `prog --ob /A/B` ************ 15 | B 16 | B/ 17 | 18 | ************ COMPGEN `prog --oc foo=` ************ 19 | 20 | 21 | ************ COMPGEN `prog -` ************ 22 | --oa 23 | --ob 24 | --oc 25 | --fa 26 | --help 27 | -h 28 | --version 29 | -V 30 | 31 | 32 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__break_chars_bash.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog a1:b` ************ 6 | b1 7 | b2 8 | 9 | ************ COMPGEN `prog a1@b` ************ 10 | @b1 11 | @b2 12 | 13 | ************ COMPGEN `prog a1=b` ************ 14 | b1 15 | b2 16 | 17 | ************ COMPGEN `prog a1 b` ************ 18 | a1\ b1 19 | a1\ b2 20 | 21 | 22 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__break_chars_powershell.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog abc,` ************ 6 | def 1 def 39 7 | ghi 1 ghi 39 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__choice.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog --oa ` ************ 6 | abc /color:default 7 | def /color:default 8 | ghi /color:default 9 | 10 | ************ COMPGEN `prog --oa=` ************ 11 | abc /color:default 12 | def /color:default 13 | ghi /color:default 14 | 15 | ************ COMPGEN `prog --oa=a` ************ 16 | abc /color:default 17 | 18 | ************ COMPGEN `prog --oa =a` ************ 19 | 20 | 21 | ************ COMPGEN `prog --ob ` ************ 22 | x /color:default 23 | y /color:default 24 | z /color:default 25 | 26 | ************ COMPGEN `prog ` ************ 27 | x /color:default 28 | y /color:default 29 | z /color:default 30 | 31 | ************ COMPGEN `prog v1 ` ************ 32 | abc /color:default 33 | def /color:default 34 | ghi /color:default 35 | 36 | ************ COMPGEN `prog '--oa=` ************ 37 | abc /color:default 38 | def /color:default 39 | ghi /color:default 40 | 41 | ************ COMPGEN `prog '--oa=a` ************ 42 | abc /color:default 43 | 44 | ************ COMPGEN `prog "--oa=` ************ 45 | abc /color:default 46 | def /color:default 47 | ghi /color:default 48 | 49 | ************ COMPGEN `prog "--oa=a` ************ 50 | abc /color:default 51 | 52 | ************ COMPGEN `prog --oc ` ************ 53 | abc /color:default 54 | def /color:default 55 | ghi /color:default 56 | 57 | ************ COMPGEN `prog --oc abc,` ************ 58 | def /color:default 59 | ghi /color:default 60 | 61 | 62 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__choice_check_vars.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog argc` ************ 6 | argc__args=([0]="prog" [1]="argc") /color:default 7 | argc__cmd_arg_index=0 /color:default 8 | argc__positionals=([0]="argc") /color:default 9 | argc_foo=argc /color:default 10 | 11 | ************ COMPGEN `prog argc ` ************ 12 | argc__args=([0]="prog" [1]="argc" [2]="") /color:default 13 | argc__cmd_arg_index=0 /color:default 14 | argc__positionals=([0]="argc" [1]="") /color:default 15 | argc_bar= /color:default 16 | argc_foo=argc /color:default 17 | 18 | ************ COMPGEN `prog argc argc` ************ 19 | argc__args=([0]="prog" [1]="argc" [2]="argc") /color:default 20 | argc__cmd_arg_index=0 /color:default 21 | argc__positionals=([0]="argc" [1]="argc") /color:default 22 | argc_bar=argc /color:default 23 | argc_foo=argc /color:default 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__choice_multi.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog --oa ` ************ 6 | abc /color:default 7 | def /color:default 8 | ghi /color:default 9 | 10 | ************ COMPGEN `prog --oa=` ************ 11 | abc /color:default 12 | def /color:default 13 | ghi /color:default 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__choice_slash.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog cmd a\b ` ************ 6 | a\b /color:default 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__cmd_aliases.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog ` ************ 6 | abc 7 | ab 8 | help 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__dashes_at.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog abc ` ************ 6 | abc /color:default 7 | def /color:default 8 | ghi /color:default 9 | 10 | ************ COMPGEN `prog abc -- ` ************ 11 | v1 /color:default 12 | v2 /color:default 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__default_subcommand.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog ` ************ 6 | cmda /color:magenta 7 | cmdb /color:magenta 8 | help /color:magenta 9 | abc /color:default 10 | def /color:default 11 | ijk /color:default 12 | 13 | ************ COMPGEN `prog abc ` ************ 14 | abc /color:default 15 | def /color:default 16 | ijk /color:default 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__delegated.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog abc` ************ 6 | abc 7 | 8 | ************ COMPGEN `prog -a` ************ 9 | -a 10 | 11 | ************ COMPGEN `prog -` ************ 12 | - 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__desc.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog --oa ` ************ 6 | abc (desc) 7 | def (desc) 8 | ijk (value (desc)) 9 | xyz ([desc]) 10 | cjk (福聲幸雪弓們家扒乍植哪黑信,坡也士背文反四未間美穿八和經。何朵申別兆洋行苗青誰圓弓葉福音語:向哭扒長次友誰員完) 11 | 12 | ************ COMPGEN Elvish `prog --oa ` ************ 13 | abc 1 abc desc default 14 | def 1 def desc default 15 | ijk 1 ijk value (desc) default 16 | xyz 1 xyz [desc] default 17 | cjk 1 cjk 福聲幸雪弓們家扒乍植哪黑信,坡也士背文反四未間美穿八和經。何朵申別兆洋行苗青誰圓弓葉福音語:向哭扒長次友誰員完 default 18 | 19 | ************ COMPGEN Fish `prog --oa ` ************ 20 | abc desc 21 | def desc 22 | ijk value (desc) 23 | xyz [desc] 24 | cjk 福聲幸雪弓們家扒乍植哪黑信,坡也士背文反四未間美穿八和經。何朵申別兆洋行苗青誰圓弓葉福音語:向哭扒長次友誰員完 25 | 26 | ************ COMPGEN Nushell `prog --oa ` ************ 27 | abc desc 28 | def desc 29 | ijk value (desc) 30 | xyz [desc] 31 | cjk 福聲幸雪弓們家扒乍植哪黑信,坡也士背文反四未間美穿八和經。何朵申別兆洋行苗青誰圓弓葉福音語:向哭扒長次友誰員完 32 | 33 | ************ COMPGEN Powershell `prog --oa ` ************ 34 | abc 1 abc desc 39 35 | def 1 def desc 39 36 | ijk 1 ijk value (desc) 39 37 | xyz 1 xyz [desc] 39 38 | cjk 1 cjk 福聲幸雪弓們家扒乍植哪黑信,坡也士背文反四未間美穿八和經。何朵申別兆洋行苗青誰圓弓葉福音語:向哭扒長次友誰員完 39 39 | 40 | ************ COMPGEN Xonsh `prog --oa ` ************ 41 | abc 1 abc desc 42 | def 1 def desc 43 | ijk 1 ijk value (desc) 44 | xyz 1 xyz [desc] 45 | cjk 1 cjk 福聲幸雪弓們家扒乍植哪黑信,坡也士背文反四未間美穿八和經。何朵申別兆洋行苗青誰圓弓葉福音語:向哭扒長次友誰員完 46 | 47 | ************ COMPGEN Zsh `prog --oa ` ************ 48 | abc abc:desc abc 39 49 | def def:desc def 39 50 | ijk ijk:value (desc) ijk 39 51 | xyz xyz:[desc] xyz 39 52 | cjk cjk:福聲幸雪弓們家扒乍植哪黑信,坡也士背文反四未間美穿八和經。何朵申別兆洋行苗青誰圓弓葉福音語:向哭扒長次友誰員完 cjk 39 53 | 54 | ************ COMPGEN Tcsh `prog --oa ` ************ 55 | abc⠀(desc) 56 | def⠀(desc) 57 | ijk⠀(value⠀(desc)) 58 | xyz⠀([desc]) 59 | cjk⠀(福聲幸雪弓們家扒乍植哪黑信,坡也士背文反四未間美穿八和經。何朵申別兆洋行苗青誰圓弓葉福音語:向哭扒長次友誰員完) 60 | 61 | 62 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__desc2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog --oa a` ************ 6 | abc 7 | 8 | ************ COMPGEN Elvish `prog --oa a` ************ 9 | abc 1 abc desc1 default 10 | 11 | ************ COMPGEN Fish `prog --oa a` ************ 12 | abc desc1 13 | 14 | ************ COMPGEN Nushell `prog --oa a` ************ 15 | abc desc1 16 | 17 | ************ COMPGEN Powershell `prog --oa a` ************ 18 | abc 1 abc desc1 39 19 | 20 | ************ COMPGEN Xonsh `prog --oa a` ************ 21 | abc 1 abc desc1 22 | 23 | ************ COMPGEN Zsh `prog --oa a` ************ 24 | abc abc:desc1 abc 39 25 | 26 | ************ COMPGEN Tcsh `prog --oa a` ************ 27 | abc 28 | 29 | 30 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__escape.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog --oa ` ************ 6 | a:b\>c 7 | d:e\>f 8 | 9 | ************ COMPGEN Elvish `prog --oa ` ************ 10 | a:b>c 1 a:b>c default 11 | d:e>f 1 d:e>f default 12 | 13 | ************ COMPGEN Fish `prog --oa ` ************ 14 | a:b>c 15 | d:e>f 16 | 17 | ************ COMPGEN Nushell `prog --oa ` ************ 18 | a:b>c 19 | d:e>f 20 | 21 | ************ COMPGEN Powershell `prog --oa ` ************ 22 | a:b>c 1 a:b>c 39 23 | d:e>f 1 d:e>f 39 24 | 25 | ************ COMPGEN Xonsh `prog --oa ` ************ 26 | 'a:b>c' 1 a:b>c 27 | 'd:e>f' 1 d:e>f 28 | 29 | ************ COMPGEN Zsh `prog --oa ` ************ 30 | a\:b\\>c a\:b>c a:b>c 39 31 | d\:e\\>f d\:e>f d:e>f 39 32 | 33 | ************ COMPGEN Tcsh `prog --oa ` ************ 34 | a:b\>c 35 | d:e\>f 36 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__fallback_comp_file.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog args ` ************ 6 | __argc_value=path /color:default 7 | 8 | ************ COMPGEN `prog args v` ************ 9 | __argc_value=path /color:default 10 | 11 | ************ COMPGEN `prog cmd --file ` ************ 12 | __argc_value=FILE /color:default 13 | 14 | ************ COMPGEN `prog cmd --file v` ************ 15 | __argc_value=FILE /color:default 16 | 17 | ************ COMPGEN `prog cmd --value ` ************ 18 | __argc_value=VALUE /color:default 19 | 20 | ************ COMPGEN `prog cmd --value v` ************ 21 | __argc_value=VALUE /color:default 22 | 23 | 24 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__filedir__cd.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog --oa ` ************ 6 | argc_value.rs 1 argc_value.rs default 7 | bin/ 0 bin/ blue bold 8 | build.rs 1 build.rs default 9 | command/ 0 command/ blue bold 10 | compgen.rs 1 compgen.rs default 11 | completions/ 0 completions/ blue bold 12 | lib.rs 1 lib.rs default 13 | mangen.rs 1 mangen.rs default 14 | matcher.rs 1 matcher.rs default 15 | param.rs 1 param.rs default 16 | parser.rs 1 parser.rs default 17 | runtime/ 0 runtime/ blue bold 18 | shell.rs 1 shell.rs default 19 | utils.rs 1 utils.rs default 20 | 21 | ************ COMPGEN `prog --oa=` ************ 22 | --oa=argc_value.rs 1 argc_value.rs default 23 | --oa=bin/ 0 bin/ blue bold 24 | --oa=build.rs 1 build.rs default 25 | --oa=command/ 0 command/ blue bold 26 | --oa=compgen.rs 1 compgen.rs default 27 | --oa=completions/ 0 completions/ blue bold 28 | --oa=lib.rs 1 lib.rs default 29 | --oa=mangen.rs 1 mangen.rs default 30 | --oa=matcher.rs 1 matcher.rs default 31 | --oa=param.rs 1 param.rs default 32 | --oa=parser.rs 1 parser.rs default 33 | --oa=runtime/ 0 runtime/ blue bold 34 | --oa=shell.rs 1 shell.rs default 35 | --oa=utils.rs 1 utils.rs default 36 | 37 | ************ COMPGEN `prog --ob ` ************ 38 | argc_value.rs: 0 argc_value.rs: default 39 | bin/ 0 bin/ blue bold 40 | build.rs: 0 build.rs: default 41 | command/ 0 command/ blue bold 42 | compgen.rs: 0 compgen.rs: default 43 | completions/ 0 completions/ blue bold 44 | lib.rs: 0 lib.rs: default 45 | mangen.rs: 0 mangen.rs: default 46 | matcher.rs: 0 matcher.rs: default 47 | param.rs: 0 param.rs: default 48 | parser.rs: 0 parser.rs: default 49 | runtime/ 0 runtime/ blue bold 50 | shell.rs: 0 shell.rs: default 51 | utils.rs: 0 utils.rs: default 52 | 53 | ************ COMPGEN `prog foo=` ************ 54 | foo=argc_value.rs 1 argc_value.rs default 55 | foo=bin/ 0 bin/ blue bold 56 | foo=build.rs 1 build.rs default 57 | foo=command/ 0 command/ blue bold 58 | foo=compgen.rs 1 compgen.rs default 59 | foo=completions/ 0 completions/ blue bold 60 | foo=lib.rs 1 lib.rs default 61 | foo=mangen.rs 1 mangen.rs default 62 | foo=matcher.rs 1 matcher.rs default 63 | foo=param.rs 1 param.rs default 64 | foo=parser.rs 1 parser.rs default 65 | foo=runtime/ 0 runtime/ blue bold 66 | foo=shell.rs 1 shell.rs default 67 | foo=utils.rs 1 utils.rs default 68 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__filedir__cd_win.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog --oa ` ************ 6 | .\argc_value.rs 1 .\argc_value.rs 39 7 | .\bin\ 0 .\bin\ 1;34 8 | .\build.rs 1 .\build.rs 39 9 | .\command\ 0 .\command\ 1;34 10 | .\compgen.rs 1 .\compgen.rs 39 11 | .\completions\ 0 .\completions\ 1;34 12 | .\lib.rs 1 .\lib.rs 39 13 | .\mangen.rs 1 .\mangen.rs 39 14 | .\matcher.rs 1 .\matcher.rs 39 15 | .\param.rs 1 .\param.rs 39 16 | .\parser.rs 1 .\parser.rs 39 17 | .\runtime\ 0 .\runtime\ 1;34 18 | .\shell.rs 1 .\shell.rs 39 19 | .\utils.rs 1 .\utils.rs 39 20 | 21 | ************ COMPGEN `prog --ob ` ************ 22 | .\argc_value.rs: 0 .\argc_value.rs: 39 23 | .\bin\ 0 .\bin\ 1;34 24 | .\build.rs: 0 .\build.rs: 39 25 | .\command\ 0 .\command\ 1;34 26 | .\compgen.rs: 0 .\compgen.rs: 39 27 | .\completions\ 0 .\completions\ 1;34 28 | .\lib.rs: 0 .\lib.rs: 39 29 | .\mangen.rs: 0 .\mangen.rs: 39 30 | .\matcher.rs: 0 .\matcher.rs: 39 31 | .\param.rs: 0 .\param.rs: 39 32 | .\parser.rs: 0 .\parser.rs: 39 33 | .\runtime\ 0 .\runtime\ 1;34 34 | .\shell.rs: 0 .\shell.rs: 39 35 | .\utils.rs: 0 .\utils.rs: 39 36 | 37 | ************ COMPGEN `prog --oa=` ************ 38 | --oa=.\argc_value.rs 1 .\argc_value.rs 39 39 | --oa=.\bin\ 0 .\bin\ 1;34 40 | --oa=.\build.rs 1 .\build.rs 39 41 | --oa=.\command\ 0 .\command\ 1;34 42 | --oa=.\compgen.rs 1 .\compgen.rs 39 43 | --oa=.\completions\ 0 .\completions\ 1;34 44 | --oa=.\lib.rs 1 .\lib.rs 39 45 | --oa=.\mangen.rs 1 .\mangen.rs 39 46 | --oa=.\matcher.rs 1 .\matcher.rs 39 47 | --oa=.\param.rs 1 .\param.rs 39 48 | --oa=.\parser.rs 1 .\parser.rs 39 49 | --oa=.\runtime\ 0 .\runtime\ 1;34 50 | --oa=.\shell.rs 1 .\shell.rs 39 51 | --oa=.\utils.rs 1 .\utils.rs 39 52 | 53 | ************ COMPGEN `prog foo=` ************ 54 | foo=.\argc_value.rs 1 .\argc_value.rs 39 55 | foo=.\bin\ 0 .\bin\ 1;34 56 | foo=.\build.rs 1 .\build.rs 39 57 | foo=.\command\ 0 .\command\ 1;34 58 | foo=.\compgen.rs 1 .\compgen.rs 39 59 | foo=.\completions\ 0 .\completions\ 1;34 60 | foo=.\lib.rs 1 .\lib.rs 39 61 | foo=.\mangen.rs 1 .\mangen.rs 39 62 | foo=.\matcher.rs 1 .\matcher.rs 39 63 | foo=.\param.rs 1 .\param.rs 39 64 | foo=.\parser.rs 1 .\parser.rs 39 65 | foo=.\runtime\ 0 .\runtime\ 1;34 66 | foo=.\shell.rs 1 .\shell.rs 39 67 | foo=.\utils.rs 1 .\utils.rs 39 68 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__filedir__value_name.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog --oa src/` ************ 6 | src/argc_value.rs 1 argc_value.rs default 7 | src/bin/ 0 bin/ blue bold 8 | src/build.rs 1 build.rs default 9 | src/command/ 0 command/ blue bold 10 | src/compgen.rs 1 compgen.rs default 11 | src/completions/ 0 completions/ blue bold 12 | src/lib.rs 1 lib.rs default 13 | src/mangen.rs 1 mangen.rs default 14 | src/matcher.rs 1 matcher.rs default 15 | src/param.rs 1 param.rs default 16 | src/parser.rs 1 parser.rs default 17 | src/runtime/ 0 runtime/ blue bold 18 | src/shell.rs 1 shell.rs default 19 | src/utils.rs 1 utils.rs default 20 | 21 | ************ COMPGEN `prog --oa src/p` ************ 22 | src/param.rs 1 param.rs default 23 | src/parser.rs 1 parser.rs default 24 | 25 | ************ COMPGEN `prog --oa ./src/` ************ 26 | ./src/argc_value.rs 1 argc_value.rs default 27 | ./src/bin/ 0 bin/ blue bold 28 | ./src/build.rs 1 build.rs default 29 | ./src/command/ 0 command/ blue bold 30 | ./src/compgen.rs 1 compgen.rs default 31 | ./src/completions/ 0 completions/ blue bold 32 | ./src/lib.rs 1 lib.rs default 33 | ./src/mangen.rs 1 mangen.rs default 34 | ./src/matcher.rs 1 matcher.rs default 35 | ./src/param.rs 1 param.rs default 36 | ./src/parser.rs 1 parser.rs default 37 | ./src/runtime/ 0 runtime/ blue bold 38 | ./src/shell.rs 1 shell.rs default 39 | ./src/utils.rs 1 utils.rs default 40 | 41 | ************ COMPGEN `prog --oa C` ************ 42 | Cargo.lock 1 Cargo.lock default 43 | Cargo.toml 1 Cargo.toml default 44 | 45 | ************ COMPGEN `prog --oa ./C` ************ 46 | ./Cargo.lock 1 Cargo.lock default 47 | ./Cargo.toml 1 Cargo.toml default 48 | 49 | ************ COMPGEN `prog --ob src/completions/ar` ************ 50 | src/completions/argc.zsh 1 argc.zsh default 51 | 52 | ************ COMPGEN `prog --oc src/` ************ 53 | src/bin/ 0 bin/ blue bold 54 | src/command/ 0 command/ blue bold 55 | src/completions/ 0 completions/ blue bold 56 | src/runtime/ 0 runtime/ blue bold 57 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__filedir__value_name_win.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog --oa src\` ************ 6 | src\argc_value.rs 1 argc_value.rs 39 7 | src\bin\ 0 bin\ 1;34 8 | src\build.rs 1 build.rs 39 9 | src\command\ 0 command\ 1;34 10 | src\compgen.rs 1 compgen.rs 39 11 | src\completions\ 0 completions\ 1;34 12 | src\lib.rs 1 lib.rs 39 13 | src\mangen.rs 1 mangen.rs 39 14 | src\matcher.rs 1 matcher.rs 39 15 | src\param.rs 1 param.rs 39 16 | src\parser.rs 1 parser.rs 39 17 | src\runtime\ 0 runtime\ 1;34 18 | src\shell.rs 1 shell.rs 39 19 | src\utils.rs 1 utils.rs 39 20 | 21 | ************ COMPGEN `prog --oa src\p` ************ 22 | src\param.rs 1 param.rs 39 23 | src\parser.rs 1 parser.rs 39 24 | 25 | ************ COMPGEN `prog --oa .\src\` ************ 26 | .\src\argc_value.rs 1 argc_value.rs 39 27 | .\src\bin\ 0 bin\ 1;34 28 | .\src\build.rs 1 build.rs 39 29 | .\src\command\ 0 command\ 1;34 30 | .\src\compgen.rs 1 compgen.rs 39 31 | .\src\completions\ 0 completions\ 1;34 32 | .\src\lib.rs 1 lib.rs 39 33 | .\src\mangen.rs 1 mangen.rs 39 34 | .\src\matcher.rs 1 matcher.rs 39 35 | .\src\param.rs 1 param.rs 39 36 | .\src\parser.rs 1 parser.rs 39 37 | .\src\runtime\ 0 runtime\ 1;34 38 | .\src\shell.rs 1 shell.rs 39 39 | .\src\utils.rs 1 utils.rs 39 40 | 41 | ************ COMPGEN `prog --oa C` ************ 42 | .\Cargo.lock 1 .\Cargo.lock 39 43 | .\Cargo.toml 1 .\Cargo.toml 39 44 | 45 | ************ COMPGEN `prog --oa .\C` ************ 46 | .\Cargo.lock 1 Cargo.lock 39 47 | .\Cargo.toml 1 Cargo.toml 39 48 | 49 | ************ COMPGEN `prog --ob src\completions/ar` ************ 50 | src\completions\ar 0 src\completions\ar 39 51 | 52 | ************ COMPGEN `prog --oc src\` ************ 53 | src\bin\ 0 bin\ 1;34 54 | src\command\ 0 command\ 1;34 55 | src\completions\ 0 completions\ 1;34 56 | src\runtime\ 0 runtime\ 1;34 57 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__filter_quote.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog v='` ************ 6 | foo 7 | bar 8 | 9 | ************ COMPGEN Elvish `prog v='` ************ 10 | v='foo 0 foo default 11 | v='bar 0 bar default 12 | 13 | ************ COMPGEN Fish `prog v='` ************ 14 | v='foo 15 | v='bar 16 | 17 | ************ COMPGEN Nushell `prog v='` ************ 18 | v='foo 19 | v='bar 20 | 21 | ************ COMPGEN Powershell `prog v='` ************ 22 | v='foo 0 foo 39 23 | v='bar 0 bar 39 24 | 25 | ************ COMPGEN Xonsh `prog v='` ************ 26 | v='foo 0 foo 27 | v='bar 0 bar 28 | 29 | ************ COMPGEN Zsh `prog v='` ************ 30 | v='foo foo foo 39 31 | v='bar bar bar 39 32 | 33 | ************ COMPGEN Tcsh `prog v='` ************ 34 | v='foo 35 | v='bar 36 | 37 | 38 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__flag_cmds.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog ` ************ 6 | bar /color:magenta Run bar 7 | help /color:magenta Show help for a command 8 | 9 | ************ COMPGEN `prog -` ************ 10 | -G /color:cyan,bold 11 | -help /color:cyan 12 | -h /color:cyan 13 | -version /color:cyan 14 | -V /color:cyan 15 | --foo /color:magenta Run --foo 16 | -F /color:magenta Run --foo 17 | -B /color:magenta Run bar 18 | 19 | ************ COMPGEN `prog -B` ************ 20 | -B /color:magenta Run bar 21 | -BC /color:cyan 22 | -BD /color:cyan 23 | 24 | ************ COMPGEN `prog -B -` ************ 25 | -C /color:cyan 26 | -D /color:cyan 27 | --fa /color:cyan 28 | -help /color:cyan 29 | -h /color:cyan 30 | 31 | ************ COMPGEN `prog -G` ************ 32 | -G /color:cyan,bold 33 | 34 | 35 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__inherit_flag_options.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog cmda --` ************ 6 | --oa /color:cyan 7 | --ob /color:cyan,bold desc 1 8 | --help /color:cyan 9 | 10 | ************ COMPGEN `prog cmdb --` ************ 11 | --oa /color:cyan 12 | --ob /color:cyan,bold desc 2 13 | --help /color:cyan Print help 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__just_match.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog --oa` ************ 6 | --oa /color:cyan,bold 7 | --oa-file /color:cyan,bold 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__kinds_of.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog ` ************ 6 | a1 (desc a1) 7 | b1 (desc b1) 8 | c1 9 | d1 10 | e1 11 | f1 (desc f1) 12 | 13 | ************ COMPGEN Elvish `prog ` ************ 14 | a1 1 a1 desc a1 default 15 | b1 0 b1 desc b1 default 16 | c1 1 c1 default 17 | d1 0 d1 default 18 | e1 1 e1 default 19 | f1 1 f1 desc f1 yellow 20 | 21 | ************ COMPGEN Fish `prog ` ************ 22 | a1 desc a1 23 | b1 desc b1 24 | c1 25 | d1 26 | e1 27 | f1 desc f1 28 | 29 | ************ COMPGEN Nushell `prog ` ************ 30 | a1 desc a1 31 | b1 desc b1 32 | c1 33 | d1 34 | e1 35 | f1 desc f1 36 | 37 | ************ COMPGEN Powershell `prog ` ************ 38 | a1 1 a1 desc a1 39 39 | b1 0 b1 desc b1 39 40 | c1 1 c1 39 41 | d1 0 d1 39 42 | e1 1 e1 39 43 | f1 1 f1 desc f1 33 44 | 45 | ************ COMPGEN Xonsh `prog ` ************ 46 | a1 1 a1 desc a1 47 | b1 0 b1 desc b1 48 | c1 1 c1 49 | d1 0 d1 50 | e1 1 e1 51 | f1 1 f1 desc f1 52 | 53 | ************ COMPGEN Zsh `prog ` ************ 54 | a1 a1:desc a1 a1 39 55 | b1 b1:desc b1 b1 39 56 | c1 c1 c1 39 57 | d1 d1 d1 39 58 | e1 e1 e1 39 59 | f1 f1:desc f1 f1 33 60 | 61 | ************ COMPGEN Tcsh `prog ` ************ 62 | a1⠀(desc⠀a1) 63 | b1⠀(desc⠀b1) 64 | c1 65 | d1 66 | e1 67 | f1⠀(desc⠀f1) 68 | 69 | 70 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__last_arg_option_assign.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog --ob=` ************ 6 | __argc_value=FILE /color:default 7 | 8 | ************ COMPGEN `prog --oa --ob=` ************ 9 | __argc_filter= /color:default 10 | ok /color:default 11 | 12 | ************ COMPGEN `prog abc --ob=` ************ 13 | __argc_filter= /color:default 14 | ok /color:default 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__multi_char.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog --oa abc,` ************ 6 | def 7 | ijk 8 | 9 | ************ COMPGEN Elvish `prog --oa abc,` ************ 10 | abc,def 0 def default 11 | abc,ijk 0 ijk default 12 | 13 | ************ COMPGEN Fish `prog --oa abc,` ************ 14 | abc,def 15 | abc,ijk 16 | 17 | ************ COMPGEN Nushell `prog --oa abc,` ************ 18 | abc,def 19 | abc,ijk 20 | 21 | ************ COMPGEN Powershell `prog --oa abc,` ************ 22 | def 0 def 39 23 | ijk 0 ijk 39 24 | 25 | ************ COMPGEN Xonsh `prog --oa abc,` ************ 26 | abc,def 0 def 27 | abc,ijk 0 ijk 28 | 29 | ************ COMPGEN Zsh `prog --oa abc,` ************ 30 | abc,def def def 39 31 | abc,ijk ijk ijk 39 32 | 33 | ************ COMPGEN Tcsh `prog --oa abc,` ************ 34 | abc,def 35 | abc,ijk 36 | 37 | 38 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__multi_char2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog --oa=abc,` ************ 6 | def 7 | ijk 8 | 9 | ************ COMPGEN Elvish `prog --oa=abc,` ************ 10 | --oa=abc,def 0 def default 11 | --oa=abc,ijk 0 ijk default 12 | 13 | ************ COMPGEN Fish `prog --oa=abc,` ************ 14 | --oa=abc,def 15 | --oa=abc,ijk 16 | 17 | ************ COMPGEN Nushell `prog --oa=abc,` ************ 18 | --oa=abc,def 19 | --oa=abc,ijk 20 | 21 | ************ COMPGEN Powershell `prog --oa=abc,` ************ 22 | def 0 def 39 23 | ijk 0 ijk 39 24 | 25 | ************ COMPGEN Xonsh `prog --oa=abc,` ************ 26 | --oa=abc,def 0 def 27 | --oa=abc,ijk 0 ijk 28 | 29 | ************ COMPGEN Zsh `prog --oa=abc,` ************ 30 | --oa=abc,def def def 39 31 | --oa=abc,ijk ijk ijk 39 32 | 33 | ************ COMPGEN Tcsh `prog --oa=abc,` ************ 34 | --oa=abc,def 35 | --oa=abc,ijk 36 | 37 | 38 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__multi_parts.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog --oa A/` ************ 6 | A/B 7 | 8 | ************ COMPGEN Elvish `prog --oa A/` ************ 9 | A/B 1 B default 10 | A/B/ 0 B/ default 11 | 12 | ************ COMPGEN Fish `prog --oa A/` ************ 13 | A/B 14 | A/B/ 15 | 16 | ************ COMPGEN Nushell `prog --oa A/` ************ 17 | A/B 18 | A/B/ 19 | 20 | ************ COMPGEN Powershell `prog --oa A/` ************ 21 | A/B 1 B 39 22 | A/B/ 0 B/ 39 23 | 24 | ************ COMPGEN Xonsh `prog --oa A/` ************ 25 | A/B 1 B 26 | A/B/ 0 B/ 27 | 28 | ************ COMPGEN Zsh `prog --oa A/` ************ 29 | A/B B B 39 30 | A/B/ B/ B/ 39 31 | 32 | ************ COMPGEN Tcsh `prog --oa A/` ************ 33 | A/B 34 | A/B/ 35 | 36 | 37 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__multi_parts2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog --oa A/B/` ************ 6 | 7 | C 8 | D 9 | 10 | ************ COMPGEN Elvish `prog --oa A/B/` ************ 11 | A/B/ 1 default 12 | A/B/C 1 C default 13 | A/B/D 1 D default 14 | 15 | ************ COMPGEN Fish `prog --oa A/B/` ************ 16 | A/B/ 17 | A/B/C 18 | A/B/D 19 | 20 | ************ COMPGEN Nushell `prog --oa A/B/` ************ 21 | A/B/ 22 | A/B/C 23 | A/B/D 24 | 25 | ************ COMPGEN Powershell `prog --oa A/B/` ************ 26 | A/B/ 1 39 27 | A/B/C 1 C 39 28 | A/B/D 1 D 39 29 | 30 | ************ COMPGEN Xonsh `prog --oa A/B/` ************ 31 | A/B/ 1 32 | A/B/C 1 C 33 | A/B/D 1 D 34 | 35 | ************ COMPGEN Zsh `prog --oa A/B/` ************ 36 | A/B/ 39 37 | A/B/C C C 39 38 | A/B/D D D 39 39 | 40 | ************ COMPGEN Tcsh `prog --oa A/B/` ************ 41 | A/B/ 42 | A/B/C 43 | A/B/D 44 | 45 | 46 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__multiline_doc.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog ` ************ 6 | cmda /color:magenta cmd-line1 7 | cmdb /color:magenta line 8 | help /color:magenta Show help for a command 9 | 10 | ************ COMPGEN `prog cmda ` ************ 11 | __argc_value=BAR /color:default 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__multiple.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog ` ************ 6 | __argc_value=FILE /color:default 7 | 8 | ************ COMPGEN `prog -` ************ 9 | --fc /color:cyan 10 | -f /color:cyan 11 | --oa /color:cyan,bold 12 | -a /color:cyan,bold 13 | --ob /color:cyan,bold 14 | -b /color:cyan,bold 15 | --oc /color:cyan,bold 16 | -c /color:cyan,bold 17 | --od /color:cyan,bold 18 | -d /color:cyan,bold 19 | --oe /color:cyan,bold 20 | -e /color:cyan,bold 21 | --help /color:cyan 22 | -h /color:cyan 23 | --version /color:cyan 24 | -V /color:cyan 25 | 26 | ************ COMPGEN `prog --` ************ 27 | --fc /color:cyan 28 | --oa /color:cyan,bold 29 | --ob /color:cyan,bold 30 | --oc /color:cyan,bold 31 | --od /color:cyan,bold 32 | --oe /color:cyan,bold 33 | --help /color:cyan 34 | --version /color:cyan 35 | 36 | ************ COMPGEN `prog -- ` ************ 37 | __argc_value=FILE /color:default 38 | 39 | ************ COMPGEN `prog -f ` ************ 40 | __argc_value=FILE /color:default 41 | 42 | ************ COMPGEN `prog --fc ` ************ 43 | __argc_value=FILE /color:default 44 | 45 | ************ COMPGEN `prog -a ` ************ 46 | __argc_value=DIR /color:default 47 | 48 | ************ COMPGEN `prog -a d1` ************ 49 | __argc_value=DIR /color:default 50 | 51 | ************ COMPGEN `prog -a d1 ` ************ 52 | __argc_value=FILE /color:default 53 | 54 | ************ COMPGEN `prog -b ` ************ 55 | __argc_value=CMD /color:default 56 | 57 | ************ COMPGEN `prog -b d1` ************ 58 | __argc_value=CMD /color:default 59 | 60 | ************ COMPGEN `prog -b d1 ` ************ 61 | __argc_value=DIR+ /color:default 62 | 63 | ************ COMPGEN `prog -b d1 d2` ************ 64 | __argc_value=DIR+ /color:default 65 | 66 | ************ COMPGEN `prog -b d1 d2 ` ************ 67 | __argc_value=DIR+ /color:default 68 | 69 | ************ COMPGEN `prog -c ` ************ 70 | __argc_value=DIR+ /color:default 71 | 72 | ************ COMPGEN `prog -c d1` ************ 73 | __argc_value=DIR+ /color:default 74 | 75 | ************ COMPGEN `prog -c d1 ` ************ 76 | __argc_value=DIR+ /color:default 77 | 78 | ************ COMPGEN `prog -d d1` ************ 79 | __argc_value=DIR /color:default 80 | 81 | ************ COMPGEN `prog -d d1 ` ************ 82 | __argc_value=FILE /color:default 83 | 84 | ************ COMPGEN `prog -d d1 d2` ************ 85 | __argc_value=FILE /color:default 86 | 87 | ************ COMPGEN `prog -d d1 d2 ` ************ 88 | __argc_value=FILE /color:default 89 | 90 | ************ COMPGEN `prog -e d1 ` ************ 91 | __argc_value=DIR+ /color:default 92 | 93 | ************ COMPGEN `prog -a d1 -c d2 -` ************ 94 | --fc /color:cyan 95 | -f /color:cyan 96 | --oa /color:cyan,bold 97 | -a /color:cyan,bold 98 | --ob /color:cyan,bold 99 | -b /color:cyan,bold 100 | --od /color:cyan,bold 101 | -d /color:cyan,bold 102 | --oe /color:cyan,bold 103 | -e /color:cyan,bold 104 | --help /color:cyan 105 | -h /color:cyan 106 | --version /color:cyan 107 | -V /color:cyan 108 | 109 | ************ COMPGEN `prog v1` ************ 110 | __argc_value=FILE /color:default 111 | 112 | ************ COMPGEN `prog v1 ` ************ 113 | __argc_value=FILE /color:default 114 | 115 | ************ COMPGEN `prog v1 v2` ************ 116 | __argc_value=FILE /color:default 117 | 118 | ************ COMPGEN `prog v1 v2 ` ************ 119 | __argc_value=FILE /color:default 120 | 121 | 122 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__nested_subcmds.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog ` ************ 6 | __argc_value=FILE /color:default 7 | cmd /color:magenta 8 | help /color:magenta 9 | 10 | ************ COMPGEN `prog cmd` ************ 11 | __argc_value=FILE /color:default 12 | cmd /color:magenta 13 | 14 | ************ COMPGEN `prog cmd ` ************ 15 | suba /color:magenta 16 | subb /color:magenta 17 | help /color:magenta 18 | 19 | ************ COMPGEN `prog cmd s` ************ 20 | suba /color:magenta 21 | subb /color:magenta 22 | 23 | ************ COMPGEN `prog cmd suba` ************ 24 | suba /color:magenta 25 | 26 | ************ COMPGEN `prog cmd suba ` ************ 27 | __argc_value=path /color:default 28 | 29 | ************ COMPGEN `prog cmd help ` ************ 30 | suba /color:magenta 31 | subb /color:magenta 32 | help /color:magenta 33 | 34 | ************ COMPGEN `prog cmd help s` ************ 35 | suba /color:magenta 36 | subb /color:magenta 37 | 38 | 39 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__no_comp_subcmds.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog ` ************ 6 | cmda /color:magenta 7 | cmdb /color:magenta 8 | help /color:magenta 9 | 10 | ************ COMPGEN `prog cmdx ` ************ 11 | __argc_value=path /color:default 12 | 13 | ************ COMPGEN `prog cmdx cmd` ************ 14 | __argc_value=path /color:default 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__no_flags_options.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog no_arg ` ************ 6 | __argc_value=path /color:default 7 | 8 | ************ COMPGEN `prog arg ` ************ 9 | __argc_value=FILE /color:default 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__no_flags_options2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog ` ************ 6 | cmda /color:magenta 7 | cmdb /color:magenta 8 | help /color:magenta 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__no_param.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog cmd ` ************ 6 | __argc_value=path /color:default 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__no_space.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog --oa ` ************ 6 | abc 7 | def 8 | ghk (hello world) 9 | 10 | ************ COMPGEN Elvish `prog --oa ` ************ 11 | abc 1 abc default 12 | def 0 def default 13 | ghk 1 ghk hello world default 14 | 15 | ************ COMPGEN Fish `prog --oa ` ************ 16 | abc 17 | def 18 | ghk hello world 19 | 20 | ************ COMPGEN Nushell `prog --oa ` ************ 21 | abc 22 | def 23 | ghk hello world 24 | 25 | ************ COMPGEN Powershell `prog --oa ` ************ 26 | abc 1 abc 39 27 | def 0 def 39 28 | ghk 1 ghk hello world 39 29 | 30 | ************ COMPGEN Xonsh `prog --oa ` ************ 31 | abc 1 abc 32 | def 0 def 33 | ghk 1 ghk hello world 34 | 35 | ************ COMPGEN Zsh `prog --oa ` ************ 36 | abc abc abc 39 37 | def def def 39 38 | ghk ghk:hello world ghk 39 39 | 40 | ************ COMPGEN Tcsh `prog --oa ` ************ 41 | abc 42 | def 43 | ghk⠀(hello⠀world) 44 | 45 | 46 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__one_combine_shorts.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog -a` ************ 6 | -a /color:cyan 7 | -ab /color:cyan 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__one_subcmd_with_options.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog ` ************ 6 | cmda /color:magenta 7 | help /color:magenta 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__option_assigned.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog --oa` ************ 6 | --oa= /color:cyan,bold 7 | 8 | ************ COMPGEN `prog --oa ` ************ 9 | __argc_value=path /color:default 10 | 11 | ************ COMPGEN `prog --oa=` ************ 12 | abc /color:default 13 | def /color:default 14 | ghi /color:default 15 | 16 | ************ COMPGEN `prog --oa=abc --o` ************ 17 | --ob= /color:cyan,bold 18 | 19 | ************ COMPGEN `prog --ob` ************ 20 | --ob= /color:cyan,bold 21 | 22 | ************ COMPGEN `prog --ob ` ************ 23 | __argc_value=path /color:default 24 | 25 | ************ COMPGEN `prog --ob=` ************ 26 | abc /color:default 27 | def /color:default 28 | ghi /color:default 29 | 30 | ************ COMPGEN `prog --ob=abc --o` ************ 31 | --oa= /color:cyan,bold 32 | --ob= /color:cyan,bold 33 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__option_prefixed.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog -D` ************ 6 | VAR1=value1 /color:default 7 | VAR2=value2 /color:default 8 | VAR3 /color:default 9 | 10 | ************ COMPGEN `prog -DVAR1` ************ 11 | VAR1=value1 /color:default 12 | 13 | ************ COMPGEN `prog -X` ************ 14 | VAR1=value1 /color:default 15 | VAR2=value2 /color:default 16 | VAR3 /color:default 17 | 18 | ************ COMPGEN `prog -XVAR1` ************ 19 | VAR1=value1 /color:default 20 | 21 | ************ COMPGEN `prog -XVAR3 -` ************ 22 | -D /color:cyan,bold 23 | --ox /color:cyan,bold 24 | -X /color:cyan,bold 25 | -s /color:cyan,bold 26 | -help /color:cyan 27 | -h /color:cyan 28 | -version /color:cyan 29 | -V /color:cyan 30 | 31 | ************ COMPGEN `prog --ox` ************ 32 | VAR1=value1 /color:default 33 | VAR2=value2 /color:default 34 | VAR3 /color:default 35 | 36 | ************ COMPGEN `prog --ox VAR1` ************ 37 | VAR1=value1 /color:default 38 | 39 | ************ COMPGEN `prog -s` ************ 40 | VAR1=value1 /color:default 41 | VAR2=value2 /color:default 42 | VAR3 /color:default 43 | 44 | ************ COMPGEN `prog -sVAR3 -` ************ 45 | -D /color:cyan,bold 46 | --ox /color:cyan,bold 47 | -X /color:cyan,bold 48 | -help /color:cyan 49 | -h /color:cyan 50 | -version /color:cyan 51 | -V /color:cyan 52 | 53 | 54 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__option_terminated.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog --oa` ************ 6 | --oa /color:cyan,bold 7 | 8 | ************ COMPGEN `prog --oa ` ************ 9 | __argc_filter= /color:default 10 | ok /color:default 11 | 12 | ************ COMPGEN `prog --oa --` ************ 13 | __argc_filter= /color:default 14 | ok /color:default 15 | 16 | ************ COMPGEN `prog --oa v1 v2` ************ 17 | __argc_filter= /color:default 18 | ok /color:default 19 | 20 | ************ COMPGEN `prog --oa -- ` ************ 21 | __argc_filter= /color:default 22 | ok /color:default 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__plus_sign.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog +` ************ 6 | +a /color:cyan 7 | +fb /color:cyan,bold 8 | +fc /color:cyan,bold 9 | +c /color:cyan,bold 10 | +d /color:cyan,bold 11 | 12 | ************ COMPGEN `prog +fb=` ************ 13 | abc /color:default 14 | def /color:default 15 | ijk /color:default 16 | 17 | ************ COMPGEN `prog +fc ` ************ 18 | abc /color:default 19 | def /color:default 20 | ghi /color:default 21 | 22 | ************ COMPGEN `prog -fd ` ************ 23 | abc /color:default 24 | def /color:default 25 | ghi /color:default 26 | 27 | 28 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__positionals.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog cmda ` ************ 6 | __argc_value=DIR /color:default 7 | 8 | ************ COMPGEN `prog cmda v1` ************ 9 | __argc_value=DIR /color:default 10 | 11 | ************ COMPGEN `prog cmda v1 ` ************ 12 | __argc_value=FILE /color:default 13 | 14 | ************ COMPGEN `prog cmda v1 v2` ************ 15 | __argc_value=FILE /color:default 16 | 17 | ************ COMPGEN `prog cmda v1 v2 ` ************ 18 | __argc_value=FILE /color:default 19 | 20 | ************ COMPGEN `prog cmdb ` ************ 21 | __argc_value=DIR1 /color:default 22 | 23 | ************ COMPGEN `prog cmdb v1` ************ 24 | __argc_value=DIR1 /color:default 25 | 26 | ************ COMPGEN `prog cmdb v1 ` ************ 27 | __argc_value=DIR2 /color:default 28 | 29 | ************ COMPGEN `prog cmdb v1 v2` ************ 30 | __argc_value=DIR2 /color:default 31 | 32 | ************ COMPGEN `prog cmdb v1 v2 ` ************ 33 | __argc_value=DIR3 /color:default 34 | 35 | ************ COMPGEN `prog cmdb v1 v2 v3` ************ 36 | __argc_value=DIR3 /color:default 37 | 38 | ************ COMPGEN `prog cmdb v1 v2 v3 ` ************ 39 | 40 | 41 | ************ COMPGEN `prog cmdc ` ************ 42 | __argc_value=DIR /color:default 43 | 44 | ************ COMPGEN `prog cmdc v1` ************ 45 | __argc_value=DIR /color:default 46 | 47 | ************ COMPGEN `prog cmdc v1 ` ************ 48 | __argc_value=FILE /color:default 49 | 50 | ************ COMPGEN `prog cmdc v1 v2` ************ 51 | __argc_value=FILE /color:default 52 | 53 | ************ COMPGEN `prog cmdc v1 v2 ` ************ 54 | __argc_value=FILE /color:default 55 | 56 | 57 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__redirect_symbols.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog > Argc` ************ 6 | Argcfile.sh 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__shorts.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog ` ************ 6 | __argc_value=path /color:default 7 | 8 | ************ COMPGEN `prog -` ************ 9 | -a /color:cyan 10 | --fb /color:cyan 11 | -b /color:cyan 12 | --fc /color:cyan 13 | -f /color:cyan 14 | -sa /color:cyan 15 | -e /color:cyan,bold 16 | --oa /color:cyan,bold 17 | -p /color:cyan,bold 18 | -help /color:cyan 19 | -h /color:cyan 20 | -version /color:cyan 21 | -V /color:cyan 22 | 23 | ************ COMPGEN `prog --` ************ 24 | --fb /color:cyan 25 | --fc /color:cyan 26 | --oa /color:cyan,bold 27 | 28 | ************ COMPGEN `prog -a` ************ 29 | -ab /color:cyan 30 | -af /color:cyan 31 | -ae /color:cyan,bold 32 | -ap /color:cyan,bold 33 | 34 | ************ COMPGEN `prog -a ` ************ 35 | __argc_value=path /color:default 36 | 37 | ************ COMPGEN `prog -af` ************ 38 | -afb /color:cyan 39 | -aff /color:cyan 40 | -afe /color:cyan,bold 41 | -afp /color:cyan,bold 42 | 43 | ************ COMPGEN `prog -af ` ************ 44 | __argc_value=path /color:default 45 | 46 | ************ COMPGEN `prog -ae` ************ 47 | 48 | 49 | ************ COMPGEN `prog -ae ` ************ 50 | __argc_value=FILE /color:default 51 | 52 | ************ COMPGEN `prog -abe` ************ 53 | 54 | 55 | ************ COMPGEN `prog -abe ` ************ 56 | __argc_value=FILE /color:default 57 | 58 | ************ COMPGEN `prog -s` ************ 59 | -sa /color:cyan 60 | 61 | ************ COMPGEN `prog -sa` ************ 62 | -sa /color:cyan 63 | 64 | ************ COMPGEN `prog -sa ` ************ 65 | __argc_value=path /color:default 66 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__special_arg_name.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog cmda ` ************ 6 | __argc_value=ARG /color:default 7 | 8 | ************ COMPGEN `prog cmdb ` ************ 9 | __argc_value=ANY /color:default 10 | 11 | 12 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__starts_quote.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog --oa='` ************ 6 | abc 7 | def 8 | ijk 9 | 10 | ************ COMPGEN Elvish `prog --oa='` ************ 11 | --oa='abc 0 abc default 12 | --oa='def 0 def default 13 | --oa='ijk 0 ijk default 14 | 15 | ************ COMPGEN Fish `prog --oa='` ************ 16 | --oa='abc 17 | --oa='def 18 | --oa='ijk 19 | 20 | ************ COMPGEN Nushell `prog --oa='` ************ 21 | --oa='abc 22 | --oa='def 23 | --oa='ijk 24 | 25 | ************ COMPGEN Powershell `prog --oa='` ************ 26 | --oa='abc 0 abc 39 27 | --oa='def 0 def 39 28 | --oa='ijk 0 ijk 39 29 | 30 | ************ COMPGEN Xonsh `prog --oa='` ************ 31 | --oa='abc 0 abc 32 | --oa='def 0 def 33 | --oa='ijk 0 ijk 34 | 35 | ************ COMPGEN Zsh `prog --oa='` ************ 36 | --oa='abc abc abc 39 37 | --oa='def def def 39 38 | --oa='ijk ijk ijk 39 39 | 40 | ************ COMPGEN Tcsh `prog --oa='` ************ 41 | --oa='abc 42 | --oa='def 43 | --oa='ijk 44 | 45 | 46 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__starts_quote2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog '--oa=` ************ 6 | abc 7 | def 8 | ijk 9 | 10 | ************ COMPGEN Elvish `prog '--oa=` ************ 11 | '--oa=abc 0 abc default 12 | '--oa=def 0 def default 13 | '--oa=ijk 0 ijk default 14 | 15 | ************ COMPGEN Fish `prog '--oa=` ************ 16 | '--oa=abc 17 | '--oa=def 18 | '--oa=ijk 19 | 20 | ************ COMPGEN Nushell `prog '--oa=` ************ 21 | '--oa=abc 22 | '--oa=def 23 | '--oa=ijk 24 | 25 | ************ COMPGEN Powershell `prog '--oa=` ************ 26 | '--oa=abc 0 abc 39 27 | '--oa=def 0 def 39 28 | '--oa=ijk 0 ijk 39 29 | 30 | ************ COMPGEN Xonsh `prog '--oa=` ************ 31 | '--oa=abc 0 abc 32 | '--oa=def 0 def 33 | '--oa=ijk 0 ijk 34 | 35 | ************ COMPGEN Zsh `prog '--oa=` ************ 36 | --oa=abc abc abc 39 37 | --oa=def def def 39 38 | --oa=ijk ijk ijk 39 39 | 40 | ************ COMPGEN Tcsh `prog '--oa=` ************ 41 | '--oa=abc 42 | '--oa=def 43 | '--oa=ijk 44 | 45 | 46 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__subcmds.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog ` ************ 6 | __argc_value=FILE /color:default 7 | cmda /color:magenta 8 | cmdb /color:magenta 9 | cmdc /color:magenta 10 | help /color:magenta 11 | 12 | ************ COMPGEN `prog c` ************ 13 | __argc_value=FILE /color:default 14 | cmda /color:magenta 15 | cmdb /color:magenta 16 | cmdc /color:magenta 17 | 18 | ************ COMPGEN `prog cmda` ************ 19 | __argc_value=FILE /color:default 20 | cmda /color:magenta 21 | 22 | ************ COMPGEN `prog cmda ` ************ 23 | __argc_value=path /color:default 24 | 25 | ************ COMPGEN `prog help ` ************ 26 | cmda /color:magenta 27 | cmdb /color:magenta 28 | cmdc /color:magenta 29 | help /color:magenta 30 | 31 | ************ COMPGEN `prog help c` ************ 32 | cmda /color:magenta 33 | cmdb /color:magenta 34 | cmdc /color:magenta 35 | 36 | ************ COMPGEN `prog help cmda ` ************ 37 | 38 | 39 | ************ COMPGEN `prog help cmdb` ************ 40 | cmdb /color:magenta 41 | 42 | 43 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__suffix.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog --oa ` ************ 6 | abc= 7 | def= 8 | ghk= 9 | 10 | ************ COMPGEN Elvish `prog --oa ` ************ 11 | abc= 0 abc= default 12 | def= 0 def= default 13 | ghk= 0 ghk= default 14 | 15 | ************ COMPGEN Fish `prog --oa ` ************ 16 | abc= 17 | def= 18 | ghk= 19 | 20 | ************ COMPGEN Nushell `prog --oa ` ************ 21 | abc= 22 | def= 23 | ghk= 24 | 25 | ************ COMPGEN Powershell `prog --oa ` ************ 26 | abc= 0 abc= 39 27 | def= 0 def= 39 28 | ghk= 0 ghk= 39 29 | 30 | ************ COMPGEN Xonsh `prog --oa ` ************ 31 | abc= 0 abc= 32 | def= 0 def= 33 | ghk= 0 ghk= 34 | 35 | ************ COMPGEN Zsh `prog --oa ` ************ 36 | abc= abc= abc= 39 37 | def= def= def= 39 38 | ghk= ghk= ghk= 39 39 | 40 | ************ COMPGEN Tcsh `prog --oa ` ************ 41 | abc= 42 | def= 43 | ghk= 44 | 45 | 46 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__symbol.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN `prog +` ************ 6 | stable /color:default 7 | beta /color:default 8 | nightly /color:default 9 | 10 | ************ COMPGEN `prog @` ************ 11 | __argc_value=file /color:default 12 | 13 | ************ COMPGEN `prog +s` ************ 14 | stable /color:default 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__value.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog --oa abc` ************ 6 | abc\ def 7 | abc\ xyz 8 | abc:def 9 | abc:xyz 10 | abc\>def 11 | abc\>xyz 12 | 13 | ************ COMPGEN Elvish `prog --oa abc` ************ 14 | abc def 1 abc def default 15 | abc xyz 1 abc xyz default 16 | abc:def 1 abc:def default 17 | abc:xyz 1 abc:xyz default 18 | abc>def 1 abc>def default 19 | abc>xyz 1 abc>xyz default 20 | 21 | ************ COMPGEN Fish `prog --oa abc` ************ 22 | abc def 23 | abc xyz 24 | abc:def 25 | abc:xyz 26 | abc>def 27 | abc>xyz 28 | 29 | ************ COMPGEN Nushell `prog --oa abc` ************ 30 | 'abc def' 31 | 'abc xyz' 32 | abc:def 33 | abc:xyz 34 | abc>def 35 | abc>xyz 36 | 37 | ************ COMPGEN Powershell `prog --oa abc` ************ 38 | 'abc def' 1 abc def 39 39 | 'abc xyz' 1 abc xyz 39 40 | abc:def 1 abc:def 39 41 | abc:xyz 1 abc:xyz 39 42 | abc>def 1 abc>def 39 43 | abc>xyz 1 abc>xyz 39 44 | 45 | ************ COMPGEN Xonsh `prog --oa abc` ************ 46 | 'abc def' 1 abc def 47 | 'abc xyz' 1 abc xyz 48 | abc:def 1 abc:def 49 | abc:xyz 1 abc:xyz 50 | 'abc>def' 1 abc>def 51 | 'abc>xyz' 1 abc>xyz 52 | 53 | ************ COMPGEN Zsh `prog --oa abc` ************ 54 | abc\\ def abc def abc def 39 55 | abc\\ xyz abc xyz abc xyz 39 56 | abc\:def abc\:def abc:def 39 57 | abc\:xyz abc\:xyz abc:xyz 39 58 | abc\\>def abc>def abc>def 39 59 | abc\\>xyz abc>xyz abc>xyz 39 60 | 61 | ************ COMPGEN Tcsh `prog --oa abc` ************ 62 | abc\⠀def 63 | abc\⠀xyz 64 | abc:def 65 | abc:xyz 66 | abc\>def 67 | abc\>xyz 68 | -------------------------------------------------------------------------------- /tests/snapshots/integration__compgen__value_display.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/compgen.rs 3 | expression: data 4 | --- 5 | ************ COMPGEN Bash `prog --oa=` ************ 6 | abc: 7 | 8 | ************ COMPGEN Elvish `prog --oa=` ************ 9 | --oa=abc:def:xyz 1 abc:def:xyz default 10 | --oa=abc:def:tsr 1 abc:def:tsr default 11 | --oa=abc:ijk:abc 1 abc:ijk:abc default 12 | --oa=abc:ijk:xyz 1 abc:ijk:xyz default 13 | 14 | ************ COMPGEN Fish `prog --oa=` ************ 15 | --oa=abc:def:xyz 16 | --oa=abc:def:tsr 17 | --oa=abc:ijk:abc 18 | --oa=abc:ijk:xyz 19 | 20 | ************ COMPGEN Nushell `prog --oa=` ************ 21 | --oa=abc:def:xyz 22 | --oa=abc:def:tsr 23 | --oa=abc:ijk:abc 24 | --oa=abc:ijk:xyz 25 | 26 | ************ COMPGEN Powershell `prog --oa=` ************ 27 | --oa=abc:def:xyz 1 abc:def:xyz 39 28 | --oa=abc:def:tsr 1 abc:def:tsr 39 29 | --oa=abc:ijk:abc 1 abc:ijk:abc 39 30 | --oa=abc:ijk:xyz 1 abc:ijk:xyz 39 31 | 32 | ************ COMPGEN Xonsh `prog --oa=` ************ 33 | --oa=abc:def:xyz 1 abc:def:xyz 34 | --oa=abc:def:tsr 1 abc:def:tsr 35 | --oa=abc:ijk:abc 1 abc:ijk:abc 36 | --oa=abc:ijk:xyz 1 abc:ijk:xyz 37 | 38 | ************ COMPGEN Zsh `prog --oa=` ************ 39 | --oa=abc\:def\:xyz abc\:def\:xyz abc:def:xyz 39 40 | --oa=abc\:def\:tsr abc\:def\:tsr abc:def:tsr 39 41 | --oa=abc\:ijk\:abc abc\:ijk\:abc abc:ijk:abc 39 42 | --oa=abc\:ijk\:xyz abc\:ijk\:xyz abc:ijk:xyz 39 43 | 44 | ************ COMPGEN Tcsh `prog --oa=` ************ 45 | --oa=abc:def:xyz 46 | --oa=abc:def:tsr 47 | --oa=abc:ijk:abc 48 | --oa=abc:ijk:xyz 49 | 50 | 51 | -------------------------------------------------------------------------------- /tests/snapshots/integration__env__env_choice.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | 6 | # OUTPUT 7 | error: invalid value `val` for environment variable `TEST_ECA` 8 | [possible values: a, b] 9 | 10 | 11 | # BUILD_OUTPUT 12 | error: invalid value `val` for environment variable `TEST_ECA` 13 | [possible values: a, b] 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/snapshots/integration__env__env_choice_fn.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | 6 | # OUTPUT 7 | error: invalid value `val` for environment variable `TEST_EFA` 8 | [possible values: abc, def, ghi] 9 | 10 | 11 | # BUILD_OUTPUT 12 | error: invalid value `val` for environment variable `TEST_EFA` 13 | [possible values: abc, def, ghi] 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/snapshots/integration__env__env_help.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | All kinds of @env 7 | 8 | USAGE: envs 9 | 10 | COMMANDS: 11 | run 12 | 13 | ENVIRONMENTS: 14 | TEST_EA optional 15 | TEST_EB* required 16 | TEST_EDA default [default: a] 17 | TEST_EDB default from fn 18 | TEST_ECA choice [possible values: a, b] 19 | TEST_ECB choice + default [possible values: a, b] [default: a] 20 | TEST_EFA choice from fn 21 | 22 | 23 | 24 | # BUILD_OUTPUT 25 | All kinds of @env 26 | 27 | USAGE: prog 28 | 29 | COMMANDS: 30 | run 31 | 32 | ENVIRONMENTS: 33 | TEST_EA optional 34 | TEST_EB* required 35 | TEST_EDA default [default: a] 36 | TEST_EDB default from fn 37 | TEST_ECA choice [possible values: a, b] 38 | TEST_ECB choice + default [possible values: a, b] [default: a] 39 | TEST_EFA choice from fn 40 | -------------------------------------------------------------------------------- /tests/snapshots/integration__env__env_help_subcmd.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | # OUTPUT 6 | USAGE: envs run 7 | 8 | ENVIRONMENTS: 9 | TEST_EB* required 10 | TEST_EDA default [default: a] 11 | TEST_EDB default from fn 12 | TEST_ECA choice [possible values: a, b] 13 | TEST_ECB choice + default [possible values: a, b] [default: a] 14 | TEST_EFA choice from fn 15 | TEST_EA override 16 | TEST_NEW append 17 | 18 | 19 | 20 | # BUILD_OUTPUT 21 | USAGE: prog run 22 | 23 | ENVIRONMENTS: 24 | TEST_EB* required 25 | TEST_EDA default [default: a] 26 | TEST_EDB default from fn 27 | TEST_ECA choice [possible values: a, b] 28 | TEST_ECB choice + default [possible values: a, b] [default: a] 29 | TEST_EFA choice from fn 30 | TEST_EA override 31 | TEST_NEW append 32 | -------------------------------------------------------------------------------- /tests/snapshots/integration__env__env_missing.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | 6 | # OUTPUT 7 | error: the following required environments were not provided: 8 | TEST_EB 9 | 10 | 11 | # BUILD_OUTPUT 12 | error: the following required environments were not provided: 13 | TEST_EB 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/snapshots/integration__env__env_run.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/env.rs 3 | expression: "format!(r#\"\n# OUTPUT\n{output}\n\n# BUILD_OUTPUT\n{build_output}\n\"#)" 4 | --- 5 | 6 | # OUTPUT 7 | TEST_EB=1 8 | TEST_ECB=a 9 | TEST_EDA=a 10 | TEST_EDB=argc 11 | 12 | 13 | # BUILD_OUTPUT 14 | TEST_EB=1 15 | TEST_ECB=a 16 | TEST_EDA=a 17 | TEST_EDB=argc 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/snapshots/integration__hook_fn__hook_only_after.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/hook_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__fn=main 11 | argc__positionals=( ) 12 | main 13 | _argc_after 14 | 15 | # BUILD_OUTPUT 16 | argc__args=([0]="prog") 17 | argc__fn=main 18 | argc__positionals=() 19 | main 20 | after 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/snapshots/integration__hook_fn__hook_only_before.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/hook_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__fn=main 11 | argc__positionals=( ) 12 | _argc_before 13 | main 14 | 15 | # BUILD_OUTPUT 16 | before 17 | argc__args=([0]="prog") 18 | argc__fn=main 19 | argc__positionals=() 20 | main 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/snapshots/integration__hook_fn__hook_param_fn.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/hook_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog ___internal___ _choice_fn 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__cmd_arg_index=0 11 | argc__positionals=( ) 12 | _argc_before 13 | _choice_fn 14 | _argc_after 15 | exit 16 | 17 | # BUILD_OUTPUT 18 | error: unsupported ___internal___ command 19 | -------------------------------------------------------------------------------- /tests/snapshots/integration__hook_fn__hook_with_main.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/hook_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__fn=main 11 | argc__positionals=( ) 12 | _argc_before 13 | main 14 | _argc_after 15 | 16 | # BUILD_OUTPUT 17 | before 18 | argc__args=([0]="prog") 19 | argc__fn=main 20 | argc__positionals=() 21 | main 22 | after 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/snapshots/integration__hook_fn__hook_with_subcmd.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/hook_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmd 7 | 8 | # OUTPUT 9 | argc__args=( prog cmd ) 10 | argc__fn=cmd 11 | argc__positionals=( ) 12 | _argc_before 13 | cmd 14 | _argc_after 15 | 16 | # BUILD_OUTPUT 17 | before 18 | argc__args=([0]="prog" [1]="cmd") 19 | argc__fn=cmd 20 | argc__positionals=() 21 | cmd 22 | after 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/snapshots/integration__hook_fn__hook_without_subcmd.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/hook_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__positionals=( ) 11 | _argc_before 12 | 13 | # BUILD_OUTPUT 14 | before 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/snapshots/integration__main_fn__global_with_arg.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/main_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog abc 7 | 8 | # OUTPUT 9 | argc_val=abc 10 | argc__args=( prog abc ) 11 | argc__fn=main 12 | argc__positionals=( abc ) 13 | main abc 14 | 15 | # BUILD_OUTPUT 16 | argc__args=([0]="prog" [1]="abc") 17 | argc__fn=main 18 | argc__positionals=([0]="abc") 19 | argc_val=abc 20 | main abc 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/snapshots/integration__main_fn__global_without_arg.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/main_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog abc 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: `prog` requires a subcommand but 'abc' is not one of them 11 | [subcommands: cmd] 12 | EOF 13 | exit 1 14 | 15 | # BUILD_OUTPUT 16 | error: `prog` requires a subcommand but one was not provided 17 | [subcommands: cmd] 18 | -------------------------------------------------------------------------------- /tests/snapshots/integration__main_fn__nested_subcmd_main.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/main_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmd 7 | 8 | # OUTPUT 9 | argc__args=( prog cmd ) 10 | argc__fn=cmd::main 11 | argc__positionals=( ) 12 | cmd::main 13 | 14 | # BUILD_OUTPUT 15 | argc__args=([0]="prog" [1]="cmd") 16 | argc__fn=cmd::main 17 | argc__positionals=() 18 | cmd::main 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/snapshots/integration__main_fn__nested_subcmd_main2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/main_fn.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog cmd 7 | 8 | # OUTPUT 9 | argc__args=( prog cmd ) 10 | argc__fn=cmd::main 11 | argc__positionals=( ) 12 | cmd::main 13 | 14 | # RUN_OUTPUT 15 | argc__args=([0]="prog" [1]="cmd") 16 | argc__fn=cmd::main 17 | argc__positionals=() 18 | cmd::main 19 | 20 | ************ RUN ************ 21 | prog cmd abc --foo 123 22 | 23 | # OUTPUT 24 | argc_foo=123 25 | argc_val=abc 26 | argc__args=( prog cmd abc --foo 123 ) 27 | argc__fn=cmd::main 28 | argc__positionals=( abc ) 29 | cmd::main abc 30 | 31 | # RUN_OUTPUT 32 | argc__args=([0]="prog" [1]="cmd" [2]="abc" [3]="--foo" [4]="123") 33 | argc__fn=cmd::main 34 | argc__positionals=([0]="abc") 35 | argc_foo=123 36 | argc_val=abc 37 | cmd::main abc 38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/snapshots/integration__main_fn__nested_subcmd_no_main.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/main_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmd 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | USAGE: prog cmd 11 | 12 | COMMANDS: 13 | foo 14 | 15 | EOF 16 | exit 0 17 | 18 | # BUILD_OUTPUT 19 | USAGE: prog cmd 20 | 21 | COMMANDS: 22 | foo 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/snapshots/integration__main_fn__no_main.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/main_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__positionals=( ) 11 | 12 | # BUILD_OUTPUT 13 | argc__args=([0]="prog") 14 | argc__positionals=() 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/snapshots/integration__main_fn__subcmd_main.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/main_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__fn=main 11 | argc__positionals=( ) 12 | main 13 | 14 | # BUILD_OUTPUT 15 | argc__args=([0]="prog") 16 | argc__fn=main 17 | argc__positionals=() 18 | main 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/snapshots/integration__main_fn__subcmd_no_main.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/main_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | USAGE: prog 11 | 12 | COMMANDS: 13 | cmd 14 | 15 | EOF 16 | exit 0 17 | 18 | # BUILD_OUTPUT 19 | USAGE: prog 20 | 21 | COMMANDS: 22 | cmd 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/snapshots/integration__main_fn__with_main.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/main_fn.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__fn=main 11 | argc__positionals=( ) 12 | main 13 | 14 | # BUILD_OUTPUT 15 | argc__args=([0]="prog") 16 | argc__fn=main 17 | argc__positionals=() 18 | main 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/snapshots/integration__main_fn__with_main2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/main_fn.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__fn=main 11 | argc__positionals=( ) 12 | main 13 | 14 | # RUN_OUTPUT 15 | argc__args=([0]="prog") 16 | argc__fn=main 17 | argc__positionals=() 18 | main 19 | 20 | ************ RUN ************ 21 | prog abc --foo 123 22 | 23 | # OUTPUT 24 | argc_foo=123 25 | argc_val=abc 26 | argc__args=( prog abc --foo 123 ) 27 | argc__fn=main 28 | argc__positionals=( abc ) 29 | main abc 30 | 31 | # RUN_OUTPUT 32 | argc__args=([0]="prog" [1]="abc" [2]="--foo" [3]="123") 33 | argc__fn=main 34 | argc__positionals=([0]="abc") 35 | argc_foo=123 36 | argc_val=abc 37 | main abc 38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/snapshots/integration__meta__dotenv.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/meta.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog 7 | 8 | # OUTPUT 9 | _argc_load_dotenv() { 10 | local env_file="$1" env_vars="" 11 | if [[ -f "$env_file" ]]; then 12 | while IFS='=' read -r key value; do 13 | if [[ "$key" == $'#'* ]] || [[ -z "$key" ]]; then 14 | continue 15 | fi 16 | if [[ -z "${!key+x}" ]]; then 17 | env_vars="$env_vars $key=$value" 18 | fi 19 | done < <(cat "$env_file"; echo "") 20 | if [[ -n "$env_vars" ]]; then 21 | eval "export $env_vars" 22 | fi 23 | fi 24 | } 25 | _argc_load_dotenv .env 26 | argc__args=( prog ) 27 | argc__positionals=( ) 28 | 29 | # BUILD_OUTPUT 30 | argc__args=([0]="prog") 31 | argc__positionals=() 32 | -------------------------------------------------------------------------------- /tests/snapshots/integration__meta__dotenv_custom_path.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/meta.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog 7 | 8 | # OUTPUT 9 | _argc_load_dotenv() { 10 | local env_file="$1" env_vars="" 11 | if [[ -f "$env_file" ]]; then 12 | while IFS='=' read -r key value; do 13 | if [[ "$key" == $'#'* ]] || [[ -z "$key" ]]; then 14 | continue 15 | fi 16 | if [[ -z "${!key+x}" ]]; then 17 | env_vars="$env_vars $key=$value" 18 | fi 19 | done < <(cat "$env_file"; echo "") 20 | if [[ -n "$env_vars" ]]; then 21 | eval "export $env_vars" 22 | fi 23 | fi 24 | } 25 | _argc_load_dotenv .env.local 26 | argc__args=( prog ) 27 | argc__positionals=( ) 28 | 29 | # BUILD_OUTPUT 30 | argc__args=([0]="prog") 31 | argc__positionals=() 32 | -------------------------------------------------------------------------------- /tests/snapshots/integration__misc__escape.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/misc.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmd $foo `pwd` $(pwd) ' \1 7 | 世界 8 | 9 | # OUTPUT 10 | argc__args=( prog cmd '$foo' '`pwd`' '$(pwd)' ''\''' '\1' '' ' 11 | ' 世界 ' ' ) 12 | argc__fn=cmd 13 | argc__positionals=( '$foo' '`pwd`' '$(pwd)' ''\''' '\1' '' ' 14 | ' 世界 ' ' ) 15 | cmd '$foo' '`pwd`' '$(pwd)' ''\''' '\1' '' ' 16 | ' 世界 ' ' 17 | 18 | # BUILD_OUTPUT 19 | argc__args=([0]="prog" [1]="cmd" [2]="\$foo" [3]="\`pwd\`" [4]="\$(pwd)" [5]="'" [6]="\\1" [7]="" [8]=$'\n' [9]="世界" [10]=" ") 20 | argc__fn=cmd 21 | argc__positionals=([0]="\$foo" [1]="\`pwd\`" [2]="\$(pwd)" [3]="'" [4]="\\1" [5]="" [6]=$'\n' [7]="世界" [8]=" ") 22 | cmd $foo `pwd` $(pwd) ' \1 23 | 世界 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/snapshots/integration__multiline__nowrap.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/multiline.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog -h 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | prog 1.0.0 11 | nobody 12 | How to use multiline help text 13 | 14 | Extra lines after the comment tag accepts description, which don't start with an `@`, 15 | are treated as the long description. A line which is not a comment ends the block. 16 | 17 | USAGE: prog [OPTIONS] 18 | 19 | ARGS: 20 | [TARGET] 21 | Eager dogs jump over quick, lazy foxes behind brown wooden fences around dark, old houses. Happy children laugh as they run through golden wheat fields under blue, sunny skies. 22 | Use '-' for standard input. 23 | 24 | OPTIONS: 25 | --foo 26 | Sunshine gleams over hills afar, bringing warmth and hope to every soul, yet challenges await as we journey forth, striving for dreams and joy in abundance. Peaceful rivers whisper secrets gently heard. 27 | * default: enables recommended style components. 28 | * full: enables all available components. 29 | * auto: same as 'default', unless the output is piped. 30 | 31 | --bar 32 | Eager dogs jump quickly over the lazy brown fox, swiftly running past green fields, but only until the night turns dark. Bright stars sparkle clearly above us now. 33 | 34 | -h, --help 35 | Print help 36 | 37 | -V, --version 38 | Print version 39 | 40 | COMMANDS: 41 | cmd Eager dogs jump quickly over lazy foxes, creating wonderful chaos amid peaceful fields, but few noticed their swift escape beyond tall fences. Swift breezes sway gently through green. 42 | 43 | EOF 44 | exit 0 45 | 46 | # BUILD_OUTPUT 47 | prog 1.0.0 48 | nobody 49 | How to use multiline help text 50 | 51 | Extra lines after the comment tag accepts description, which don't start with an `@`, 52 | are treated as the long description. A line which is not a comment ends the block. 53 | 54 | USAGE: prog [OPTIONS] 55 | 56 | ARGS: 57 | [TARGET] 58 | Eager dogs jump over quick, lazy foxes behind brown wooden fences around dark, old houses. Happy children laugh as they run through golden wheat fields under blue, sunny skies. 59 | Use '-' for standard input. 60 | 61 | OPTIONS: 62 | --foo 63 | Sunshine gleams over hills afar, bringing warmth and hope to every soul, yet challenges await as we journey forth, striving for dreams and joy in abundance. Peaceful rivers whisper secrets gently heard. 64 | * default: enables recommended style components. 65 | * full: enables all available components. 66 | * auto: same as 'default', unless the output is piped. 67 | 68 | --bar 69 | Eager dogs jump quickly over the lazy brown fox, swiftly running past green fields, but only until the night turns dark. Bright stars sparkle clearly above us now. 70 | 71 | -h, --help 72 | Print help 73 | 74 | -V, --version 75 | Print version 76 | 77 | COMMANDS: 78 | cmd Eager dogs jump quickly over lazy foxes, creating wonderful chaos amid peaceful fields, but few noticed their swift escape beyond tall fences. Swift breezes sway gently through green. 79 | -------------------------------------------------------------------------------- /tests/snapshots/integration__multiline__wrap.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/multiline.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog -h 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | prog 1.0.0 11 | nobody 12 | How to use multiline help text 13 | 14 | Extra lines after the comment tag accepts description, which don't start with 15 | an `@`, 16 | are treated as the long description. A line which is not a comment ends the 17 | block. 18 | 19 | USAGE: prog [OPTIONS] 20 | 21 | ARGS: 22 | [TARGET] 23 | Eager dogs jump over quick, lazy foxes behind brown wooden fences 24 | around dark, old houses. Happy children laugh as they run through 25 | golden wheat fields under blue, sunny skies. 26 | Use '-' for standard input. 27 | 28 | OPTIONS: 29 | --foo 30 | Sunshine gleams over hills afar, bringing warmth and hope to every 31 | soul, yet challenges await as we journey forth, striving for dreams 32 | and joy in abundance. Peaceful rivers whisper secrets gently heard. 33 | * default: enables recommended style components. 34 | * full: enables all available components. 35 | * auto: same as 'default', unless the output is piped. 36 | 37 | --bar 38 | Eager dogs jump quickly over the lazy brown fox, swiftly running 39 | past green fields, but only until the night turns dark. Bright stars 40 | sparkle clearly above us now. 41 | 42 | -h, --help 43 | Print help 44 | 45 | -V, --version 46 | Print version 47 | 48 | COMMANDS: 49 | cmd Eager dogs jump quickly over lazy foxes, creating wonderful chaos amid 50 | peaceful fields, but few noticed their swift escape beyond tall fences. 51 | Swift breezes sway gently through green. 52 | 53 | EOF 54 | exit 0 55 | 56 | # BUILD_OUTPUT 57 | prog 1.0.0 58 | nobody 59 | How to use multiline help text 60 | 61 | Extra lines after the comment tag accepts description, which don't start with an `@`, 62 | are treated as the long description. A line which is not a comment ends the block. 63 | 64 | USAGE: prog [OPTIONS] 65 | 66 | ARGS: 67 | [TARGET] 68 | Eager dogs jump over quick, lazy foxes behind brown wooden fences around dark, old houses. Happy children laugh as they run through golden wheat fields under blue, sunny skies. 69 | Use '-' for standard input. 70 | 71 | OPTIONS: 72 | --foo 73 | Sunshine gleams over hills afar, bringing warmth and hope to every soul, yet challenges await as we journey forth, striving for dreams and joy in abundance. Peaceful rivers whisper secrets gently heard. 74 | * default: enables recommended style components. 75 | * full: enables all available components. 76 | * auto: same as 'default', unless the output is piped. 77 | 78 | --bar 79 | Eager dogs jump quickly over the lazy brown fox, swiftly running past green fields, but only until the night turns dark. Bright stars sparkle clearly above us now. 80 | 81 | -h, --help 82 | Print help 83 | 84 | -V, --version 85 | Print version 86 | 87 | COMMANDS: 88 | cmd Eager dogs jump quickly over lazy foxes, creating wonderful chaos amid peaceful fields, but few noticed their swift escape beyond tall fences. Swift breezes sway gently through green. 89 | -------------------------------------------------------------------------------- /tests/snapshots/integration__multiline__wrap2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/multiline.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog foo -h 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | prog 1.0.0 11 | nobody 12 | How to use multiline help text 13 | 14 | Extra lines after the comment tag accepts description, which don't start with 15 | an `@`, 16 | are treated as the long description. A line which is not a comment ends the 17 | block. 18 | 19 | USAGE: prog [OPTIONS] 20 | 21 | ARGS: 22 | [TARGET] 23 | Eager dogs jump over quick, lazy foxes behind brown wooden fences 24 | around dark, old houses. Happy children laugh as they run through 25 | golden wheat fields under blue, sunny skies. 26 | Use '-' for standard input. 27 | 28 | OPTIONS: 29 | --foo 30 | Sunshine gleams over hills afar, bringing warmth and hope to every 31 | soul, yet challenges await as we journey forth, striving for dreams 32 | and joy in abundance. Peaceful rivers whisper secrets gently heard. 33 | * default: enables recommended style components. 34 | * full: enables all available components. 35 | * auto: same as 'default', unless the output is piped. 36 | 37 | --bar 38 | Eager dogs jump quickly over the lazy brown fox, swiftly running 39 | past green fields, but only until the night turns dark. Bright stars 40 | sparkle clearly above us now. 41 | 42 | -h, --help 43 | Print help 44 | 45 | -V, --version 46 | Print version 47 | 48 | COMMANDS: 49 | cmd Eager dogs jump quickly over lazy foxes, creating wonderful chaos amid 50 | peaceful fields, but few noticed their swift escape beyond tall fences. 51 | Swift breezes sway gently through green. 52 | 53 | EOF 54 | exit 0 55 | 56 | # BUILD_OUTPUT 57 | prog 1.0.0 58 | nobody 59 | How to use multiline help text 60 | 61 | Extra lines after the comment tag accepts description, which don't start with an `@`, 62 | are treated as the long description. A line which is not a comment ends the block. 63 | 64 | USAGE: prog [OPTIONS] 65 | 66 | ARGS: 67 | [TARGET] 68 | Eager dogs jump over quick, lazy foxes behind brown wooden fences around dark, old houses. Happy children laugh as they run through golden wheat fields under blue, sunny skies. 69 | Use '-' for standard input. 70 | 71 | OPTIONS: 72 | --foo 73 | Sunshine gleams over hills afar, bringing warmth and hope to every soul, yet challenges await as we journey forth, striving for dreams and joy in abundance. Peaceful rivers whisper secrets gently heard. 74 | * default: enables recommended style components. 75 | * full: enables all available components. 76 | * auto: same as 'default', unless the output is piped. 77 | 78 | --bar 79 | Eager dogs jump quickly over the lazy brown fox, swiftly running past green fields, but only until the night turns dark. Bright stars sparkle clearly above us now. 80 | 81 | -h, --help 82 | Print help 83 | 84 | -V, --version 85 | Print version 86 | 87 | COMMANDS: 88 | cmd Eager dogs jump quickly over lazy foxes, creating wonderful chaos amid peaceful fields, but few noticed their swift escape beyond tall fences. Swift breezes sway gently through green. 89 | -------------------------------------------------------------------------------- /tests/snapshots/integration__param_fn__case1.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/param_fn.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog ___internal___ _choice_fn 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__cmd_arg_index=0 11 | argc__positionals=( ) 12 | _choice_fn 13 | exit 14 | 15 | # RUN_OUTPUT 16 | error: unsupported ___internal___ command 17 | 18 | ************ RUN ************ 19 | prog ___internal___ _choice_fn prog test1 --cc 20 | 21 | # OUTPUT 22 | argc_cc='' 23 | argc__args=( prog test1 --cc '' ) 24 | argc__cmd_arg_index=1 25 | argc__cmd_fn=test1 26 | argc__option=argc_cc 27 | argc__positionals=( ) 28 | _choice_fn 29 | exit 30 | 31 | # RUN_OUTPUT 32 | error: unsupported ___internal___ command 33 | 34 | ************ RUN ************ 35 | prog ___internal___ _choice_fn prog test1 -a --oa oa --cc 36 | 37 | # OUTPUT 38 | argc_a=1 39 | argc_oa=oa 40 | argc_cc='' 41 | argc__args=( prog test1 -a --oa oa --cc '' ) 42 | argc__cmd_arg_index=1 43 | argc__cmd_fn=test1 44 | argc__option=argc_cc 45 | argc__positionals=( ) 46 | _choice_fn 47 | exit 48 | 49 | # RUN_OUTPUT 50 | error: unsupported ___internal___ command 51 | -------------------------------------------------------------------------------- /tests/snapshots/integration__param_fn__case2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/param_fn.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog ___internal___ _choice_fn 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__cmd_arg_index=0 11 | argc__positionals=( ) 12 | _choice_fn 13 | exit 14 | 15 | # RUN_OUTPUT 16 | error: unsupported ___internal___ command 17 | 18 | ************ RUN ************ 19 | prog ___internal___ _choice_fn prog cmd_multi_arg_with_choice_fn 20 | 21 | # OUTPUT 22 | argc_val=( '' ) 23 | argc__args=( prog cmd_multi_arg_with_choice_fn '' ) 24 | argc__cmd_arg_index=1 25 | argc__cmd_fn=cmd_multi_arg_with_choice_fn 26 | argc__positionals=( '' ) 27 | _choice_fn '' 28 | exit 29 | 30 | # RUN_OUTPUT 31 | error: unsupported ___internal___ command 32 | 33 | ************ RUN ************ 34 | prog ___internal___ _choice_fn prog cmd_multi_arg_with_choice_fn v1 35 | 36 | # OUTPUT 37 | argc_val=( v1 ) 38 | argc__args=( prog cmd_multi_arg_with_choice_fn v1 ) 39 | argc__cmd_arg_index=1 40 | argc__cmd_fn=cmd_multi_arg_with_choice_fn 41 | argc__positionals=( v1 ) 42 | _choice_fn v1 43 | exit 44 | 45 | # RUN_OUTPUT 46 | error: unsupported ___internal___ command 47 | 48 | ************ RUN ************ 49 | prog ___internal___ _choice_fn prog cmd_multi_arg_with_choice_fn v1 50 | 51 | # OUTPUT 52 | argc_val=( v1 '' ) 53 | argc__args=( prog cmd_multi_arg_with_choice_fn v1 '' ) 54 | argc__cmd_arg_index=1 55 | argc__cmd_fn=cmd_multi_arg_with_choice_fn 56 | argc__positionals=( v1 '' ) 57 | _choice_fn v1 '' 58 | exit 59 | 60 | # RUN_OUTPUT 61 | error: unsupported ___internal___ command 62 | 63 | ************ RUN ************ 64 | prog ___internal___ _choice_fn prog cmd_multi_arg_with_choice_fn v1 v2 65 | 66 | # OUTPUT 67 | argc_val=( v1 v2 ) 68 | argc__args=( prog cmd_multi_arg_with_choice_fn v1 v2 ) 69 | argc__cmd_arg_index=1 70 | argc__cmd_fn=cmd_multi_arg_with_choice_fn 71 | argc__positionals=( v1 v2 ) 72 | _choice_fn v1 v2 73 | exit 74 | 75 | # RUN_OUTPUT 76 | error: unsupported ___internal___ command 77 | 78 | ************ RUN ************ 79 | prog ___internal___ _choice_fn prog cmd_multi_arg_with_choice_fn v1 v2 80 | 81 | # OUTPUT 82 | argc_val=( v1 v2 '' ) 83 | argc__args=( prog cmd_multi_arg_with_choice_fn v1 v2 '' ) 84 | argc__cmd_arg_index=1 85 | argc__cmd_fn=cmd_multi_arg_with_choice_fn 86 | argc__positionals=( v1 v2 '' ) 87 | _choice_fn v1 v2 '' 88 | exit 89 | 90 | # RUN_OUTPUT 91 | error: unsupported ___internal___ command 92 | -------------------------------------------------------------------------------- /tests/snapshots/integration__param_fn__case3.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/param_fn.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog ___internal___ _choice_fn 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__cmd_arg_index=0 11 | argc__positionals=( ) 12 | _choice_fn 13 | exit 14 | 15 | # RUN_OUTPUT 16 | error: unsupported ___internal___ command 17 | 18 | ************ RUN ************ 19 | prog ___internal___ _choice_fn prog 20 | 21 | # OUTPUT 22 | argc_v1='' 23 | argc__args=( prog '' ) 24 | argc__cmd_arg_index=0 25 | argc__positionals=( '' ) 26 | _choice_fn '' 27 | exit 28 | 29 | # RUN_OUTPUT 30 | error: unsupported ___internal___ command 31 | 32 | ************ RUN ************ 33 | prog ___internal___ _choice_fn prog v1 34 | 35 | # OUTPUT 36 | argc_v1=v1 37 | argc__args=( prog v1 ) 38 | argc__cmd_arg_index=0 39 | argc__positionals=( v1 ) 40 | _choice_fn v1 41 | exit 42 | 43 | # RUN_OUTPUT 44 | error: unsupported ___internal___ command 45 | 46 | ************ RUN ************ 47 | prog ___internal___ _choice_fn prog v1 48 | 49 | # OUTPUT 50 | argc_v1=v1 51 | argc_v2='' 52 | argc__args=( prog v1 '' ) 53 | argc__cmd_arg_index=0 54 | argc__positionals=( v1 '' ) 55 | _choice_fn v1 '' 56 | exit 57 | 58 | # RUN_OUTPUT 59 | error: unsupported ___internal___ command 60 | 61 | ************ RUN ************ 62 | prog ___internal___ _choice_fn prog v1 v2 63 | 64 | # OUTPUT 65 | argc_v1=v1 66 | argc_v2=v2 67 | argc__args=( prog v1 v2 ) 68 | argc__cmd_arg_index=0 69 | argc__positionals=( v1 v2 ) 70 | _choice_fn v1 v2 71 | exit 72 | 73 | # RUN_OUTPUT 74 | error: unsupported ___internal___ command 75 | 76 | ************ RUN ************ 77 | prog ___internal___ _choice_fn prog v1 v2 78 | 79 | # OUTPUT 80 | argc_v1=v1 81 | argc_v2=v2 82 | argc__args=( prog v1 v2 '' ) 83 | argc__cmd_arg_index=0 84 | argc__positionals=( v1 v2 ) 85 | _choice_fn v1 v2 86 | exit 87 | 88 | # RUN_OUTPUT 89 | error: unsupported ___internal___ command 90 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__arg_no_option.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmd_multi_arg --o1 -o2 -3 7 | 8 | # OUTPUT 9 | argc_val=( --o1 -o2 -3 ) 10 | argc__args=( prog cmd_multi_arg --o1 -o2 -3 ) 11 | argc__fn=cmd_multi_arg 12 | argc__positionals=( --o1 -o2 -3 ) 13 | cmd_multi_arg --o1 -o2 -3 14 | 15 | # BUILD_OUTPUT 16 | argc__args=([0]="prog" [1]="cmd_multi_arg" [2]="--o1" [3]="-o2" [4]="-3") 17 | argc__fn=cmd_multi_arg 18 | argc__positionals=([0]="--o1" [1]="-o2" [2]="-3") 19 | argc_val=([0]="--o1" [1]="-o2" [2]="-3") 20 | cmd_multi_arg --o1 -o2 -3 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__arg_no_param.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog cmd v1 v2 7 | 8 | # OUTPUT 9 | argc__args=( prog cmd v1 v2 ) 10 | argc__fn=cmd 11 | argc__positionals=( v1 v2 ) 12 | cmd v1 v2 13 | 14 | # RUN_OUTPUT 15 | argc__args=([0]="prog" [1]="cmd" [2]="v1" [3]="v2") 16 | argc__fn=cmd 17 | argc__positionals=([0]="v1" [1]="v2") 18 | cmd v1 v2 19 | 20 | ************ RUN ************ 21 | prog cmd --o1 -o2 -3 22 | 23 | # OUTPUT 24 | argc__args=( prog cmd --o1 -o2 -3 ) 25 | argc__fn=cmd 26 | argc__positionals=( --o1 -o2 -3 ) 27 | cmd --o1 -o2 -3 28 | 29 | # RUN_OUTPUT 30 | argc__args=([0]="prog" [1]="cmd" [2]="--o1" [3]="-o2" [4]="-3") 31 | argc__fn=cmd 32 | argc__positionals=([0]="--o1" [1]="-o2" [2]="-3") 33 | cmd --o1 -o2 -3 34 | 35 | 36 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__arg_terminated.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmda -h 7 | 8 | # OUTPUT 9 | argc_args=( -h ) 10 | argc__args=( prog cmda -h ) 11 | argc__fn=cmda 12 | argc__positionals=( -h ) 13 | cmda -h 14 | 15 | # BUILD_OUTPUT 16 | argc__args=([0]="prog" [1]="cmda" [2]="-h") 17 | argc__fn=cmda 18 | argc__positionals=([0]="-h") 19 | argc_args=([0]="-h") 20 | cmda -h 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__arg_two_multi.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog cmd_two_multi_args a b c 7 | 8 | # OUTPUT 9 | argc_val1=( a b ) 10 | argc_val2=( c ) 11 | argc__args=( prog cmd_two_multi_args a b c ) 12 | argc__fn=cmd_two_multi_args 13 | argc__positionals=( a b c ) 14 | cmd_two_multi_args a b c 15 | 16 | # RUN_OUTPUT 17 | argc__args=([0]="prog" [1]="cmd_two_multi_args" [2]="a" [3]="b" [4]="c") 18 | argc__fn=cmd_two_multi_args 19 | argc__positionals=([0]="a" [1]="b" [2]="c") 20 | argc_val1=([0]="a" [1]="b") 21 | argc_val2=([0]="c") 22 | cmd_two_multi_args a b c 23 | 24 | ************ RUN ************ 25 | prog cmd_two_multi_args -- a b c 26 | 27 | # OUTPUT 28 | argc_val1=( a b ) 29 | argc_val2=( c ) 30 | argc__args=( prog cmd_two_multi_args -- a b c ) 31 | argc__fn=cmd_two_multi_args 32 | argc__positionals=( a b c ) 33 | cmd_two_multi_args a b c 34 | 35 | # RUN_OUTPUT 36 | argc__args=([0]="prog" [1]="cmd_two_multi_args" [2]="--" [3]="a" [4]="b" [5]="c") 37 | argc__fn=cmd_two_multi_args 38 | argc__positionals=([0]="a" [1]="b" [2]="c") 39 | argc_val1=([0]="a" [1]="b") 40 | argc_val2=([0]="c") 41 | cmd_two_multi_args a b c 42 | 43 | ************ RUN ************ 44 | prog cmd_two_multi_args a -- b c 45 | 46 | # OUTPUT 47 | argc_val1=( a ) 48 | argc_val2=( b c ) 49 | argc__args=( prog cmd_two_multi_args a -- b c ) 50 | argc__fn=cmd_two_multi_args 51 | argc__positionals=( a b c ) 52 | cmd_two_multi_args a b c 53 | 54 | # RUN_OUTPUT 55 | argc__args=([0]="prog" [1]="cmd_two_multi_args" [2]="a" [3]="--" [4]="b" [5]="c") 56 | argc__fn=cmd_two_multi_args 57 | argc__positionals=([0]="a" [1]="b" [2]="c") 58 | argc_val1=([0]="a") 59 | argc_val2=([0]="b" [1]="c") 60 | cmd_two_multi_args a b c 61 | 62 | ************ RUN ************ 63 | prog cmd_two_multi_args a b -- c 64 | 65 | # OUTPUT 66 | argc_val1=( a b ) 67 | argc_val2=( c ) 68 | argc__args=( prog cmd_two_multi_args a b -- c ) 69 | argc__fn=cmd_two_multi_args 70 | argc__positionals=( a b c ) 71 | cmd_two_multi_args a b c 72 | 73 | # RUN_OUTPUT 74 | argc__args=([0]="prog" [1]="cmd_two_multi_args" [2]="a" [3]="b" [4]="--" [5]="c") 75 | argc__fn=cmd_two_multi_args 76 | argc__positionals=([0]="a" [1]="b" [2]="c") 77 | argc_val1=([0]="a" [1]="b") 78 | argc_val2=([0]="c") 79 | cmd_two_multi_args a b c 80 | 81 | ************ RUN ************ 82 | prog cmd_two_multi_args a b c -- 83 | 84 | # OUTPUT 85 | argc_val1=( a b c ) 86 | argc__args=( prog cmd_two_multi_args a b c -- ) 87 | argc__fn=cmd_two_multi_args 88 | argc__positionals=( a b c ) 89 | cmd_two_multi_args a b c 90 | 91 | # RUN_OUTPUT 92 | argc__args=([0]="prog" [1]="cmd_two_multi_args" [2]="a" [3]="b" [4]="c" [5]="--") 93 | argc__fn=cmd_two_multi_args 94 | argc__positionals=([0]="a" [1]="b" [2]="c") 95 | argc_val1=([0]="a" [1]="b" [2]="c") 96 | cmd_two_multi_args a b c 97 | 98 | 99 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__auto_alias_subcommand.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog -h 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | USAGE: prog 11 | 12 | COMMANDS: 13 | cmd_a [aliases: cmd-a] 14 | _cmdb 15 | 16 | EOF 17 | exit 0 18 | 19 | # RUN_OUTPUT 20 | USAGE: prog 21 | 22 | COMMANDS: 23 | cmd_a [aliases: cmd-a] 24 | _cmdb 25 | 26 | ************ RUN ************ 27 | prog cmd_a 28 | 29 | # OUTPUT 30 | argc__args=( prog cmd_a ) 31 | argc__fn=cmd_a 32 | argc__positionals=( ) 33 | cmd_a 34 | 35 | # RUN_OUTPUT 36 | argc__args=([0]="prog" [1]="cmd_a") 37 | argc__fn=cmd_a 38 | argc__positionals=() 39 | cmd_a 40 | 41 | ************ RUN ************ 42 | prog cmd-a 43 | 44 | # OUTPUT 45 | argc__args=( prog cmd-a ) 46 | argc__fn=cmd_a 47 | argc__positionals=( ) 48 | cmd_a 49 | 50 | # RUN_OUTPUT 51 | argc__args=([0]="prog" [1]="cmd-a") 52 | argc__fn=cmd_a 53 | argc__positionals=() 54 | cmd_a 55 | 56 | ************ RUN ************ 57 | prog _cmdb 58 | 59 | # OUTPUT 60 | argc__args=( prog _cmdb ) 61 | argc__fn=_cmdb 62 | argc__positionals=( ) 63 | _cmdb 64 | 65 | # RUN_OUTPUT 66 | argc__args=([0]="prog" [1]="_cmdb") 67 | argc__fn=_cmdb 68 | argc__positionals=() 69 | _cmdb 70 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__cmd_combine_shorts.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog -A 7 | 8 | # OUTPUT 9 | argc__args=( prog -A ) 10 | argc__fn=-A 11 | argc__positionals=( ) 12 | -A 13 | 14 | # RUN_OUTPUT 15 | argc__args=([0]="prog" [1]="-A") 16 | argc__fn=-A 17 | argc__positionals=() 18 | -A 19 | 20 | ************ RUN ************ 21 | prog -AB 22 | 23 | # OUTPUT 24 | argc_B=1 25 | argc__args=( prog -AB ) 26 | argc__fn=-A 27 | argc__positionals=( ) 28 | -A 29 | 30 | # RUN_OUTPUT 31 | error: `prog` requires a subcommand but one was not provided 32 | [subcommands: -A] 33 | 34 | 35 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__cmd_with_hyphen.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog --foo --fa 7 | 8 | # OUTPUT 9 | argc_fa=1 10 | argc__args=( prog --foo --fa ) 11 | argc__fn=--foo 12 | argc__positionals=( ) 13 | --foo 14 | 15 | # RUN_OUTPUT 16 | argc__args=([0]="prog" [1]="--foo" [2]="--fa") 17 | argc__fn=--foo 18 | argc__positionals=() 19 | argc_fa=1 20 | --foo 21 | 22 | ************ RUN ************ 23 | prog -B --fa 24 | 25 | # OUTPUT 26 | argc_fa=1 27 | argc__args=( prog -B --fa ) 28 | argc__fn=bar 29 | argc__positionals=( ) 30 | bar 31 | 32 | # RUN_OUTPUT 33 | argc__args=([0]="prog" [1]="-B" [2]="--fa") 34 | argc__fn=bar 35 | argc__positionals=() 36 | argc_fa=1 37 | bar 38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__dash_split.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog v1 -f --oa a 7 | 8 | # OUTPUT 9 | argc_f=1 10 | argc_oa=a 11 | argc_v1=v1 12 | argc__args=( prog v1 -f --oa a ) 13 | argc__positionals=( v1 ) 14 | 15 | # RUN_OUTPUT 16 | argc__args=([0]="prog" [1]="v1" [2]="-f" [3]="--oa" [4]="a") 17 | argc__positionals=([0]="v1") 18 | argc_f=1 19 | argc_oa=a 20 | argc_v1=v1 21 | 22 | ************ RUN ************ 23 | prog v1 -f -- --oa a 24 | 25 | # OUTPUT 26 | argc_f=1 27 | argc_v1=v1 28 | argc_v2=( --oa a ) 29 | argc__args=( prog v1 -f -- --oa a ) 30 | argc__positionals=( v1 --oa a ) 31 | 32 | # RUN_OUTPUT 33 | argc__args=([0]="prog" [1]="v1" [2]="-f" [3]="--" [4]="--oa" [5]="a") 34 | argc__positionals=([0]="v1" [1]="--oa" [2]="a") 35 | argc_f=1 36 | argc_v1=v1 37 | argc_v2=([0]="--oa" [1]="a") 38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__default_subcommand.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog -h 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | USAGE: prog 11 | 12 | ARGS: 13 | [VAL] 14 | 15 | OPTIONS: 16 | -h, --help 17 | -V, --version 18 | --fa 19 | 20 | COMMANDS: 21 | cmda [default] 22 | cmdb 23 | 24 | EOF 25 | exit 0 26 | 27 | # RUN_OUTPUT 28 | USAGE: prog 29 | 30 | ARGS: 31 | [VAL] 32 | 33 | OPTIONS: 34 | -h, --help 35 | -V, --version 36 | --fa 37 | 38 | COMMANDS: 39 | cmda [default] 40 | cmdb 41 | 42 | ************ RUN ************ 43 | prog --fa 44 | 45 | # OUTPUT 46 | argc_fa=1 47 | argc__args=( prog --fa ) 48 | argc__fn=cmda 49 | argc__positionals=( ) 50 | cmda 51 | 52 | # RUN_OUTPUT 53 | argc__args=([0]="prog" [1]="--fa") 54 | argc__fn=cmda 55 | argc__positionals=() 56 | argc_fa=1 57 | cmda 58 | 59 | ************ RUN ************ 60 | prog --fa -h 61 | 62 | # OUTPUT 63 | command cat >&2 <<-'EOF' 64 | USAGE: prog cmda [OPTIONS] [VAL] 65 | 66 | ARGS: 67 | [VAL] 68 | 69 | OPTIONS: 70 | --fa 71 | -h, --help 72 | 73 | EOF 74 | exit 0 75 | 76 | # RUN_OUTPUT 77 | USAGE: prog cmda [OPTIONS] [VAL] 78 | 79 | ARGS: 80 | [VAL] 81 | 82 | OPTIONS: 83 | --fa 84 | -h, --help 85 | 86 | ************ RUN ************ 87 | prog v1 88 | 89 | # OUTPUT 90 | argc_val=v1 91 | argc__args=( prog v1 ) 92 | argc__fn=cmda 93 | argc__positionals=( v1 ) 94 | cmda v1 95 | 96 | # RUN_OUTPUT 97 | argc__args=([0]="prog" [1]="v1") 98 | argc__fn=cmda 99 | argc__positionals=([0]="v1") 100 | argc_val=v1 101 | cmda v1 102 | 103 | ************ RUN ************ 104 | prog cmda v1 105 | 106 | # OUTPUT 107 | argc_val=v1 108 | argc__args=( prog cmda v1 ) 109 | argc__fn=cmda 110 | argc__positionals=( v1 ) 111 | cmda v1 112 | 113 | # RUN_OUTPUT 114 | argc__args=([0]="prog" [1]="cmda" [2]="v1") 115 | argc__fn=cmda 116 | argc__positionals=([0]="v1") 117 | argc_val=v1 118 | cmda v1 119 | 120 | ************ RUN ************ 121 | prog cmdb v1 122 | 123 | # OUTPUT 124 | argc__args=( prog cmdb v1 ) 125 | argc__fn=cmdb 126 | argc__positionals=( v1 ) 127 | cmdb v1 128 | 129 | # RUN_OUTPUT 130 | argc__args=([0]="prog" [1]="cmdb" [2]="v1") 131 | argc__fn=cmdb 132 | argc__positionals=([0]="v1") 133 | cmdb v1 134 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__inherit_flag_options.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog cmda --ob a 7 | 8 | # OUTPUT 9 | argc_ob=a 10 | argc__args=( prog cmda --ob a ) 11 | argc__fn=cmda 12 | argc__positionals=( ) 13 | cmda 14 | 15 | # RUN_OUTPUT 16 | argc__args=([0]="prog" [1]="cmda" [2]="--ob" [3]="a") 17 | argc__fn=cmda 18 | argc__positionals=() 19 | argc_ob=a 20 | cmda 21 | 22 | ************ RUN ************ 23 | prog cmdb --ob x 24 | 25 | # OUTPUT 26 | argc_ob=x 27 | argc__args=( prog cmdb --ob x ) 28 | argc__fn=cmdb 29 | argc__positionals=( ) 30 | cmdb 31 | 32 | # RUN_OUTPUT 33 | argc__args=([0]="prog" [1]="cmdb" [2]="--ob" [3]="x") 34 | argc__fn=cmdb 35 | argc__positionals=() 36 | argc_ob=x 37 | cmdb 38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__name_with_special_chars.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog --fa:foo --fa.bar --fa_baz 7 | 8 | # OUTPUT 9 | argc_fa_foo=1 10 | argc_fa_bar=1 11 | argc_fa_baz=1 12 | argc__args=( prog --fa:foo --fa.bar --fa_baz ) 13 | argc__positionals=( ) 14 | 15 | # RUN_OUTPUT 16 | argc__args=([0]="prog" [1]="--fa:foo" [2]="--fa.bar" [3]="--fa_baz") 17 | argc__positionals=() 18 | argc_fa_bar=1 19 | argc_fa_baz=1 20 | argc_fa_foo=1 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__notation_modifier.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog --oa 7 | 8 | # OUTPUT 9 | argc_oa=( ) 10 | argc__args=( prog --oa ) 11 | argc__positionals=( ) 12 | 13 | # RUN_OUTPUT 14 | argc__args=([0]="prog" [1]="--oa") 15 | argc__positionals=() 16 | argc_oa=() 17 | 18 | ************ RUN ************ 19 | prog --oa v1 20 | 21 | # OUTPUT 22 | argc_oa=( v1 ) 23 | argc__args=( prog --oa v1 ) 24 | argc__positionals=( ) 25 | 26 | # RUN_OUTPUT 27 | argc__args=([0]="prog" [1]="--oa" [2]="v1") 28 | argc__positionals=() 29 | argc_oa=([0]="v1") 30 | 31 | ************ RUN ************ 32 | prog --oa v1 v2 33 | 34 | # OUTPUT 35 | argc_oa=( v1 v2 ) 36 | argc__args=( prog --oa v1 v2 ) 37 | argc__positionals=( ) 38 | 39 | # RUN_OUTPUT 40 | argc__args=([0]="prog" [1]="--oa" [2]="v1" [3]="v2") 41 | argc__positionals=() 42 | argc_oa=([0]="v1" [1]="v2") 43 | 44 | ************ RUN ************ 45 | prog --ob 46 | 47 | # OUTPUT 48 | command cat >&2 <<-'EOF' 49 | error: incorrect number of values for `--ob ` 50 | EOF 51 | exit 1 52 | 53 | # RUN_OUTPUT 54 | error: incorrect number of values for `--ob ` 55 | 56 | ************ RUN ************ 57 | prog --ob v1 58 | 59 | # OUTPUT 60 | argc_ob=( v1 ) 61 | argc__args=( prog --ob v1 ) 62 | argc__positionals=( ) 63 | 64 | # RUN_OUTPUT 65 | argc__args=([0]="prog" [1]="--ob" [2]="v1") 66 | argc__positionals=() 67 | argc_ob=([0]="v1") 68 | 69 | ************ RUN ************ 70 | prog --ob v1 v2 71 | 72 | # OUTPUT 73 | argc_ob=( v1 v2 ) 74 | argc__args=( prog --ob v1 v2 ) 75 | argc__positionals=( ) 76 | 77 | # RUN_OUTPUT 78 | argc__args=([0]="prog" [1]="--ob" [2]="v1" [3]="v2") 79 | argc__positionals=() 80 | argc_ob=([0]="v1" [1]="v2") 81 | 82 | ************ RUN ************ 83 | prog --oc 84 | 85 | # OUTPUT 86 | argc_oc='' 87 | argc__args=( prog --oc ) 88 | argc__positionals=( ) 89 | 90 | # RUN_OUTPUT 91 | argc__args=([0]="prog" [1]="--oc") 92 | argc__positionals=() 93 | argc_oc= 94 | 95 | ************ RUN ************ 96 | prog --oc v1 97 | 98 | # OUTPUT 99 | argc_oc=v1 100 | argc__args=( prog --oc v1 ) 101 | argc__positionals=( ) 102 | 103 | # RUN_OUTPUT 104 | argc__args=([0]="prog" [1]="--oc" [2]="v1") 105 | argc__positionals=() 106 | argc_oc=v1 107 | 108 | ************ RUN ************ 109 | prog --oc v1 v2 110 | 111 | # OUTPUT 112 | argc_oc=v1 113 | argc__args=( prog --oc v1 v2 ) 114 | argc__positionals=( v2 ) 115 | 116 | # RUN_OUTPUT 117 | argc__args=([0]="prog" [1]="--oc" [2]="v1" [3]="v2") 118 | argc__positionals=([0]="v2") 119 | argc_oc=v1 120 | 121 | 122 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__option_assigned.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog --oa=v1 --ob=1 --ob=2 7 | 8 | # OUTPUT 9 | argc_oa=v1 10 | argc_ob=( 1 2 ) 11 | argc__args=( prog '--oa=v1' '--ob=1' '--ob=2' ) 12 | argc__positionals=( ) 13 | 14 | # RUN_OUTPUT 15 | argc__args=([0]="prog" [1]="--oa=v1" [2]="--ob=1" [3]="--ob=2") 16 | argc__positionals=() 17 | argc_oa=v1 18 | argc_ob=([0]="1" [1]="2") 19 | 20 | ************ RUN ************ 21 | prog --oa v1 22 | 23 | # OUTPUT 24 | command cat >&2 <<-'EOF' 25 | error: incorrect number of values for `--oa=` 26 | EOF 27 | exit 1 28 | 29 | # RUN_OUTPUT 30 | error: incorrect number of values for `--oa=` 31 | 32 | ************ RUN ************ 33 | prog --oc v1 34 | 35 | # OUTPUT 36 | argc_oc='' 37 | argc__args=( prog --oc v1 ) 38 | argc__positionals=( v1 ) 39 | 40 | # RUN_OUTPUT 41 | argc__args=([0]="prog" [1]="--oc" [2]="v1") 42 | argc__positionals=([0]="v1") 43 | argc_oc= 44 | 45 | ************ RUN ************ 46 | prog --o: v1 47 | 48 | # OUTPUT 49 | argc_o_=v1 50 | argc__args=( prog --o: v1 ) 51 | argc__positionals=( ) 52 | 53 | # RUN_OUTPUT 54 | argc__args=([0]="prog" [1]="--o:" [2]="v1") 55 | argc__positionals=() 56 | argc_o_=v1 57 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__option_multiple.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog -h 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | USAGE: prog [OPTIONS] 11 | 12 | OPTIONS: 13 | -f, --fc... 14 | -a, --oa [DIR]... 15 | -b, --ob 16 | -c, --oc 17 | -d, --od 18 | -e, --oe [DIR+]... 19 | -h, --help 20 | -V, --version 21 | 22 | EOF 23 | exit 0 24 | 25 | # RUN_OUTPUT 26 | USAGE: prog [OPTIONS] 27 | 28 | OPTIONS: 29 | -f, --fc... 30 | -a, --oa [DIR]... 31 | -b, --ob 32 | -c, --oc 33 | -d, --od 34 | -e, --oe [DIR+]... 35 | -h, --help 36 | -V, --version 37 | 38 | ************ RUN ************ 39 | prog -f -f 40 | 41 | # OUTPUT 42 | argc_fc=2 43 | argc__args=( prog -f -f ) 44 | argc__positionals=( ) 45 | 46 | # RUN_OUTPUT 47 | argc__args=([0]="prog" [1]="-f" [2]="-f") 48 | argc__positionals=() 49 | argc_fc=2 50 | 51 | ************ RUN ************ 52 | prog -a dir1 dir2 53 | 54 | # OUTPUT 55 | argc_oa=( dir1 ) 56 | argc__args=( prog -a dir1 dir2 ) 57 | argc__positionals=( dir2 ) 58 | 59 | # RUN_OUTPUT 60 | argc__args=([0]="prog" [1]="-a" [2]="dir1" [3]="dir2") 61 | argc__positionals=([0]="dir2") 62 | argc_oa=([0]="dir1") 63 | 64 | ************ RUN ************ 65 | prog -a dir1 -a dir2 66 | 67 | # OUTPUT 68 | argc_oa=( dir1 dir2 ) 69 | argc__args=( prog -a dir1 -a dir2 ) 70 | argc__positionals=( ) 71 | 72 | # RUN_OUTPUT 73 | argc__args=([0]="prog" [1]="-a" [2]="dir1" [3]="-a" [4]="dir2") 74 | argc__positionals=() 75 | argc_oa=([0]="dir1" [1]="dir2") 76 | 77 | ************ RUN ************ 78 | prog -b vim dir1 dir2 79 | 80 | # OUTPUT 81 | argc_ob=( vim dir1 dir2 ) 82 | argc__args=( prog -b vim dir1 dir2 ) 83 | argc__positionals=( ) 84 | 85 | # RUN_OUTPUT 86 | argc__args=([0]="prog" [1]="-b" [2]="vim" [3]="dir1" [4]="dir2") 87 | argc__positionals=() 88 | argc_ob=([0]="vim" [1]="dir1" [2]="dir2") 89 | 90 | ************ RUN ************ 91 | prog -c dir1 dir2 92 | 93 | # OUTPUT 94 | argc_oc=( dir1 dir2 ) 95 | argc__args=( prog -c dir1 dir2 ) 96 | argc__positionals=( ) 97 | 98 | # RUN_OUTPUT 99 | argc__args=([0]="prog" [1]="-c" [2]="dir1" [3]="dir2") 100 | argc__positionals=() 101 | argc_oc=([0]="dir1" [1]="dir2") 102 | 103 | ************ RUN ************ 104 | prog -d dir1 file1 file2 105 | 106 | # OUTPUT 107 | argc_od=( dir1 file1 ) 108 | argc__args=( prog -d dir1 file1 file2 ) 109 | argc__positionals=( file2 ) 110 | 111 | # RUN_OUTPUT 112 | argc__args=([0]="prog" [1]="-d" [2]="dir1" [3]="file1" [4]="file2") 113 | argc__positionals=([0]="file2") 114 | argc_od=([0]="dir1" [1]="file1") 115 | 116 | ************ RUN ************ 117 | prog -e dir1 -e dir2 dir3 118 | 119 | # OUTPUT 120 | argc_oe=( dir1 dir2 dir3 ) 121 | argc__args=( prog -e dir1 -e dir2 dir3 ) 122 | argc__positionals=( ) 123 | 124 | # RUN_OUTPUT 125 | argc__args=([0]="prog" [1]="-e" [2]="dir1" [3]="-e" [4]="dir2" [5]="dir3") 126 | argc__positionals=() 127 | argc_oe=([0]="dir1" [1]="dir2" [2]="dir3") 128 | 129 | 130 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__option_prefixed.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog -o1 -Dv1=foo -Dv2 bar 7 | 8 | # OUTPUT 9 | declare -A argc_o 10 | argc_o["1"]=1 11 | declare -A argc_D 12 | argc_D["v1"]=foo 13 | argc_D["v2"]=bar 14 | argc__args=( prog -o1 '-Dv1=foo' -Dv2 bar ) 15 | argc__positionals=( ) 16 | 17 | # RUN_OUTPUT 18 | error: unexpected argument `-o1` found 19 | 20 | ************ RUN ************ 21 | prog -v- 22 | 23 | # OUTPUT 24 | argc_v_=1 25 | argc__args=( prog -v- ) 26 | argc__positionals=( ) 27 | 28 | # RUN_OUTPUT 29 | argc__args=([0]="prog" [1]="-v-") 30 | argc__positionals=() 31 | argc_v_=1 32 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__option_shorts.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog test1 -af 7 | 8 | # OUTPUT 9 | argc_a=1 10 | argc_fb=1 11 | argc__args=( prog test1 -af ) 12 | argc__fn=test1 13 | argc__positionals=( ) 14 | test1 15 | 16 | # RUN_OUTPUT 17 | error: unexpected argument `-af` found 18 | 19 | ************ RUN ************ 20 | prog test1 -ae e 21 | 22 | # OUTPUT 23 | argc_a=1 24 | argc_e=e 25 | argc__args=( prog test1 -ae e ) 26 | argc__fn=test1 27 | argc__positionals=( ) 28 | test1 29 | 30 | # RUN_OUTPUT 31 | error: unexpected argument `-ae` found 32 | 33 | ************ RUN ************ 34 | prog test1 -afe e 35 | 36 | # OUTPUT 37 | argc_a=1 38 | argc_fb=1 39 | argc_e=e 40 | argc__args=( prog test1 -afe e ) 41 | argc__fn=test1 42 | argc__positionals=( ) 43 | test1 44 | 45 | # RUN_OUTPUT 46 | error: unexpected argument `-afe` found 47 | 48 | ************ RUN ************ 49 | prog test1 -ao v1 v2 50 | 51 | # OUTPUT 52 | argc_a=1 53 | argc_od=( v1 v2 ) 54 | argc__args=( prog test1 -ao v1 v2 ) 55 | argc__fn=test1 56 | argc__positionals=( ) 57 | test1 58 | 59 | # RUN_OUTPUT 60 | error: unexpected argument `-ao` found 61 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__option_single_dash.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog --oa - 7 | 8 | # OUTPUT 9 | argc_oa=- 10 | argc__args=( prog --oa - ) 11 | argc__positionals=( ) 12 | 13 | # RUN_OUTPUT 14 | argc__args=([0]="prog" [1]="--oa" [2]="-") 15 | argc__positionals=() 16 | argc_oa=- 17 | 18 | ************ RUN ************ 19 | prog --oa - 20 | 21 | # OUTPUT 22 | argc_oa=- 23 | argc__args=( prog --oa - '' ) 24 | argc__positionals=( '' ) 25 | 26 | # RUN_OUTPUT 27 | argc__args=([0]="prog" [1]="--oa" [2]="-" [3]="") 28 | argc__positionals=([0]="") 29 | argc_oa=- 30 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__option_terminated.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog --oa bash Argcfile.sh --ob 7 | 8 | # OUTPUT 9 | argc_oa=( bash Argcfile.sh --ob ) 10 | argc__args=( prog --oa bash Argcfile.sh --ob ) 11 | argc__positionals=( ) 12 | 13 | # BUILD_OUTPUT 14 | argc__args=([0]="prog" [1]="--oa" [2]="bash" [3]="Argcfile.sh" [4]="--ob") 15 | argc__positionals=() 16 | argc_oa=([0]="bash" [1]="Argcfile.sh" [2]="--ob") 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__option_to_variable.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog --flag-foo --option-foo foo1 --option-foo foo2 --option-bar bar v1 x1 x2 7 | 8 | # OUTPUT 9 | argc_flag_foo=1 10 | argc_option_foo=( foo1 foo2 ) 11 | argc_option_bar=bar 12 | argc_arg_foo=v1 13 | argc_arg_bar=( x1 x2 ) 14 | argc__args=( prog --flag-foo --option-foo foo1 --option-foo foo2 --option-bar bar v1 x1 x2 ) 15 | argc__positionals=( v1 x1 x2 ) 16 | 17 | # BUILD_OUTPUT 18 | argc__args=([0]="prog" [1]="--flag-foo" [2]="--option-foo" [3]="foo1" [4]="--option-foo" [5]="foo2" [6]="--option-bar" [7]="bar" [8]="v1" [9]="x1" [10]="x2") 19 | argc__positionals=([0]="v1" [1]="x1" [2]="x2") 20 | argc_arg_bar=([0]="x1" [1]="x2") 21 | argc_arg_foo=v1 22 | argc_flag_foo=1 23 | argc_option_bar=bar 24 | argc_option_foo=([0]="foo1" [1]="foo2") 25 | 26 | 27 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__option_value_dash.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog --oa --- 7 | 8 | # OUTPUT 9 | argc_oa=--- 10 | argc__args=( prog --oa --- ) 11 | argc__positionals=( ) 12 | 13 | # RUN_OUTPUT 14 | argc__args=([0]="prog" [1]="--oa" [2]="---") 15 | argc__positionals=() 16 | argc_oa=--- 17 | 18 | ************ RUN ************ 19 | prog --- 20 | 21 | # OUTPUT 22 | argc__args=( prog --- ) 23 | argc__positionals=( --- ) 24 | 25 | # RUN_OUTPUT 26 | argc__args=([0]="prog" [1]="---") 27 | argc__positionals=([0]="---") 28 | 29 | ************ RUN ************ 30 | prog --a b 31 | 32 | # OUTPUT 33 | argc__args=( prog '--a b' ) 34 | argc__positionals=( '--a b' ) 35 | 36 | # RUN_OUTPUT 37 | argc__args=([0]="prog" [1]="--a b") 38 | argc__positionals=([0]="--a b") 39 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__plus_sign.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog +a +fb fb +c fc1 +fc fc2 7 | 8 | # OUTPUT 9 | argc_plus_a=1 10 | argc_plus_fb=fb 11 | argc_plus_fc=( fc1 fc2 ) 12 | argc__args=( prog +a +fb fb +c fc1 +fc fc2 ) 13 | argc__positionals=( ) 14 | 15 | # RUN_OUTPUT 16 | argc__args=([0]="prog" [1]="+a" [2]="+fb" [3]="fb" [4]="+c" [5]="fc1" [6]="+fc" [7]="fc2") 17 | argc__positionals=() 18 | argc_plus_a=1 19 | argc_plus_fb=fb 20 | argc_plus_fc=([0]="fc1" [1]="fc2") 21 | 22 | ************ RUN ************ 23 | prog +d fd1 -fd fd2 24 | 25 | # OUTPUT 26 | argc_fd=( fd1 fd2 ) 27 | argc__args=( prog +d fd1 -fd fd2 ) 28 | argc__positionals=( ) 29 | 30 | # RUN_OUTPUT 31 | argc__args=([0]="prog" [1]="+d" [2]="fd1" [3]="-fd" [4]="fd2") 32 | argc__positionals=() 33 | argc_fd=([0]="fd1" [1]="fd2") 34 | 35 | 36 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__same_option_positional.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog -h 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | USAGE: prog [OPTIONS] [URL] 11 | 12 | ARGS: 13 | [URL] 14 | 15 | OPTIONS: 16 | --url 17 | -h, --help 18 | -V, --version 19 | 20 | EOF 21 | exit 0 22 | 23 | # BUILD_OUTPUT 24 | USAGE: prog [OPTIONS] [URL] 25 | 26 | ARGS: 27 | [URL] 28 | 29 | OPTIONS: 30 | --url 31 | -h, --help 32 | -V, --version 33 | 34 | 35 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__symbol.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog +nightly 7 | 8 | # OUTPUT 9 | argc_toolchain=nightly 10 | argc__args=( prog +nightly ) 11 | argc__positionals=( ) 12 | 13 | # RUN_OUTPUT 14 | argc__args=([0]="prog" [1]="+nightly") 15 | argc__positionals=([0]="+nightly") 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/snapshots/integration__spec__undefine_positionals.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/spec.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog --oa v1 v2 7 | 8 | # OUTPUT 9 | argc_oa=v1 10 | argc__args=( prog --oa v1 v2 ) 11 | argc__positionals=( v2 ) 12 | 13 | # BUILD_OUTPUT 14 | argc__args=([0]="prog" [1]="--oa" [2]="v1" [3]="v2") 15 | argc__positionals=([0]="v2") 16 | argc_oa=v1 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__arg_choice.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmd_arg_with_choices val 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: invalid value `val` for `[VAL]` 11 | [possible values: x, y, z] 12 | EOF 13 | exit 1 14 | 15 | # BUILD_OUTPUT 16 | error: invalid value `val` for `[VAL]` 17 | [possible values: x, y, z] 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__arg_choice_fn.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmd_arg_with_choice_fn val 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: invalid value `val` for `[VAL]` 11 | [possible values: abc, def, ghi] 12 | EOF 13 | exit 1 14 | 15 | # BUILD_OUTPUT 16 | error: invalid value `val` for `[VAL]` 17 | [possible values: abc, def, ghi] 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__arg_choice_fn_pass.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmd_arg_with_choice_fn val 7 | 8 | # OUTPUT 9 | argc_val=val 10 | argc__args=( prog cmd_arg_with_choice_fn val ) 11 | argc__fn=cmd_arg_with_choice_fn 12 | argc__positionals=( val ) 13 | cmd_arg_with_choice_fn val 14 | 15 | # BUILD_OUTPUT 16 | error: invalid value `val` for `[VAL]` 17 | [possible values: abc, def, ghi] 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__arg_choice_fn_skip.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmd_arg_with_choice_fn_and_skip_check abc 7 | 8 | # OUTPUT 9 | argc_val=abc 10 | argc__args=( prog cmd_arg_with_choice_fn_and_skip_check abc ) 11 | argc__fn=cmd_arg_with_choice_fn_and_skip_check 12 | argc__positionals=( abc ) 13 | cmd_arg_with_choice_fn_and_skip_check abc 14 | 15 | # BUILD_OUTPUT 16 | argc__args=([0]="prog" [1]="cmd_arg_with_choice_fn_and_skip_check" [2]="abc") 17 | argc__fn=cmd_arg_with_choice_fn_and_skip_check 18 | argc__positionals=([0]="abc") 19 | argc_val=abc 20 | cmd_arg_with_choice_fn_and_skip_check abc 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__arg_choice_multi.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmd_multi_arg_with_choice_fn abc val 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: invalid value `val` for `[VAL]...` 11 | [possible values: abc, def, ghi] 12 | EOF 13 | exit 1 14 | 15 | # BUILD_OUTPUT 16 | error: invalid value `val` for `[VAL]...` 17 | [possible values: abc, def, ghi] 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__arg_help_subcmd.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog help cmd_required_multi_arg 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | USAGE: prog cmd_required_multi_arg ... 11 | 12 | ARGS: 13 | ... 14 | 15 | EOF 16 | exit 0 17 | 18 | # BUILD_OUTPUT 19 | USAGE: prog cmd_required_multi_arg ... 20 | 21 | ARGS: 22 | ... 23 | 24 | 25 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__arg_invalid_subcmd.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog foo 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: `prog` requires a subcommand but 'foo' is not one of them 11 | [subcommands: cmda, cmdb] 12 | EOF 13 | exit 1 14 | 15 | # BUILD_OUTPUT 16 | error: `prog` requires a subcommand but one was not provided 17 | [subcommands: cmda, cmdb] 18 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__arg_missing.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmd_required_multi_arg 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: the following required arguments were not provided: 11 | ... 12 | EOF 13 | exit 1 14 | 15 | # BUILD_OUTPUT 16 | error: the required environments `...` were not provided 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__arg_unknown.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog cmd_arg v1 v2 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: unexpected argument `v2` found 11 | EOF 12 | exit 1 13 | 14 | # BUILD_OUTPUT 15 | error: unexpected argument `v2` found 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__choice_access_vars.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog --fa foo 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: invalid value `foo` for `[VAL]` 11 | [possible values: abc] 12 | EOF 13 | exit 1 14 | 15 | # RUN_OUTPUT 16 | error: invalid value `foo` for `[VAL]` 17 | [possible values: abc] 18 | 19 | ************ RUN ************ 20 | prog foo 21 | 22 | # OUTPUT 23 | command cat >&2 <<-'EOF' 24 | error: invalid value `foo` for `[VAL]` 25 | [possible values: def] 26 | EOF 27 | exit 1 28 | 29 | # RUN_OUTPUT 30 | error: invalid value `foo` for `[VAL]` 31 | [possible values: def] 32 | 33 | 34 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__choice_slash.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog cmd a\b a\b 7 | 8 | # OUTPUT 9 | argc_foo='a\b' 10 | argc_bar='a\b' 11 | argc__args=( prog cmd 'a\b' 'a\b' ) 12 | argc__fn=cmd 13 | argc__positionals=( 'a\b' 'a\b' ) 14 | cmd 'a\b' 'a\b' 15 | 16 | # RUN_OUTPUT 17 | error: invalid value `a\b` for `[BAR]` 18 | [possible values: ] 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__cmd_name_sanitize.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog --help 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | USAGE: prog 11 | 12 | COMMANDS: 13 | cat 14 | do 15 | 16 | EOF 17 | exit 0 18 | 19 | # RUN_OUTPUT 20 | USAGE: prog 21 | 22 | COMMANDS: 23 | cat 24 | do 25 | 26 | ************ RUN ************ 27 | prog cat --help 28 | 29 | # OUTPUT 30 | command cat >&2 <<-'EOF' 31 | USAGE: prog cat 32 | 33 | EOF 34 | exit 0 35 | 36 | # RUN_OUTPUT 37 | USAGE: prog cat 38 | 39 | ************ RUN ************ 40 | prog cat 41 | 42 | # OUTPUT 43 | argc__args=( prog cat ) 44 | argc__fn=cat_ 45 | argc__positionals=( ) 46 | cat_ 47 | 48 | # RUN_OUTPUT 49 | argc__args=([0]="prog" [1]="cat") 50 | argc__fn=cat_ 51 | argc__positionals=() 52 | cat_ 53 | 54 | ************ RUN ************ 55 | prog do --help 56 | 57 | # OUTPUT 58 | command cat >&2 <<-'EOF' 59 | USAGE: prog do 60 | 61 | COMMANDS: 62 | foo 63 | bar 64 | 65 | EOF 66 | exit 0 67 | 68 | # RUN_OUTPUT 69 | USAGE: prog do 70 | 71 | COMMANDS: 72 | foo 73 | bar 74 | 75 | ************ RUN ************ 76 | prog do 77 | 78 | # OUTPUT 79 | command cat >&2 <<-'EOF' 80 | USAGE: prog do 81 | 82 | COMMANDS: 83 | foo 84 | bar 85 | 86 | EOF 87 | exit 0 88 | 89 | # RUN_OUTPUT 90 | USAGE: prog do 91 | 92 | COMMANDS: 93 | foo 94 | bar 95 | 96 | ************ RUN ************ 97 | prog do foo 98 | 99 | # OUTPUT 100 | argc__args=( prog do foo ) 101 | argc__fn=do_::foo 102 | argc__positionals=( ) 103 | do_::foo 104 | 105 | # RUN_OUTPUT 106 | argc__args=([0]="prog" [1]="do" [2]="foo") 107 | argc__fn=do_::foo 108 | argc__positionals=() 109 | do_::foo 110 | 111 | 112 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__delimiter.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog cmd --oa abc,def 7 | 8 | # OUTPUT 9 | argc_oa=( abc def ) 10 | argc__args=( prog cmd --oa abc,def ) 11 | argc__fn=cmd 12 | argc__positionals=( ) 13 | cmd 14 | 15 | # RUN_OUTPUT 16 | argc__args=([0]="prog" [1]="cmd" [2]="--oa" [3]="abc,def") 17 | argc__fn=cmd 18 | argc__positionals=() 19 | argc_oa=([0]="abc" [1]="def") 20 | cmd 21 | 22 | ************ RUN ************ 23 | prog cmd abc,def 24 | 25 | # OUTPUT 26 | argc_val=( abc def ) 27 | argc__args=( prog cmd abc,def ) 28 | argc__fn=cmd 29 | argc__positionals=( abc def ) 30 | cmd abc def 31 | 32 | # RUN_OUTPUT 33 | argc__args=([0]="prog" [1]="cmd" [2]="abc,def") 34 | argc__fn=cmd 35 | argc__positionals=([0]="abc" [1]="def") 36 | argc_val=([0]="abc" [1]="def") 37 | cmd abc def 38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__empty_choices.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog --oa foo 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: invalid value `foo` for `` 11 | [possible values: ] 12 | EOF 13 | exit 1 14 | 15 | # RUN_OUTPUT 16 | error: invalid value `foo` for `` 17 | [possible values: ] 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__escape_at_symbol.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog -h 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | Patch utils 11 | 12 | Here is an example of a patch block: 13 | --- a/hello.py 14 | +++ b/hello.py 15 | @@ ... @@ 16 | def hello(): 17 | - print("Hello World") 18 | + name = input("What is your name? ") 19 | + print(f"Hello {name}") 20 | 21 | USAGE: prog 22 | 23 | EOF 24 | exit 0 25 | 26 | # RUN_OUTPUT 27 | Patch utils 28 | 29 | Here is an example of a patch block: 30 | --- a/hello.py 31 | +++ b/hello.py 32 | @@ ... @@ 33 | def hello(): 34 | - print("Hello World") 35 | + name = input("What is your name? ") 36 | + print(f"Hello {name}") 37 | 38 | USAGE: prog 39 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__flag_not_multiple.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog test1 -a -a 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: the argument `-a` cannot be used multiple times 11 | EOF 12 | exit 1 13 | 14 | # BUILD_OUTPUT 15 | error: the argument `-a` cannot be used multiple times 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__flag_with_value.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog test1 -a=3 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: flag `-a` don't accept any value 11 | EOF 12 | exit 1 13 | 14 | # BUILD_OUTPUT 15 | error: flag `-a` don't accept any value 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__help_notations.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog -h 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | USAGE: prog [OPTIONS] 11 | 12 | OPTIONS: 13 | -target -- see the targets command 14 | -n volumes for input, '0' to prompt interactively 15 | --merge Perform a three-way merge by providing paths for two modified versions of a file, the common origin of both modified versions and the output file to save merge results. 16 | -h, -help Print help 17 | -V, -version Print version 18 | 19 | EOF 20 | exit 0 21 | 22 | # RUN_OUTPUT 23 | USAGE: prog [OPTIONS] 24 | 25 | OPTIONS: 26 | -target -- see the targets command 27 | -n volumes for input, '0' to prompt interactively 28 | --merge Perform a three-way merge by providing paths for two modified versions of a file, the common origin of both modified versions and the output file to save merge results. 29 | -h, -help Print help 30 | -V, -version Print version 31 | 32 | 33 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__help_version.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog help 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | prog 1.0.0 11 | nobody 12 | Test argc 13 | 14 | USAGE: prog 15 | 16 | EOF 17 | exit 0 18 | 19 | # RUN_OUTPUT 20 | prog 1.0.0 21 | nobody 22 | Test argc 23 | 24 | USAGE: prog 25 | 26 | ************ RUN ************ 27 | prog --help 28 | 29 | # OUTPUT 30 | command cat >&2 <<-'EOF' 31 | prog 1.0.0 32 | nobody 33 | Test argc 34 | 35 | USAGE: prog 36 | 37 | EOF 38 | exit 0 39 | 40 | # RUN_OUTPUT 41 | prog 1.0.0 42 | nobody 43 | Test argc 44 | 45 | USAGE: prog 46 | 47 | ************ RUN ************ 48 | prog -help 49 | 50 | # OUTPUT 51 | command cat >&2 <<-'EOF' 52 | prog 1.0.0 53 | nobody 54 | Test argc 55 | 56 | USAGE: prog 57 | 58 | EOF 59 | exit 0 60 | 61 | # RUN_OUTPUT 62 | prog 1.0.0 63 | nobody 64 | Test argc 65 | 66 | USAGE: prog 67 | 68 | ************ RUN ************ 69 | prog -h 70 | 71 | # OUTPUT 72 | command cat >&2 <<-'EOF' 73 | prog 1.0.0 74 | nobody 75 | Test argc 76 | 77 | USAGE: prog 78 | 79 | EOF 80 | exit 0 81 | 82 | # RUN_OUTPUT 83 | prog 1.0.0 84 | nobody 85 | Test argc 86 | 87 | USAGE: prog 88 | 89 | ************ RUN ************ 90 | prog --version 91 | 92 | # OUTPUT 93 | command cat >&2 <<-'EOF' 94 | prog 1.0.0 95 | EOF 96 | exit 0 97 | 98 | # RUN_OUTPUT 99 | prog 1.0.0 100 | 101 | ************ RUN ************ 102 | prog -version 103 | 104 | # OUTPUT 105 | command cat >&2 <<-'EOF' 106 | prog 1.0.0 107 | EOF 108 | exit 0 109 | 110 | # RUN_OUTPUT 111 | prog 1.0.0 112 | 113 | ************ RUN ************ 114 | prog -V 115 | 116 | # OUTPUT 117 | command cat >&2 <<-'EOF' 118 | prog 1.0.0 119 | EOF 120 | exit 0 121 | 122 | # RUN_OUTPUT 123 | prog 1.0.0 124 | 125 | 126 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__help_version_exist.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog -h 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | prog 1.0.0 11 | Test argc 12 | 13 | USAGE: prog [OPTIONS] 14 | 15 | OPTIONS: 16 | -h, --help 17 | -V, --version 18 | 19 | EOF 20 | exit 0 21 | 22 | # RUN_OUTPUT 23 | prog 1.0.0 24 | Test argc 25 | 26 | USAGE: prog [OPTIONS] 27 | 28 | OPTIONS: 29 | -h, --help 30 | -V, --version 31 | 32 | ************ RUN ************ 33 | prog -V 34 | 35 | # OUTPUT 36 | command cat >&2 <<-'EOF' 37 | prog 1.0.0 38 | EOF 39 | exit 0 40 | 41 | # RUN_OUTPUT 42 | prog 1.0.0 43 | 44 | 45 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__help_version_legacy.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog help 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | prog 1.0.0 11 | nobody 12 | Test argc 13 | 14 | USAGE: prog 15 | 16 | EOF 17 | exit 0 18 | 19 | # RUN_OUTPUT 20 | prog 1.0.0 21 | nobody 22 | Test argc 23 | 24 | USAGE: prog 25 | 26 | ************ RUN ************ 27 | prog --help 28 | 29 | # OUTPUT 30 | command cat >&2 <<-'EOF' 31 | prog 1.0.0 32 | nobody 33 | Test argc 34 | 35 | USAGE: prog 36 | 37 | EOF 38 | exit 0 39 | 40 | # RUN_OUTPUT 41 | prog 1.0.0 42 | nobody 43 | Test argc 44 | 45 | USAGE: prog 46 | 47 | ************ RUN ************ 48 | prog -help 49 | 50 | # OUTPUT 51 | command cat >&2 <<-'EOF' 52 | prog 1.0.0 53 | nobody 54 | Test argc 55 | 56 | USAGE: prog 57 | 58 | EOF 59 | exit 0 60 | 61 | # RUN_OUTPUT 62 | prog 1.0.0 63 | nobody 64 | Test argc 65 | 66 | USAGE: prog 67 | 68 | ************ RUN ************ 69 | prog -h 70 | 71 | # OUTPUT 72 | command cat >&2 <<-'EOF' 73 | prog 1.0.0 74 | nobody 75 | Test argc 76 | 77 | USAGE: prog 78 | 79 | EOF 80 | exit 0 81 | 82 | # RUN_OUTPUT 83 | prog 1.0.0 84 | nobody 85 | Test argc 86 | 87 | USAGE: prog 88 | 89 | ************ RUN ************ 90 | prog --version 91 | 92 | # OUTPUT 93 | command cat >&2 <<-'EOF' 94 | prog 1.0.0 95 | EOF 96 | exit 0 97 | 98 | # RUN_OUTPUT 99 | prog 1.0.0 100 | 101 | ************ RUN ************ 102 | prog -version 103 | 104 | # OUTPUT 105 | command cat >&2 <<-'EOF' 106 | prog 1.0.0 107 | EOF 108 | exit 0 109 | 110 | # RUN_OUTPUT 111 | prog 1.0.0 112 | 113 | ************ RUN ************ 114 | prog -V 115 | 116 | # OUTPUT 117 | command cat >&2 <<-'EOF' 118 | prog 1.0.0 119 | EOF 120 | exit 0 121 | 122 | # RUN_OUTPUT 123 | prog 1.0.0 124 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__help_version_shadow.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog -h 7 | 8 | # OUTPUT 9 | argc_host=1 10 | argc__args=( prog -h ) 11 | argc__positionals=( ) 12 | 13 | # RUN_OUTPUT 14 | argc__args=([0]="prog" [1]="-h") 15 | argc__positionals=() 16 | argc_host=1 17 | 18 | ************ RUN ************ 19 | prog -V 20 | 21 | # OUTPUT 22 | argc_verify=1 23 | argc__args=( prog -V ) 24 | argc__positionals=( ) 25 | 26 | # RUN_OUTPUT 27 | argc__args=([0]="prog" [1]="-V") 28 | argc__positionals=() 29 | argc_verify=1 30 | 31 | 32 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__option_choice.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog test1 --ca val 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: invalid value `val` for `` 11 | [possible values: x, y, z] 12 | EOF 13 | exit 1 14 | 15 | # BUILD_OUTPUT 16 | error: invalid value `val` for `` 17 | [possible values: x, y, z] 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__option_choice_fn.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog test1 --cc val 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: invalid value `val` for `` 11 | [possible values: abc, def, ghi] 12 | EOF 13 | exit 1 14 | 15 | # BUILD_OUTPUT 16 | error: invalid value `val` for `` 17 | [possible values: abc, def, ghi] 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__option_choice_fn_pass.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog test1 --cc val 7 | 8 | # OUTPUT 9 | argc_cc=val 10 | argc__args=( prog test1 --cc val ) 11 | argc__fn=test1 12 | argc__positionals=( ) 13 | test1 14 | 15 | # BUILD_OUTPUT 16 | error: invalid value `val` for `` 17 | [possible values: abc, def, ghi] 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__option_choice_fn_skip.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog test1 --cd val 7 | 8 | # OUTPUT 9 | argc_cd=val 10 | argc__args=( prog test1 --cd val ) 11 | argc__fn=test1 12 | argc__positionals=( ) 13 | test1 14 | 15 | # BUILD_OUTPUT 16 | argc__args=([0]="prog" [1]="test1" [2]="--cd" [3]="val") 17 | argc__fn=test1 18 | argc__positionals=() 19 | argc_cd=val 20 | test1 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__option_choice_multi.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog test1 --ce abc --ce val 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: invalid value `val` for `` 11 | [possible values: abc, def, ghi] 12 | EOF 13 | exit 1 14 | 15 | # BUILD_OUTPUT 16 | error: invalid value `val` for `` 17 | [possible values: abc, def, ghi] 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__option_mismatch_values.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog test1 -o file1 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: incorrect number of values for `--od ` 11 | EOF 12 | exit 1 13 | 14 | # BUILD_OUTPUT 15 | error: incorrect number of values for `--od ` 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__option_missing.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog test2 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: the following required arguments were not provided: 11 | --oa 12 | --ob ... 13 | --oc ... 14 | --oca 15 | --ocb ... 16 | --occ ... 17 | EOF 18 | exit 1 19 | 20 | # BUILD_OUTPUT 21 | error: the following required arguments were not provided: 22 | --oa 23 | --ob ... 24 | --oc ... 25 | --oca 26 | --ocb ... 27 | --occ ... 28 | 29 | 30 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__option_not_multiple.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog test1 -e -e 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: incorrect number of values for `-e ` 11 | EOF 12 | exit 1 13 | 14 | # BUILD_OUTPUT 15 | error: incorrect number of values for `-e ` 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__option_unknown.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog test1 --unknown 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: unexpected argument `--unknown` found 11 | EOF 12 | exit 1 13 | 14 | # BUILD_OUTPUT 15 | error: unexpected argument `--unknown` found 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__param_missing.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: the following required arguments were not provided: 11 | --ao 12 | EOF 13 | exit 1 14 | 15 | # BUILD_OUTPUT 16 | error: the following required arguments were not provided: 17 | --ao 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__param_missing_parent.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | RUN 6 | prog foo 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | error: the following required arguments were not provided: 11 | --ao 12 | EOF 13 | exit 1 14 | 15 | # BUILD_OUTPUT 16 | error: the following required arguments were not provided: 17 | --ao 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__require_tools.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog 7 | 8 | # OUTPUT 9 | argc__args=( prog ) 10 | argc__fn=main 11 | argc__positionals=( ) 12 | 13 | _argc_require_tools() { 14 | local tool missing_tools=() 15 | for tool in "$@"; do 16 | if ! command -v "$tool" >/dev/null 2>&1; then 17 | missing_tools+=("$tool") 18 | fi 19 | done 20 | if [[ "${#missing_tools[@]}" -gt 0 ]]; then 21 | echo "error: missing tools: ${missing_tools[*]}" >&2 22 | exit 1 23 | fi 24 | } 25 | _argc_require_tools not-found1 26 | 27 | main 28 | 29 | # RUN_OUTPUT 30 | error: missing tools: not-found1 31 | 32 | ************ RUN ************ 33 | prog cmd1 34 | 35 | # OUTPUT 36 | argc__args=( prog cmd1 ) 37 | argc__fn=cmd1 38 | argc__positionals=( ) 39 | 40 | _argc_require_tools() { 41 | local tool missing_tools=() 42 | for tool in "$@"; do 43 | if ! command -v "$tool" >/dev/null 2>&1; then 44 | missing_tools+=("$tool") 45 | fi 46 | done 47 | if [[ "${#missing_tools[@]}" -gt 0 ]]; then 48 | echo "error: missing tools: ${missing_tools[*]}" >&2 49 | exit 1 50 | fi 51 | } 52 | _argc_require_tools not-found1 not-found2 53 | 54 | cmd1 55 | 56 | # RUN_OUTPUT 57 | error: missing tools: not-found1 not-found2 58 | 59 | ************ RUN ************ 60 | prog cmd2 61 | 62 | # OUTPUT 63 | argc__args=( prog cmd2 ) 64 | argc__fn=cmd2 65 | argc__positionals=( ) 66 | 67 | _argc_require_tools() { 68 | local tool missing_tools=() 69 | for tool in "$@"; do 70 | if ! command -v "$tool" >/dev/null 2>&1; then 71 | missing_tools+=("$tool") 72 | fi 73 | done 74 | if [[ "${#missing_tools[@]}" -gt 0 ]]; then 75 | echo "error: missing tools: ${missing_tools[*]}" >&2 76 | exit 1 77 | fi 78 | } 79 | _argc_require_tools not-found1 80 | 81 | cmd2 82 | 83 | # RUN_OUTPUT 84 | error: missing tools: not-found1 85 | -------------------------------------------------------------------------------- /tests/snapshots/integration__validate__version_missing.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: tests/validate.rs 3 | expression: data 4 | --- 5 | ************ RUN ************ 6 | prog --version 7 | 8 | # OUTPUT 9 | command cat >&2 <<-'EOF' 10 | prog 0.0.0 11 | EOF 12 | exit 0 13 | 14 | # RUN_OUTPUT 15 | prog 0.0.0 16 | 17 | ************ RUN ************ 18 | prog cmd --version 19 | 20 | # OUTPUT 21 | argc__args=( prog cmd --version ) 22 | argc__fn=cmd 23 | argc__positionals=( --version ) 24 | cmd --version 25 | 26 | # RUN_OUTPUT 27 | argc__args=([0]="prog" [1]="cmd" [2]="--version") 28 | argc__fn=cmd 29 | argc__positionals=([0]="--version") 30 | cmd --version 31 | -------------------------------------------------------------------------------- /tests/tests.rs: -------------------------------------------------------------------------------- 1 | mod fixtures; 2 | 3 | pub const SCRIPT_OPTIONS: &str = include_str!("../examples/options.sh"); 4 | pub const SCRIPT_ARGS: &str = include_str!("../examples/args.sh"); 5 | pub const SCRIPT_ENVS: &str = include_str!("../examples/envs.sh"); 6 | pub const SCRIPT_MULTILINE: &str = include_str!("../examples/multiline.sh"); 7 | 8 | pub use fixtures::locate_script; 9 | 10 | #[macro_use] 11 | mod macros; 12 | mod bind_env; 13 | mod cli; 14 | mod compgen; 15 | mod env; 16 | mod fail; 17 | mod hook_fn; 18 | mod main_fn; 19 | mod meta; 20 | #[cfg(target_os = "linux")] 21 | mod misc; 22 | mod multiline; 23 | mod param_fn; 24 | mod spec; 25 | mod validate; 26 | --------------------------------------------------------------------------------