Skip to content

Fix default command not being triggered when only flags are provided #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2024
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
4 changes: 3 additions & 1 deletion lib/bashly/views/command/command_filter.gtx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ if commands.any?
> action=${1:-}
>
> case $action in
> -*) ;;
unless default_command
> -*) ;;
end
>

commands.each do |command|
Expand Down
25 changes: 25 additions & 0 deletions spec/approvals/fixtures/default-command-flag-only
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
+ bundle exec bashly generate
creating user files in src
created src/get_command.sh
created ./cli
run ./cli --help to test your bash script
+ ./cli
# this file is located in 'src/get_command.sh'
# code for 'cli get' goes here
# you can edit it freely and regenerate (it will not be overwritten)
args: none
+ ./cli -fd
# this file is located in 'src/get_command.sh'
# code for 'cli get' goes here
# you can edit it freely and regenerate (it will not be overwritten)
args:
- ${args[--debug]} = 1
- ${args[--force]} = 1
+ ./cli source -fd
# this file is located in 'src/get_command.sh'
# code for 'cli get' goes here
# you can edit it freely and regenerate (it will not be overwritten)
args:
- ${args[--debug]} = 1
- ${args[--force]} = 1
- ${args[source]} = source
2 changes: 2 additions & 0 deletions spec/fixtures/workspaces/default-command-flag-only/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cli
src/*.sh
3 changes: 3 additions & 0 deletions spec/fixtures/workspaces/default-command-flag-only/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This fixture tests that the default command is triggered even when only flags
are provided.
Reference issue: https://github.com/DannyBen/bashly/issues/537
22 changes: 22 additions & 0 deletions spec/fixtures/workspaces/default-command-flag-only/src/bashly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: cli
help: Test that default command is called when only flags are provided
version: 0.1.0

commands:
- name: get
alias: g
help: Get something
default: force

args:
- name: source
help: Source

flags:
- long: --debug
short: -d
help: Debug

- long: --force
short: -f
help: Force
12 changes: 12 additions & 0 deletions spec/fixtures/workspaces/default-command-flag-only/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

rm -f ./src/*.sh
rm -f ./cli

set -x

bundle exec bashly generate

./cli
./cli -fd
./cli source -fd