Skip to content

Commit 7187c48

Browse files
authored
Merge pull request #135 from DannyBen/fix/pr-122
Allow empty string as argument (replacing #122)
2 parents c0fb600 + d20add3 commit 7187c48

File tree

11 files changed

+62
-5
lines changed

11 files changed

+62
-5
lines changed

lib/bashly/views/argument/validations.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ if [[ -n $(validate_<%= validation_function %> "$1") ]]; then
33
printf "<%= strings[:validation_error] %>\n" "<%= name.upcase %> $(validate_<%= validation_function %> "$1")"
44
exit 1
55
fi
6-
% end
6+
% end

lib/bashly/views/command/parse_requirements_case.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
% if args.any?
33
% condition = "if"
44
% args.each do |arg|
5-
<%= condition %> [[ ! ${args[<%= arg.name %>]} ]]; then
5+
<%= condition %> [[ -z ${args[<%= arg.name %>]+x} ]]; then
66
<%= arg.render(:validations).indent 2 %>
77
args[<%= arg.name %>]=$1
88
shift

lib/bashly/views/command/required_args_filter.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# :command.required_args_filter
22
% required_args.each do |arg|
3-
if [[ $1 && $1 != -* ]]; then
3+
if [[ -n ${1+x} && $1 != -* ]]; then
44
<%= arg.render(:validations).indent 2 %>
55
args[<%= arg.name %>]=$1
66
shift

lib/bashly/views/flag/case.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# :flag.case
22
<%= aliases.join " | " %> )
33
% if arg
4-
if [[ $2 ]]; then
4+
if [[ -n ${2+x} ]]; then
55
<%= render(:validations).indent 4 %>
66
args[<%= name %>]="$2"
77
shift

lib/bashly/views/flag/validations.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ if [[ -n $(validate_<%= validation_function %> "$2") ]]; then
33
printf "<%= strings[:validation_error] %>\n" "<%= usage_string %> $(validate_<%= validation_function %> "$2")"
44
exit 1
55
fi
6-
% end
6+
% end

spec/approvals/examples/empty-args

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
creating user files in src
2+
skipped src/initialize.sh (exists)
3+
skipped src/test_command.sh (exists)
4+
created ./cli
5+
run ./cli --help to test your bash script
6+
+ ./cli test a b --flag c
7+
args:
8+
- ${args[--flag]} = c
9+
- ${args[optional_arg]} = b
10+
- ${args[required_arg]} = a
11+
+ ./cli test ''
12+
args:
13+
- ${args[required_arg]} =
14+
+ ./cli test '' --flag ''
15+
args:
16+
- ${args[--flag]} =
17+
- ${args[required_arg]} =
18+
+ ./cli test '' '' --flag ''
19+
args:
20+
- ${args[--flag]} =
21+
- ${args[optional_arg]} =
22+
- ${args[required_arg]} =
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cli
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: cli
2+
help: Sample application
3+
version: 0.1.0
4+
5+
commands:
6+
- name: test
7+
help: Run test
8+
flags:
9+
- long: --flag
10+
arg: value
11+
args:
12+
- name: required_arg
13+
required: true
14+
- name: optional_arg
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Code here runs inside the initialize() function
2+
# Use it for anything that you need to run before any other function, like
3+
# setting environment vairables:
4+
# CONFIG_FILE=settings.ini
5+
#
6+
# Feel free to empty (but not delete) this file.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
inspect_args

0 commit comments

Comments
 (0)