Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.1
Original file line numberDiff line numberDiff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.md
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
% download(1) Version 0.1.0 | Sample application
% Lana Lang
% September 2025
% November 2025

NAME
==================================================
Expand Down
1 change: 1 addition & 0 deletions lib/bashly/config_validator.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
11 changes: 8 additions & 3 deletions lib/bashly/script/catch_all.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand All@@ -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
Expand All@@ -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?
Expand All@@ -45,6 +46,10 @@ def required?
@required
end

def catch_help?
@catch_help
end

def usage_string
return nil unless enabled?

Expand Down
7 changes: 7 additions & 0 deletions lib/bashly/script/introspection/flags.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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?
Expand Down
14 changes: 8 additions & 6 deletions lib/bashly/views/command/fixed_flags_filter.gtx
Original file line numberDiff line numberDiff line change
Expand Up@@ -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|
Expand Down
10 changes: 1 addition & 9 deletions lib/bashly/views/command/long_usage.gtx
Original file line numberDiff line numberDiff line change
@@ -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 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
Expand Down
16 changes: 9 additions & 7 deletions lib/bashly/views/command/usage_fixed_flags.gtx
Original file line numberDiff line numberDiff line change
@@ -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")
Expand Down
11 changes: 11 additions & 0 deletions lib/bashly/views/command/usage_options.gtx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
= view_marker

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)
5 changes: 5 additions & 0 deletions schemas/bashly.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
26 changes: 26 additions & 0 deletions spec/approvals/fixtures/catch-all-including-help
Original file line numberDiff line numberDiff line change
@@ -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

22 changes: 22 additions & 0 deletions spec/approvals/fixtures/catch-all-no-fixed-flags
Original file line numberDiff line numberDiff line change
@@ -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

1 change: 1 addition & 0 deletions spec/approvals/validations/command_catch_all_catch_help
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.catch_all.catch_help must be a boolean>
7 changes: 7 additions & 0 deletions spec/fixtures/script/validations.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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:
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
This fixture tests that catch all with catch_help is catching the --help flag
18 changes: 18 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
show_help=${args["--show-help-anyway"]-}

if [[ $show_help ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker --show-help-anyway
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
3 changes: 3 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/README.md
Original file line numberDiff line numberDiff line change
@@ -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)
13 changes: 13 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
if [[ "${other_args[0]}" == "show-hidden-usage" ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker show-hidden-usage
28 changes: 25 additions & 3 deletions spec/fixtures/workspaces/lib-upgrade/src/lib/send_completions.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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")'
Expand Down
4 changes: 3 additions & 1 deletion support/runfile/example.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.1
Original file line numberDiff line numberDiff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.md
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
% download(1) Version 0.1.0 | Sample application
% Lana Lang
% September 2025
% November 2025

NAME
==================================================
Expand Down
1 change: 1 addition & 0 deletions lib/bashly/config_validator.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
11 changes: 8 additions & 3 deletions lib/bashly/script/catch_all.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand All@@ -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
Expand All@@ -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?
Expand All@@ -45,6 +46,10 @@ def required?
@required
end

def catch_help?
@catch_help
end

def usage_string
return nil unless enabled?

Expand Down
7 changes: 7 additions & 0 deletions lib/bashly/script/introspection/flags.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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?
Expand Down
14 changes: 8 additions & 6 deletions lib/bashly/views/command/fixed_flags_filter.gtx
Original file line numberDiff line numberDiff line change
Expand Up@@ -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|
Expand Down
10 changes: 1 addition & 9 deletions lib/bashly/views/command/long_usage.gtx
Original file line numberDiff line numberDiff line change
@@ -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 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
Expand Down
16 changes: 9 additions & 7 deletions lib/bashly/views/command/usage_fixed_flags.gtx
Original file line numberDiff line numberDiff line change
@@ -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")
Expand Down
11 changes: 11 additions & 0 deletions lib/bashly/views/command/usage_options.gtx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
= view_marker

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)
5 changes: 5 additions & 0 deletions schemas/bashly.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
26 changes: 26 additions & 0 deletions spec/approvals/fixtures/catch-all-including-help
Original file line numberDiff line numberDiff line change
@@ -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

22 changes: 22 additions & 0 deletions spec/approvals/fixtures/catch-all-no-fixed-flags
Original file line numberDiff line numberDiff line change
@@ -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

1 change: 1 addition & 0 deletions spec/approvals/validations/command_catch_all_catch_help
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.catch_all.catch_help must be a boolean>
7 changes: 7 additions & 0 deletions spec/fixtures/script/validations.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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:
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
This fixture tests that catch all with catch_help is catching the --help flag
18 changes: 18 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
show_help=${args["--show-help-anyway"]-}

if [[ $show_help ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker --show-help-anyway
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
3 changes: 3 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/README.md
Original file line numberDiff line numberDiff line change
@@ -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)
13 changes: 13 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
if [[ "${other_args[0]}" == "show-hidden-usage" ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker show-hidden-usage
28 changes: 25 additions & 3 deletions spec/fixtures/workspaces/lib-upgrade/src/lib/send_completions.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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")'
Expand Down
4 changes: 3 additions & 1 deletion support/runfile/example.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.1
Original file line numberDiff line numberDiff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.md
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
% download(1) Version 0.1.0 | Sample application
% Lana Lang
% September 2025
% November 2025

NAME
==================================================
Expand Down
1 change: 1 addition & 0 deletions lib/bashly/config_validator.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
11 changes: 8 additions & 3 deletions lib/bashly/script/catch_all.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand All@@ -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
Expand All@@ -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?
Expand All@@ -45,6 +46,10 @@ def required?
@required
end

def catch_help?
@catch_help
end

def usage_string
return nil unless enabled?

Expand Down
7 changes: 7 additions & 0 deletions lib/bashly/script/introspection/flags.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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?
Expand Down
14 changes: 8 additions & 6 deletions lib/bashly/views/command/fixed_flags_filter.gtx
Original file line numberDiff line numberDiff line change
Expand Up@@ -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|
Expand Down
10 changes: 1 addition & 9 deletions lib/bashly/views/command/long_usage.gtx
Original file line numberDiff line numberDiff line change
@@ -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 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
Expand Down
16 changes: 9 additions & 7 deletions lib/bashly/views/command/usage_fixed_flags.gtx
Original file line numberDiff line numberDiff line change
@@ -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")
Expand Down
11 changes: 11 additions & 0 deletions lib/bashly/views/command/usage_options.gtx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
= view_marker

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)
5 changes: 5 additions & 0 deletions schemas/bashly.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
26 changes: 26 additions & 0 deletions spec/approvals/fixtures/catch-all-including-help
Original file line numberDiff line numberDiff line change
@@ -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

22 changes: 22 additions & 0 deletions spec/approvals/fixtures/catch-all-no-fixed-flags
Original file line numberDiff line numberDiff line change
@@ -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

1 change: 1 addition & 0 deletions spec/approvals/validations/command_catch_all_catch_help
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.catch_all.catch_help must be a boolean>
7 changes: 7 additions & 0 deletions spec/fixtures/script/validations.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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:
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
This fixture tests that catch all with catch_help is catching the --help flag
18 changes: 18 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
show_help=${args["--show-help-anyway"]-}

if [[ $show_help ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker --show-help-anyway
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
3 changes: 3 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/README.md
Original file line numberDiff line numberDiff line change
@@ -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)
13 changes: 13 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
if [[ "${other_args[0]}" == "show-hidden-usage" ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker show-hidden-usage
28 changes: 25 additions & 3 deletions spec/fixtures/workspaces/lib-upgrade/src/lib/send_completions.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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")'
Expand Down
4 changes: 3 additions & 1 deletion support/runfile/example.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.1
Original file line numberDiff line numberDiff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.md
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
% download(1) Version 0.1.0 | Sample application
% Lana Lang
% September 2025
% November 2025

NAME
==================================================
Expand Down
1 change: 1 addition & 0 deletions lib/bashly/config_validator.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
11 changes: 8 additions & 3 deletions lib/bashly/script/catch_all.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand All@@ -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
Expand All@@ -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?
Expand All@@ -45,6 +46,10 @@ def required?
@required
end

def catch_help?
@catch_help
end

def usage_string
return nil unless enabled?

Expand Down
7 changes: 7 additions & 0 deletions lib/bashly/script/introspection/flags.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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?
Expand Down
14 changes: 8 additions & 6 deletions lib/bashly/views/command/fixed_flags_filter.gtx
Original file line numberDiff line numberDiff line change
Expand Up@@ -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|
Expand Down
10 changes: 1 addition & 9 deletions lib/bashly/views/command/long_usage.gtx
Original file line numberDiff line numberDiff line change
@@ -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 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
Expand Down
16 changes: 9 additions & 7 deletions lib/bashly/views/command/usage_fixed_flags.gtx
Original file line numberDiff line numberDiff line change
@@ -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")
Expand Down
11 changes: 11 additions & 0 deletions lib/bashly/views/command/usage_options.gtx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
= view_marker

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)
5 changes: 5 additions & 0 deletions schemas/bashly.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
26 changes: 26 additions & 0 deletions spec/approvals/fixtures/catch-all-including-help
Original file line numberDiff line numberDiff line change
@@ -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

22 changes: 22 additions & 0 deletions spec/approvals/fixtures/catch-all-no-fixed-flags
Original file line numberDiff line numberDiff line change
@@ -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

1 change: 1 addition & 0 deletions spec/approvals/validations/command_catch_all_catch_help
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.catch_all.catch_help must be a boolean>
7 changes: 7 additions & 0 deletions spec/fixtures/script/validations.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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:
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
This fixture tests that catch all with catch_help is catching the --help flag
18 changes: 18 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
show_help=${args["--show-help-anyway"]-}

if [[ $show_help ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker --show-help-anyway
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
3 changes: 3 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/README.md
Original file line numberDiff line numberDiff line change
@@ -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)
13 changes: 13 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
if [[ "${other_args[0]}" == "show-hidden-usage" ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker show-hidden-usage
28 changes: 25 additions & 3 deletions spec/fixtures/workspaces/lib-upgrade/src/lib/send_completions.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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")'
Expand Down
4 changes: 3 additions & 1 deletion support/runfile/example.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.1
Original file line numberDiff line numberDiff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.md
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
% download(1) Version 0.1.0 | Sample application
% Lana Lang
% September 2025
% November 2025

NAME
==================================================
Expand Down
1 change: 1 addition & 0 deletions lib/bashly/config_validator.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
11 changes: 8 additions & 3 deletions lib/bashly/script/catch_all.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand All@@ -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
Expand All@@ -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?
Expand All@@ -45,6 +46,10 @@ def required?
@required
end

def catch_help?
@catch_help
end

def usage_string
return nil unless enabled?

Expand Down
7 changes: 7 additions & 0 deletions lib/bashly/script/introspection/flags.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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?
Expand Down
14 changes: 8 additions & 6 deletions lib/bashly/views/command/fixed_flags_filter.gtx
Original file line numberDiff line numberDiff line change
Expand Up@@ -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|
Expand Down
10 changes: 1 addition & 9 deletions lib/bashly/views/command/long_usage.gtx
Original file line numberDiff line numberDiff line change
@@ -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 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
Expand Down
16 changes: 9 additions & 7 deletions lib/bashly/views/command/usage_fixed_flags.gtx
Original file line numberDiff line numberDiff line change
@@ -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")
Expand Down
11 changes: 11 additions & 0 deletions lib/bashly/views/command/usage_options.gtx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
= view_marker

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)
5 changes: 5 additions & 0 deletions schemas/bashly.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
26 changes: 26 additions & 0 deletions spec/approvals/fixtures/catch-all-including-help
Original file line numberDiff line numberDiff line change
@@ -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

22 changes: 22 additions & 0 deletions spec/approvals/fixtures/catch-all-no-fixed-flags
Original file line numberDiff line numberDiff line change
@@ -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

1 change: 1 addition & 0 deletions spec/approvals/validations/command_catch_all_catch_help
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.catch_all.catch_help must be a boolean>
7 changes: 7 additions & 0 deletions spec/fixtures/script/validations.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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:
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
This fixture tests that catch all with catch_help is catching the --help flag
18 changes: 18 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
show_help=${args["--show-help-anyway"]-}

if [[ $show_help ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker --show-help-anyway
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
3 changes: 3 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/README.md
Original file line numberDiff line numberDiff line change
@@ -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)
13 changes: 13 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
if [[ "${other_args[0]}" == "show-hidden-usage" ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker show-hidden-usage
28 changes: 25 additions & 3 deletions spec/fixtures/workspaces/lib-upgrade/src/lib/send_completions.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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")'
Expand Down
4 changes: 3 additions & 1 deletion support/runfile/example.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.1
Original file line numberDiff line numberDiff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.md
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
% download(1) Version 0.1.0 | Sample application
% Lana Lang
% September 2025
% November 2025

NAME
==================================================
Expand Down
1 change: 1 addition & 0 deletions lib/bashly/config_validator.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
11 changes: 8 additions & 3 deletions lib/bashly/script/catch_all.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand All@@ -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
Expand All@@ -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?
Expand All@@ -45,6 +46,10 @@ def required?
@required
end

def catch_help?
@catch_help
end

def usage_string
return nil unless enabled?

Expand Down
7 changes: 7 additions & 0 deletions lib/bashly/script/introspection/flags.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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?
Expand Down
14 changes: 8 additions & 6 deletions lib/bashly/views/command/fixed_flags_filter.gtx
Original file line numberDiff line numberDiff line change
Expand Up@@ -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|
Expand Down
10 changes: 1 addition & 9 deletions lib/bashly/views/command/long_usage.gtx
Original file line numberDiff line numberDiff line change
@@ -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 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
Expand Down
16 changes: 9 additions & 7 deletions lib/bashly/views/command/usage_fixed_flags.gtx
Original file line numberDiff line numberDiff line change
@@ -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")
Expand Down
11 changes: 11 additions & 0 deletions lib/bashly/views/command/usage_options.gtx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
= view_marker

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)
5 changes: 5 additions & 0 deletions schemas/bashly.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
26 changes: 26 additions & 0 deletions spec/approvals/fixtures/catch-all-including-help
Original file line numberDiff line numberDiff line change
@@ -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

22 changes: 22 additions & 0 deletions spec/approvals/fixtures/catch-all-no-fixed-flags
Original file line numberDiff line numberDiff line change
@@ -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

1 change: 1 addition & 0 deletions spec/approvals/validations/command_catch_all_catch_help
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.catch_all.catch_help must be a boolean>
7 changes: 7 additions & 0 deletions spec/fixtures/script/validations.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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:
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
This fixture tests that catch all with catch_help is catching the --help flag
18 changes: 18 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
show_help=${args["--show-help-anyway"]-}

if [[ $show_help ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker --show-help-anyway
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
3 changes: 3 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/README.md
Original file line numberDiff line numberDiff line change
@@ -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)
13 changes: 13 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
if [[ "${other_args[0]}" == "show-hidden-usage" ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker show-hidden-usage
28 changes: 25 additions & 3 deletions spec/fixtures/workspaces/lib-upgrade/src/lib/send_completions.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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")'
Expand Down
4 changes: 3 additions & 1 deletion support/runfile/example.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.1
Original file line numberDiff line numberDiff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.md
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
% download(1) Version 0.1.0 | Sample application
% Lana Lang
% September 2025
% November 2025

NAME
==================================================
Expand Down
1 change: 1 addition & 0 deletions lib/bashly/config_validator.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
11 changes: 8 additions & 3 deletions lib/bashly/script/catch_all.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand All@@ -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
Expand All@@ -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?
Expand All@@ -45,6 +46,10 @@ def required?
@required
end

def catch_help?
@catch_help
end

def usage_string
return nil unless enabled?

Expand Down
7 changes: 7 additions & 0 deletions lib/bashly/script/introspection/flags.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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?
Expand Down
14 changes: 8 additions & 6 deletions lib/bashly/views/command/fixed_flags_filter.gtx
Original file line numberDiff line numberDiff line change
Expand Up@@ -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|
Expand Down
10 changes: 1 addition & 9 deletions lib/bashly/views/command/long_usage.gtx
Original file line numberDiff line numberDiff line change
@@ -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 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
Expand Down
16 changes: 9 additions & 7 deletions lib/bashly/views/command/usage_fixed_flags.gtx
Original file line numberDiff line numberDiff line change
@@ -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")
Expand Down
11 changes: 11 additions & 0 deletions lib/bashly/views/command/usage_options.gtx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
= view_marker

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)
5 changes: 5 additions & 0 deletions schemas/bashly.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
26 changes: 26 additions & 0 deletions spec/approvals/fixtures/catch-all-including-help
Original file line numberDiff line numberDiff line change
@@ -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

22 changes: 22 additions & 0 deletions spec/approvals/fixtures/catch-all-no-fixed-flags
Original file line numberDiff line numberDiff line change
@@ -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

1 change: 1 addition & 0 deletions spec/approvals/validations/command_catch_all_catch_help
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.catch_all.catch_help must be a boolean>
7 changes: 7 additions & 0 deletions spec/fixtures/script/validations.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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:
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
This fixture tests that catch all with catch_help is catching the --help flag
18 changes: 18 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
show_help=${args["--show-help-anyway"]-}

if [[ $show_help ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker --show-help-anyway
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
3 changes: 3 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/README.md
Original file line numberDiff line numberDiff line change
@@ -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)
13 changes: 13 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
if [[ "${other_args[0]}" == "show-hidden-usage" ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker show-hidden-usage
28 changes: 25 additions & 3 deletions spec/fixtures/workspaces/lib-upgrade/src/lib/send_completions.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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")'
Expand Down
4 changes: 3 additions & 1 deletion support/runfile/example.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.1
Original file line numberDiff line numberDiff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/render-mandoc/docs/download.md
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
% download(1) Version 0.1.0 | Sample application
% Lana Lang
% September 2025
% November 2025

NAME
==================================================
Expand Down
1 change: 1 addition & 0 deletions lib/bashly/config_validator.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
11 changes: 8 additions & 3 deletions lib/bashly/script/catch_all.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand All@@ -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
Expand All@@ -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?
Expand All@@ -45,6 +46,10 @@ def required?
@required
end

def catch_help?
@catch_help
end

def usage_string
return nil unless enabled?

Expand Down
7 changes: 7 additions & 0 deletions lib/bashly/script/introspection/flags.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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?
Expand Down
14 changes: 8 additions & 6 deletions lib/bashly/views/command/fixed_flags_filter.gtx
Original file line numberDiff line numberDiff line change
Expand Up@@ -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|
Expand Down
10 changes: 1 addition & 9 deletions lib/bashly/views/command/long_usage.gtx
Original file line numberDiff line numberDiff line change
@@ -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 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
Expand Down
16 changes: 9 additions & 7 deletions lib/bashly/views/command/usage_fixed_flags.gtx
Original file line numberDiff line numberDiff line change
@@ -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")
Expand Down
11 changes: 11 additions & 0 deletions lib/bashly/views/command/usage_options.gtx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
= view_marker

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)
5 changes: 5 additions & 0 deletions schemas/bashly.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
26 changes: 26 additions & 0 deletions spec/approvals/fixtures/catch-all-including-help
Original file line numberDiff line numberDiff line change
@@ -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

22 changes: 22 additions & 0 deletions spec/approvals/fixtures/catch-all-no-fixed-flags
Original file line numberDiff line numberDiff line change
@@ -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

1 change: 1 addition & 0 deletions spec/approvals/validations/command_catch_all_catch_help
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.catch_all.catch_help must be a boolean>
7 changes: 7 additions & 0 deletions spec/fixtures/script/validations.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -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:
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
This fixture tests that catch all with catch_help is catching the --help flag
18 changes: 18 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
show_help=${args["--show-help-anyway"]-}

if [[ $show_help ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-including-help/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker --show-help-anyway
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
cli
3 changes: 3 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/README.md
Original file line numberDiff line numberDiff line change
@@ -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)
13 changes: 13 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/src/bashly.yml
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
if [[ "${other_args[0]}" == "show-hidden-usage" ]]; then
long_usage=yes
cli_docker_usage
else
inspect_args
fi
10 changes: 10 additions & 0 deletions spec/fixtures/workspaces/catch-all-no-fixed-flags/test.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

rm -f ./cli

set -x

bundle exec bashly generate

./cli docker --help
./cli docker show-hidden-usage
28 changes: 25 additions & 3 deletions spec/fixtures/workspaces/lib-upgrade/src/lib/send_completions.sh
Original file line numberDiff line numberDiff line change
Expand Up@@ -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")'
Expand Down
4 changes: 3 additions & 1 deletion support/runfile/example.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
Loading