Skip to content

Commit f763b01

Browse files
authored
Merge pull request #538 from DannyBen/fix/default-command-flags-only
Fix default command not being triggered when only flags are provided
2 parents 1d611b0 + 7f5d552 commit f763b01

File tree

6 files changed

+67
-1
lines changed

6 files changed

+67
-1
lines changed

lib/bashly/views/command/command_filter.gtx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ if commands.any?
44
> action=${1:-}
55
>
66
> case $action in
7-
> -*) ;;
7+
unless default_command
8+
> -*) ;;
9+
end
810
>
911

1012
commands.each do |command|
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
+ bundle exec bashly generate
2+
creating user files in src
3+
created src/get_command.sh
4+
created ./cli
5+
run ./cli --help to test your bash script
6+
+ ./cli
7+
# this file is located in 'src/get_command.sh'
8+
# code for 'cli get' goes here
9+
# you can edit it freely and regenerate (it will not be overwritten)
10+
args: none
11+
+ ./cli -fd
12+
# this file is located in 'src/get_command.sh'
13+
# code for 'cli get' goes here
14+
# you can edit it freely and regenerate (it will not be overwritten)
15+
args:
16+
- ${args[--debug]} = 1
17+
- ${args[--force]} = 1
18+
+ ./cli source -fd
19+
# this file is located in 'src/get_command.sh'
20+
# code for 'cli get' goes here
21+
# you can edit it freely and regenerate (it will not be overwritten)
22+
args:
23+
- ${args[--debug]} = 1
24+
- ${args[--force]} = 1
25+
- ${args[source]} = source
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cli
2+
src/*.sh
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This fixture tests that the default command is triggered even when only flags
2+
are provided.
3+
Reference issue: https://github.com/DannyBen/bashly/issues/537
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: cli
2+
help: Test that default command is called when only flags are provided
3+
version: 0.1.0
4+
5+
commands:
6+
- name: get
7+
alias: g
8+
help: Get something
9+
default: force
10+
11+
args:
12+
- name: source
13+
help: Source
14+
15+
flags:
16+
- long: --debug
17+
short: -d
18+
help: Debug
19+
20+
- long: --force
21+
short: -f
22+
help: Force
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
rm -f ./src/*.sh
4+
rm -f ./cli
5+
6+
set -x
7+
8+
bundle exec bashly generate
9+
10+
./cli
11+
./cli -fd
12+
./cli source -fd

0 commit comments

Comments
 (0)