From 26d6f19c57abe31519eb2739d5baea5555955fad Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Mon, 3 Nov 2025 07:26:29 +0000 Subject: [PATCH 1/3] - Add support for captuing `--help` when using `catch_all` --- examples/render-mandoc/docs/download.1 | 2 +- examples/render-mandoc/docs/download.md | 2 +- lib/bashly/config_validator.rb | 1 + lib/bashly/script/catch_all.rb | 11 +++++--- lib/bashly/script/introspection/flags.rb | 7 +++++ .../views/command/fixed_flags_filter.gtx | 14 +++++----- lib/bashly/views/command/long_usage.gtx | 10 +------ .../views/command/usage_fixed_flags.gtx | 16 +++++++----- lib/bashly/views/command/usage_options.gtx | 13 ++++++++++ .../fixtures/catch-all-including-help | 26 +++++++++++++++++++ .../fixtures/catch-all-no-fixed-flags | 22 ++++++++++++++++ .../validations/command_catch_all_catch_help | 1 + spec/fixtures/script/validations.yml | 7 +++++ .../catch-all-including-help/.gitignore | 1 + .../catch-all-including-help/README.md | 1 + .../catch-all-including-help/src/bashly.yml | 18 +++++++++++++ .../src/docker_command.sh | 8 ++++++ .../catch-all-including-help/test.sh | 15 +++++++++++ .../catch-all-no-fixed-flags/.gitignore | 1 + .../catch-all-no-fixed-flags/README.md | 3 +++ .../catch-all-no-fixed-flags/src/bashly.yml | 13 ++++++++++ .../src/docker_command.sh | 6 +++++ .../catch-all-no-fixed-flags/test.sh | 15 +++++++++++ 23 files changed, 186 insertions(+), 27 deletions(-) create mode 100644 lib/bashly/views/command/usage_options.gtx create mode 100644 spec/approvals/fixtures/catch-all-including-help create mode 100644 spec/approvals/fixtures/catch-all-no-fixed-flags create mode 100644 spec/approvals/validations/command_catch_all_catch_help create mode 100644 spec/fixtures/workspaces/catch-all-including-help/.gitignore create mode 100644 spec/fixtures/workspaces/catch-all-including-help/README.md create mode 100644 spec/fixtures/workspaces/catch-all-including-help/src/bashly.yml create mode 100644 spec/fixtures/workspaces/catch-all-including-help/src/docker_command.sh create mode 100644 spec/fixtures/workspaces/catch-all-including-help/test.sh create mode 100644 spec/fixtures/workspaces/catch-all-no-fixed-flags/.gitignore create mode 100644 spec/fixtures/workspaces/catch-all-no-fixed-flags/README.md create mode 100644 spec/fixtures/workspaces/catch-all-no-fixed-flags/src/bashly.yml create mode 100644 spec/fixtures/workspaces/catch-all-no-fixed-flags/src/docker_command.sh create mode 100644 spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh diff --git a/examples/render-mandoc/docs/download.1 b/examples/render-mandoc/docs/download.1 index 0994956e..f4398bb2 100644 --- a/examples/render-mandoc/docs/download.1 +++ b/examples/render-mandoc/docs/download.1 @@ -1,6 +1,6 @@ .\" Automatically generated by Pandoc 3.2 .\" -.TH "download" "1" "September 2025" "Version 0.1.0" "Sample application" +.TH "download" "1" "November 2025" "Version 0.1.0" "Sample application" .SH NAME \f[B]download\f[R] \- Sample application .SH SYNOPSIS diff --git a/examples/render-mandoc/docs/download.md b/examples/render-mandoc/docs/download.md index 706412b8..d1dfb470 100644 --- a/examples/render-mandoc/docs/download.md +++ b/examples/render-mandoc/docs/download.md @@ -1,6 +1,6 @@ % download(1) Version 0.1.0 | Sample application % Lana Lang -% September 2025 +% November 2025 NAME ================================================== diff --git a/lib/bashly/config_validator.rb b/lib/bashly/config_validator.rb index 0c430054..2fcac278 100644 --- a/lib/bashly/config_validator.rb +++ b/lib/bashly/config_validator.rb @@ -35,6 +35,7 @@ def assert_catch_all_hash(key, value) assert_string "#{key}.label", value['label'] assert_optional_string "#{key}.help", value['help'] assert_boolean "#{key}.required", value['required'] + assert_boolean "#{key}.catch_help", value['catch_help'] end def assert_default_command(key, value) diff --git a/lib/bashly/script/catch_all.rb b/lib/bashly/script/catch_all.rb index b2abdddb..03708aad 100644 --- a/lib/bashly/script/catch_all.rb +++ b/lib/bashly/script/catch_all.rb @@ -3,7 +3,7 @@ module Script class CatchAll class << self def option_keys - @option_keys ||= %i[label help required] + @option_keys ||= %i[label help required catch_help] end def from_config(config) @@ -13,7 +13,7 @@ def from_config(config) when String { label: config } when Hash - { label: config['label'], help: config['help'], required: config['required'] } + config.transform_keys(&:to_sym).slice(*option_keys) else {} end @@ -22,11 +22,12 @@ def from_config(config) end end - def initialize(label: nil, help: nil, required: false, enabled: true) + def initialize(label: nil, help: nil, required: false, catch_help: false, enabled: true) @label = label @help = help @required = required @enabled = enabled + @catch_help = catch_help end def enabled? @@ -45,6 +46,10 @@ def required? @required end + def catch_help? + @catch_help + end + def usage_string return nil unless enabled? diff --git a/lib/bashly/script/introspection/flags.rb b/lib/bashly/script/introspection/flags.rb index 107661cd..89ca2a57 100644 --- a/lib/bashly/script/introspection/flags.rb +++ b/lib/bashly/script/introspection/flags.rb @@ -16,6 +16,13 @@ def flags end end + # Returns true if there is at least one fixed flag (--version / --help) + # Root command always has --version and subcommands always have --help + # except when it is consumed by catch_all + def fixed_flags? + root_command? || !catch_all.catch_help? + end + # Returns true if this command's flags should be considered as gloal # flags, and cascade to subcommands def global_flags? diff --git a/lib/bashly/views/command/fixed_flags_filter.gtx b/lib/bashly/views/command/fixed_flags_filter.gtx index a51b80e0..ccf36c0b 100644 --- a/lib/bashly/views/command/fixed_flags_filter.gtx +++ b/lib/bashly/views/command/fixed_flags_filter.gtx @@ -12,12 +12,14 @@ if root_command? > end -= (short_flag_exist?("-h") ? "--help)" : "--help | -h)").indent(4) -> long_usage=yes -> <%= function_name %>_usage -> exit -> ;; -> +unless catch_all.catch_help? + = (short_flag_exist?("-h") ? "--help)" : "--help | -h)").indent(4) + > long_usage=yes + > <%= function_name %>_usage + > exit + > ;; + > +end if global_flags? flags.each do |flag| diff --git a/lib/bashly/views/command/long_usage.gtx b/lib/bashly/views/command/long_usage.gtx index d9794a73..e77d1f44 100644 --- a/lib/bashly/views/command/long_usage.gtx +++ b/lib/bashly/views/command/long_usage.gtx @@ -1,15 +1,7 @@ = view_marker > if [[ -n "$long_usage" ]]; then -options_caption = strings[:options] -if commands.any? && (public_flags.any? || (flags.any? && Settings.private_reveal_key)) - options_caption = strings[:global_options] -end - -> printf "%s\n" "{{ options_caption.color(:caption) }}" -> -= render(:usage_flags).indent 2 if flags.any? -= render(:usage_fixed_flags).indent 2 += render(:usage_options).indent 2 = render(:usage_args).indent 2 if args.any? or catch_all.help = render(:usage_environment_variables).indent 2 if environment_variables.any? = render(:usage_examples).indent 2 if examples diff --git a/lib/bashly/views/command/usage_fixed_flags.gtx b/lib/bashly/views/command/usage_fixed_flags.gtx index 1a1f496f..6e831c5a 100644 --- a/lib/bashly/views/command/usage_fixed_flags.gtx +++ b/lib/bashly/views/command/usage_fixed_flags.gtx @@ -1,13 +1,15 @@ = view_marker -if short_flag_exist?("-h") - > printf " %s\n" "{{ '--help'.color(:flag) }}" -else - > printf " %s\n" "{{ '--help, -h'.color(:flag) }}" -end +unless catch_all.catch_help? + if short_flag_exist?("-h") + > printf " %s\n" "{{ '--help'.color(:flag) }}" + else + > printf " %s\n" "{{ '--help, -h'.color(:flag) }}" + end -> printf " {{ strings[:help_flag_text] }}\n" -> echo + > printf " {{ strings[:help_flag_text] }}\n" + > echo +end if root_command? if short_flag_exist?("-v") diff --git a/lib/bashly/views/command/usage_options.gtx b/lib/bashly/views/command/usage_options.gtx new file mode 100644 index 00000000..18863299 --- /dev/null +++ b/lib/bashly/views/command/usage_options.gtx @@ -0,0 +1,13 @@ += view_marker + +if flags.any? || fixed_flags? + options_caption = strings[:options] + if commands.any? && (public_flags.any? || (flags.any? && Settings.private_reveal_key)) + options_caption = strings[:global_options] + end + + > printf "%s\n" "{{ options_caption.color(:caption) }}" + > + = render(:usage_flags).indent 2 if flags.any? + = render(:usage_fixed_flags).indent 2 +end diff --git a/spec/approvals/fixtures/catch-all-including-help b/spec/approvals/fixtures/catch-all-including-help new file mode 100644 index 00000000..29fc3df6 --- /dev/null +++ b/spec/approvals/fixtures/catch-all-including-help @@ -0,0 +1,26 @@ ++ bundle exec bashly generate +creating user files in src +skipped src/docker_command.sh (exists) +created ./cli +run ./cli --help to test your bash script ++ ./cli docker --help +args: none + +other_args: +- ${other_args[*]} = --help +- ${other_args[0]} = --help ++ ./cli docker --show-help-anyway +cli docker - Pass all arguments to the docker cli + +Usage: + cli docker [OPTIONS] [--] [PARAMS...] + cli docker --help | -h + +Options: + --show-help-anyway + Show this help message + +Arguments: + PARAMS... + Parameters to pass to docker + diff --git a/spec/approvals/fixtures/catch-all-no-fixed-flags b/spec/approvals/fixtures/catch-all-no-fixed-flags new file mode 100644 index 00000000..9b67b823 --- /dev/null +++ b/spec/approvals/fixtures/catch-all-no-fixed-flags @@ -0,0 +1,22 @@ ++ bundle exec bashly generate +creating user files in src +skipped src/docker_command.sh (exists) +created ./cli +run ./cli --help to test your bash script ++ ./cli docker --help +args: none + +other_args: +- ${other_args[*]} = --help +- ${other_args[0]} = --help ++ ./cli docker show-hidden-usage +cli docker - Pass all arguments to the docker cli + +Usage: + cli docker [--] [PARAMS...] + cli docker --help | -h + +Arguments: + PARAMS... + Parameters to pass to docker + diff --git a/spec/approvals/validations/command_catch_all_catch_help b/spec/approvals/validations/command_catch_all_catch_help new file mode 100644 index 00000000..a44f0afc --- /dev/null +++ b/spec/approvals/validations/command_catch_all_catch_help @@ -0,0 +1 @@ +# \ No newline at end of file diff --git a/spec/fixtures/script/validations.yml b/spec/fixtures/script/validations.yml index 2d125660..997f38d1 100644 --- a/spec/fixtures/script/validations.yml +++ b/spec/fixtures/script/validations.yml @@ -94,6 +94,13 @@ help: catch_all must be boolean, string, or hash catch_all: [1,2] +:command_catch_all_catch_help: + name: invalid + help: catch_all.catch_help must be boolean + catch_all: + label: params + catch_help: "this is not a help string" + :command_catch_all_valid: name: invalid catch_all: diff --git a/spec/fixtures/workspaces/catch-all-including-help/.gitignore b/spec/fixtures/workspaces/catch-all-including-help/.gitignore new file mode 100644 index 00000000..573c0c4f --- /dev/null +++ b/spec/fixtures/workspaces/catch-all-including-help/.gitignore @@ -0,0 +1 @@ +cli diff --git a/spec/fixtures/workspaces/catch-all-including-help/README.md b/spec/fixtures/workspaces/catch-all-including-help/README.md new file mode 100644 index 00000000..c7878740 --- /dev/null +++ b/spec/fixtures/workspaces/catch-all-including-help/README.md @@ -0,0 +1 @@ +This fixture tests that catch all with catch_help is catching the --help flag diff --git a/spec/fixtures/workspaces/catch-all-including-help/src/bashly.yml b/spec/fixtures/workspaces/catch-all-including-help/src/bashly.yml new file mode 100644 index 00000000..308c41dd --- /dev/null +++ b/spec/fixtures/workspaces/catch-all-including-help/src/bashly.yml @@ -0,0 +1,18 @@ +name: cli +help: Showing catch all including the help flag +version: 0.1.0 + +commands: +- name: docker + help: Pass all arguments to the docker cli + catch_all: + label: params + help: Parameters to pass to docker + required: false + # Also catch --help | -h as any other param + catch_help: true + + # We want to see that the internal usage command still prints normally + flags: + - long: --show-help-anyway + help: Show this help message diff --git a/spec/fixtures/workspaces/catch-all-including-help/src/docker_command.sh b/spec/fixtures/workspaces/catch-all-including-help/src/docker_command.sh new file mode 100644 index 00000000..75187d0a --- /dev/null +++ b/spec/fixtures/workspaces/catch-all-including-help/src/docker_command.sh @@ -0,0 +1,8 @@ +show_help=${args[--show-help-anyway]-} + +if [[ $show_help ]]; then + long_usage=yes + cli_docker_usage +else + inspect_args +fi diff --git a/spec/fixtures/workspaces/catch-all-including-help/test.sh b/spec/fixtures/workspaces/catch-all-including-help/test.sh new file mode 100644 index 00000000..bf4b0ca5 --- /dev/null +++ b/spec/fixtures/workspaces/catch-all-including-help/test.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# This fixture tests that catch all with help is displayed even when the +# configuration file does not have any args defined. +# It is executed as part of the Runfile examples test +# Reference issue: https://github.com/bashly-framework/bashly/issues/74 + +rm -f ./cli + +set -x + +bundle exec bashly generate + +./cli docker --help +./cli docker --show-help-anyway diff --git a/spec/fixtures/workspaces/catch-all-no-fixed-flags/.gitignore b/spec/fixtures/workspaces/catch-all-no-fixed-flags/.gitignore new file mode 100644 index 00000000..573c0c4f --- /dev/null +++ b/spec/fixtures/workspaces/catch-all-no-fixed-flags/.gitignore @@ -0,0 +1 @@ +cli diff --git a/spec/fixtures/workspaces/catch-all-no-fixed-flags/README.md b/spec/fixtures/workspaces/catch-all-no-fixed-flags/README.md new file mode 100644 index 00000000..3da4ded7 --- /dev/null +++ b/spec/fixtures/workspaces/catch-all-no-fixed-flags/README.md @@ -0,0 +1,3 @@ +This fixture tests that when catch all is set with catch_help and no other +flags, the usage text - if called by the developer - is not showing the +"Options" caption (since there are now zero options to show) diff --git a/spec/fixtures/workspaces/catch-all-no-fixed-flags/src/bashly.yml b/spec/fixtures/workspaces/catch-all-no-fixed-flags/src/bashly.yml new file mode 100644 index 00000000..01b34f42 --- /dev/null +++ b/spec/fixtures/workspaces/catch-all-no-fixed-flags/src/bashly.yml @@ -0,0 +1,13 @@ +name: cli +help: Showing catch all including the help flag +version: 0.1.0 + +commands: +- name: docker + help: Pass all arguments to the docker cli + catch_all: + label: params + help: Parameters to pass to docker + required: false + # Also catch --help | -h as any other param + catch_help: true diff --git a/spec/fixtures/workspaces/catch-all-no-fixed-flags/src/docker_command.sh b/spec/fixtures/workspaces/catch-all-no-fixed-flags/src/docker_command.sh new file mode 100644 index 00000000..3a00e90d --- /dev/null +++ b/spec/fixtures/workspaces/catch-all-no-fixed-flags/src/docker_command.sh @@ -0,0 +1,6 @@ +if [[ "${other_args[0]}" == "show-hidden-usage" ]]; then + long_usage=yes + cli_docker_usage +else + inspect_args +fi diff --git a/spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh b/spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh new file mode 100644 index 00000000..79f3ea75 --- /dev/null +++ b/spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# This fixture tests that catch all with help is displayed even when the +# configuration file does not have any args defined. +# It is executed as part of the Runfile examples test +# Reference issue: https://github.com/bashly-framework/bashly/issues/74 + +rm -f ./cli + +set -x + +bundle exec bashly generate + +./cli docker --help +./cli docker show-hidden-usage From 65cf0c6ebb7dcae02c6a168b8ebafbb0c84b9468 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Mon, 3 Nov 2025 07:42:15 +0000 Subject: [PATCH 2/3] fix shfmt violations --- lib/bashly/views/command/usage_options.gtx | 6 ++-- .../src/docker_command.sh | 2 +- .../lib-upgrade/src/lib/send_completions.sh | 28 +++++++++++++++++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/bashly/views/command/usage_options.gtx b/lib/bashly/views/command/usage_options.gtx index 18863299..208be567 100644 --- a/lib/bashly/views/command/usage_options.gtx +++ b/lib/bashly/views/command/usage_options.gtx @@ -6,8 +6,8 @@ if flags.any? || fixed_flags? options_caption = strings[:global_options] end - > printf "%s\n" "{{ options_caption.color(:caption) }}" + > printf "%s\n" "{{ options_caption.color(:caption) }}" > - = render(:usage_flags).indent 2 if flags.any? - = render(:usage_fixed_flags).indent 2 + = render(:usage_flags) if flags.any? + = render(:usage_fixed_flags) end diff --git a/spec/fixtures/workspaces/catch-all-including-help/src/docker_command.sh b/spec/fixtures/workspaces/catch-all-including-help/src/docker_command.sh index 75187d0a..f907d810 100644 --- a/spec/fixtures/workspaces/catch-all-including-help/src/docker_command.sh +++ b/spec/fixtures/workspaces/catch-all-including-help/src/docker_command.sh @@ -1,4 +1,4 @@ -show_help=${args[--show-help-anyway]-} +show_help=${args["--show-help-anyway"]-} if [[ $show_help ]]; then long_usage=yes diff --git a/spec/fixtures/workspaces/lib-upgrade/src/lib/send_completions.sh b/spec/fixtures/workspaces/lib-upgrade/src/lib/send_completions.sh index e2853585..b1851a88 100644 --- a/spec/fixtures/workspaces/lib-upgrade/src/lib/send_completions.sh +++ b/spec/fixtures/workspaces/lib-upgrade/src/lib/send_completions.sh @@ -11,24 +11,46 @@ send_completions() { echo $' local cur=${COMP_WORDS[COMP_CWORD]}' echo $' local result=()' echo $'' + echo $' # words the user already typed (excluding the command itself)' + echo $' local used=()' + echo $' if ((COMP_CWORD > 1)); then' + echo $' used=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")' + echo $' fi' + echo $'' echo $' if [[ "${cur:0:1}" == "-" ]]; then' + echo $' # Completing an option: offer everything (including options)' echo $' echo "$words"' echo $'' echo $' else' + echo $' # Completing a non-option: offer only non-options,' + echo $' # and don\'t re-offer ones already used earlier in the line.' echo $' for word in $words; do' - echo $' [[ "${word:0:1}" != "-" ]] && result+=("$word")' + echo $' [[ "${word:0:1}" == "-" ]] && continue' + echo $'' + echo $' local seen=0' + echo $' for u in "${used[@]}"; do' + echo $' if [[ "$u" == "$word" ]]; then' + echo $' seen=1' + echo $' break' + echo $' fi' + echo $' done' + echo $' ((!seen)) && result+=("$word")' echo $' done' echo $'' echo $' echo "${result[*]}"' - echo $'' echo $' fi' echo $'}' echo $'' echo $'_cli_completions() {' echo $' local cur=${COMP_WORDS[COMP_CWORD]}' - echo $' local compwords=("${COMP_WORDS[@]:1:$COMP_CWORD-1}")' + echo $' local compwords=()' + echo $' if ((COMP_CWORD > 0)); then' + echo $' compwords=("${COMP_WORDS[@]:1:$((COMP_CWORD - 1))}")' + echo $' fi' echo $' local compline="${compwords[*]}"' echo $'' + echo $' COMPREPLY=()' + echo $'' echo $' case "$compline" in' echo $' \'download\'*)' echo $' while read -r; do COMPREPLY+=("$REPLY"); done < <(compgen -W "$(_cli_completions_filter "--force --help -f -h")" -- "$cur")' From 8f93a593c2094ff00c311dcbfef8d5a73a31aa06 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Mon, 3 Nov 2025 10:29:37 +0000 Subject: [PATCH 3/3] update JSON scehame with command.catch_all.catch_help and add CI tests for scehams in fixtures --- lib/bashly/views/command/long_usage.gtx | 2 +- lib/bashly/views/command/usage_options.gtx | 18 ++++++++---------- schemas/bashly.json | 5 +++++ .../catch-all-including-help/test.sh | 5 ----- .../catch-all-no-fixed-flags/test.sh | 5 ----- support/runfile/example.rb | 4 +++- support/runfile/schema.runfile | 13 +++++++++++++ support/schema/bashly.yml | 6 ++++++ 8 files changed, 36 insertions(+), 22 deletions(-) diff --git a/lib/bashly/views/command/long_usage.gtx b/lib/bashly/views/command/long_usage.gtx index e77d1f44..211835b8 100644 --- a/lib/bashly/views/command/long_usage.gtx +++ b/lib/bashly/views/command/long_usage.gtx @@ -1,7 +1,7 @@ = view_marker > if [[ -n "$long_usage" ]]; then -= render(:usage_options).indent 2 += render(:usage_options).indent 2 if flags.any? || fixed_flags? = render(:usage_args).indent 2 if args.any? or catch_all.help = render(:usage_environment_variables).indent 2 if environment_variables.any? = render(:usage_examples).indent 2 if examples diff --git a/lib/bashly/views/command/usage_options.gtx b/lib/bashly/views/command/usage_options.gtx index 208be567..92c25c2b 100644 --- a/lib/bashly/views/command/usage_options.gtx +++ b/lib/bashly/views/command/usage_options.gtx @@ -1,13 +1,11 @@ = view_marker -if flags.any? || fixed_flags? - options_caption = strings[:options] - if commands.any? && (public_flags.any? || (flags.any? && Settings.private_reveal_key)) - options_caption = strings[:global_options] - end - - > printf "%s\n" "{{ options_caption.color(:caption) }}" - > - = render(:usage_flags) if flags.any? - = render(:usage_fixed_flags) +options_caption = strings[:options] +if commands.any? && (public_flags.any? || (flags.any? && Settings.private_reveal_key)) + options_caption = strings[:global_options] end + +> printf "%s\n" "{{ options_caption.color(:caption) }}" +> += render(:usage_flags) if flags.any? += render(:usage_fixed_flags) diff --git a/schemas/bashly.json b/schemas/bashly.json index 06615873..dfdcb352 100644 --- a/schemas/bashly.json +++ b/schemas/bashly.json @@ -683,6 +683,11 @@ "description": "Whether the current argument or flag is required\nhttps://bashly.dev/configuration/command/#catch_all", "type": "boolean", "default": false + }, + "catch_help": { + "description": "Whether to also disable the --help flag and catch it like any other\nhttps://bashly.dev/configuration/command/#catch_all", + "type": "boolean", + "default": false } }, "additionalProperties": false diff --git a/spec/fixtures/workspaces/catch-all-including-help/test.sh b/spec/fixtures/workspaces/catch-all-including-help/test.sh index bf4b0ca5..21eb115d 100644 --- a/spec/fixtures/workspaces/catch-all-including-help/test.sh +++ b/spec/fixtures/workspaces/catch-all-including-help/test.sh @@ -1,10 +1,5 @@ #!/usr/bin/env bash -# This fixture tests that catch all with help is displayed even when the -# configuration file does not have any args defined. -# It is executed as part of the Runfile examples test -# Reference issue: https://github.com/bashly-framework/bashly/issues/74 - rm -f ./cli set -x diff --git a/spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh b/spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh index 79f3ea75..f87ba7ba 100644 --- a/spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh +++ b/spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh @@ -1,10 +1,5 @@ #!/usr/bin/env bash -# This fixture tests that catch all with help is displayed even when the -# configuration file does not have any args defined. -# It is executed as part of the Runfile examples test -# Reference issue: https://github.com/bashly-framework/bashly/issues/74 - rm -f ./cli set -x diff --git a/support/runfile/example.rb b/support/runfile/example.rb index e3cc7a03..f6198796 100644 --- a/support/runfile/example.rb +++ b/support/runfile/example.rb @@ -8,7 +8,9 @@ def examples end def fixtures - filter_dirs('spec/fixtures/workspaces').map { |dir| new dir, type: :fixture } + filter_dirs('spec/fixtures/workspaces') + .select { |dir| File.exist? "#{dir}/src/bashly.yml" } + .map { |dir| new dir, type: :fixture } end def all diff --git a/support/runfile/schema.runfile b/support/runfile/schema.runfile index b233e6cc..fc874372 100644 --- a/support/runfile/schema.runfile +++ b/support/runfile/schema.runfile @@ -16,6 +16,7 @@ end help 'Run all the test actions in this runfile' action :all do check_examples + check_fixtures check_settings check_strings check_arbitrary @@ -46,6 +47,9 @@ action(:example) { |args| schema_check "examples/#{args['EXAMPLE']}/src/bashly.y help 'Test the bashly schema against all examples' action(:examples) { check_examples } +help 'Test the bashly schema against all workspace fixtures' +action(:fixtures) { check_fixtures } + help 'Test the settings schema against the default settings template' action(:settings) { check_settings } @@ -68,6 +72,15 @@ helpers do say "\ngub`Examples PASS`" end + def check_fixtures + say "\ngub`Fixtures`" + Example.fixtures.each do |example| + file = example.yaml_path + schema_check file + end + say "\ngub`Examples PASS`" + end + def check_settings say "\ngub`Settings schema`" file = 'lib/bashly/libraries/settings/settings.yml' diff --git a/support/schema/bashly.yml b/support/schema/bashly.yml index b27a0403..1cc26157 100644 --- a/support/schema/bashly.yml +++ b/support/schema/bashly.yml @@ -581,6 +581,12 @@ definitions: https://bashly.dev/configuration/command/#catch_all type: boolean default: false + catch_help: + description: |- + Whether to also disable the --help flag and catch it like any other + https://bashly.dev/configuration/command/#catch_all + type: boolean + default: false additionalProperties: false completions-property: title: completions