Skip to content

Commit 3b3c008

Browse files
committed
test: fix tests
1 parent a1d00e6 commit 3b3c008

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

bin/args-init

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ unset -v _args_readlink
88
ARGS_ROOT_DIR="${ARGS_ROOT_DIR%/*}"
99
ARGS_ROOT_DIR="${ARGS_ROOT_DIR%/*}"
1010

11-
source "$ARGS_ROOT_DIR/lib/args-parse.sh"
1211
source "$ARGS_ROOT_DIR/lib/util/util.sh"
12+
source "$ARGS_ROOT_DIR/lib/args-parse.sh"

lib/args-parse.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ args.parse() {
282282
# use argsAllFlags to ensure no invalid arguments
283283
for arg; do
284284
case "$arg" in
285+
-) ;;
286+
--) break ;;
285287
-*)
286288
local isValidFlag=no
287289
for flag in "${argsAllFlags[@]}"; do
@@ -292,11 +294,10 @@ args.parse() {
292294
done
293295

294296
if [ "$isValidFlag" = no ]; then
295-
die "args.parse: Flag '$arg' is not accepted"
297+
args.util.die "args.parse: Flag '$arg' is not accepted"
296298
return
297299
fi
298300
esac
299-
300301
done
301302

302303
# generate argsHelpText
@@ -307,7 +308,7 @@ args.parse() {
307308

308309
# TODO: description can wrap around incorrectly
309310
local descriptionOutput=
310-
if [ -n "$description" ]; then
311+
if [ -n "${description:-}" ]; then
311312
printf -v descriptionOutput "\nDescription:\n"
312313
fi
313314

@@ -322,6 +323,7 @@ args.parse() {
322323
fi
323324
fi
324325

326+
argumentOutput=
325327
if [ "${#argsHelpArrayArgs[@]}" -gt 0 ]; then
326328
printf -v argumentOutput "\nArguments:\n%s" "${argsHelpArrayArgs[*]}"
327329
fi

test/args.bats

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ source ./bin/args-init
5959
@test "longOption and default" {
6060
declare -A args=()
6161

62-
args.parse - <<-'EOF'
62+
args.parse <<-'EOF'
6363
@flag [port] {3000} - The port to open on
6464
EOF
6565

@@ -105,6 +105,7 @@ source ./bin/args-init
105105
(
106106
args.parse --port --something nother <<-'EOF'
107107
@flag <port> - The port to open on
108+
@flag <something> - something
108109
EOF
109110
)
110111
}

test/argsCommands.bats

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ source ./bin/args-init
2121
declare -A args
2222
declare -a argsCommands=()
2323

24-
args.parse --port 3005 serve --user admin now --enable-security <<-'EOF'
24+
args.parse --port 3005 serve --user admin --enable-security now <<-'EOF'
2525
@flag [port.p] {3000} - The port to open on
26+
@flag [user] {} - User
27+
@flag [enable-security] - Enable security
2628
EOF
2729

2830
[[ "${#argsCommands[@]}" = 2 ]]

0 commit comments

Comments
 (0)