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
12
12
./cli -h
13
13
./cli dir
14
14
./cli file
15
+ # verify invalid commands properly error
16
+ ./cli dig
15
17
./cli dir -h
16
18
./cli file -h
17
19
./cli dir list
18
20
./cli dir list -h
21
+ # verify invalid subcommands properly error
22
+ ./cli dir lost -h
19
23
./cli file edit
20
24
./cli file edit -h
21
25
./cli file edit filename
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ version_flag_text: Show version number
26
26
flag_requires_an_argument : " %{name} requires an argument: %{usage}"
27
27
invalid_argument : " invalid argument: %s"
28
28
invalid_flag : " invalid option: %s"
29
+ invalid_command : " invalid command: %s"
29
30
conflicting_flags : " conflicting options: %s cannot be used with %s"
30
31
missing_required_argument : " missing required argument: %{arg}\\ nusage: %{usage}"
31
32
missing_required_flag : " missing required flag: %{usage}"
Original file line number Diff line number Diff line change 1
1
= view_marker
2
2
3
+ > "" )
4
+ > {{ function_name }}_usage
5
+ > exit 1
6
+ > ;;
7
+ >
8
+ > * )
9
+
3
10
if default_command
4
- > "" )
5
- > {{ function_name }}_usage
6
- > exit 1
7
- > ;;
8
- >
9
- > * )
10
11
> action="{{ default_command.name }}"
11
12
> {{ default_command.function_name }}_parse_requirements "$@"
12
13
> shift $#
13
14
> ;;
14
15
>
15
16
16
17
elsif extensible.is_a? String
17
- > "" )
18
- > {{ function_name }}_usage
19
- > exit 1
20
- > ;;
21
- >
22
- > * )
23
18
> if [[ -x "$(command -v "{{ extensible }}")" ]]; then
24
19
> exec {{ extensible }} "$@"
25
20
> else
26
- > {{ function_name }}_usage
21
+ > printf " {{ strings[:invalid_command] }}\n" "$action"
27
22
> exit 1
28
23
> fi
29
24
>
30
25
31
26
elsif extensible
32
- > "" )
33
- > {{ function_name }}_usage
34
- > exit 1
35
- > ;;
36
- >
37
- > * )
38
27
> if [[ -x "$(command -v "{{ function_name }}-$action")" ]]; then
39
28
> shift
40
29
> exec "{{ function_name }}-$action" "$@"
41
30
> else
42
- > {{ function_name }}_usage
31
+ > printf " {{ strings[:invalid_command] }}\n" "$action"
43
32
> exit 1
44
33
> fi
45
34
>
46
35
47
36
else
48
- > * )
49
- > {{ function_name }}_usage
37
+ > printf "{{ strings[:invalid_command] }}\n" "$action"
50
38
> exit 1
51
39
> ;;
52
40
>
53
41
54
42
end
55
-
56
-
Original file line number Diff line number Diff line change @@ -64,6 +64,8 @@ Commands:
64
64
show Show file contents
65
65
edit Edit the file
66
66
67
+ + ./cli dig
68
+ invalid command: dig
67
69
+ ./cli dir -h
68
70
cli dir - Directory commands
69
71
@@ -116,6 +118,8 @@ Arguments:
116
118
PATH
117
119
Directory path
118
120
121
+ + ./cli dir lost -h
122
+ invalid command: lost
119
123
+ ./cli file edit
120
124
missing required argument: PATH
121
125
usage: cli file edit PATH
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ created ./cli
6
6
run ./cli --help to test your bash script
7
7
+ ./cli --version
8
8
1.2.3
9
- + ./cli help
9
+ + ./cli -- help
10
10
cli - Sample application
11
11
12
12
Usage:
@@ -17,6 +17,13 @@ Usage:
17
17
Commands:
18
18
git Delegate to git
19
19
20
+ Options:
21
+ --help, -h
22
+ Show this help
23
+
24
+ --version, -v
25
+ Show version number
26
+
20
27
+ ./cli git --version
21
28
# this file is located in 'src/git_command.sh'
22
29
# code for 'cli git' goes here
Original file line number Diff line number Diff line change 7
7
bundle exec bashly generate
8
8
9
9
./cli --version
10
- ./cli help
10
+ ./cli -- help
11
11
./cli git --version
12
12
./cli git any " other args" -or --flags
You can’t perform that action at this time.
0 commit comments