File tree Expand file tree Collapse file tree 6 files changed +28
-26
lines changed
fixtures/workspaces/version-in-subcommands Expand file tree Collapse file tree 6 files changed +28
-26
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,14 @@ bashly generate
1212./cli -h
1313./cli dir
1414./cli file
15+ # verify invalid commands properly error
16+ ./cli dig
1517./cli dir -h
1618./cli file -h
1719./cli dir list
1820./cli dir list -h
21+ # verify invalid subcommands properly error
22+ ./cli dir lost -h
1923./cli file edit
2024./cli file edit -h
2125./cli file edit filename
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ version_flag_text: Show version number
2626flag_requires_an_argument : " %{name} requires an argument: %{usage}"
2727invalid_argument : " invalid argument: %s"
2828invalid_flag : " invalid option: %s"
29+ invalid_command : " invalid command: %s"
2930conflicting_flags : " conflicting options: %s cannot be used with %s"
3031missing_required_argument : " missing required argument: %{arg}\\ nusage: %{usage}"
3132missing_required_flag : " missing required flag: %{usage}"
Original file line number Diff line number Diff line change 11= view_marker
22
3+ > "" )
4+ > {{ function_name }}_usage
5+ > exit 1
6+ > ;;
7+ >
8+ > * )
9+
310if default_command
4- > "" )
5- > {{ function_name }}_usage
6- > exit 1
7- > ;;
8- >
9- > * )
1011 > action="{{ default_command.name }}"
1112 > {{ default_command.function_name }}_parse_requirements "$@"
1213 > shift $#
1314 > ;;
1415 >
1516
1617elsif extensible.is_a? String
17- > "" )
18- > {{ function_name }}_usage
19- > exit 1
20- > ;;
21- >
22- > * )
2318 > if [[ -x "$(command -v "{{ extensible }}")" ]]; then
2419 > exec {{ extensible }} "$@"
2520 > else
26- > {{ function_name }}_usage
21+ > printf " {{ strings[:invalid_command] }}\n" "$action"
2722 > exit 1
2823 > fi
2924 >
3025
3126elsif extensible
32- > "" )
33- > {{ function_name }}_usage
34- > exit 1
35- > ;;
36- >
37- > * )
3827 > if [[ -x "$(command -v "{{ function_name }}-$action")" ]]; then
3928 > shift
4029 > exec "{{ function_name }}-$action" "$@"
4130 > else
42- > {{ function_name }}_usage
31+ > printf " {{ strings[:invalid_command] }}\n" "$action"
4332 > exit 1
4433 > fi
4534 >
4635
4736else
48- > * )
49- > {{ function_name }}_usage
37+ > printf "{{ strings[:invalid_command] }}\n" "$action"
5038 > exit 1
5139 > ;;
5240 >
5341
5442end
55-
56-
Original file line number Diff line number Diff line change @@ -64,6 +64,8 @@ Commands:
6464 show Show file contents
6565 edit Edit the file
6666
67+ + ./cli dig
68+ invalid command: dig
6769+ ./cli dir -h
6870cli dir - Directory commands
6971
@@ -116,6 +118,8 @@ Arguments:
116118 PATH
117119 Directory path
118120
121+ + ./cli dir lost -h
122+ invalid command: lost
119123+ ./cli file edit
120124missing required argument: PATH
121125usage: cli file edit PATH
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ created ./cli
66run ./cli --help to test your bash script
77+ ./cli --version
881.2.3
9- + ./cli help
9+ + ./cli -- help
1010cli - Sample application
1111
1212Usage:
@@ -17,6 +17,13 @@ Usage:
1717Commands:
1818 git Delegate to git
1919
20+ Options:
21+ --help, -h
22+ Show this help
23+
24+ --version, -v
25+ Show version number
26+
2027+ ./cli git --version
2128# this file is located in 'src/git_command.sh'
2229# code for 'cli git' goes here
Original file line number Diff line number Diff line change 77bundle exec bashly generate
88
99./cli --version
10- ./cli help
10+ ./cli -- help
1111./cli git --version
1212./cli git any " other args" -or --flags
You can’t perform that action at this time.
0 commit comments