Skip to content

Commit

Permalink
Fixes #34
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Jun 17, 2021
1 parent 982778d commit 2304a94
Show file tree
Hide file tree
Showing 6 changed files with 631 additions and 638 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"startrow",
"stty",
"systemctl",
"tnum",
"tprintf",
"tput",
"ttput",
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 5.?.?

- `build.go` now generates `COMMANDS.md` as well.
- Fixed #34 (Argument parsing for switches may result in infinite loop)

## 5.5.0

Expand Down
11 changes: 8 additions & 3 deletions nsroot/misc/arguments-parse.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
],
"body": [
"POSITIONAL=()",
"while [[ \\$# > 0 ]]; do",
"while (( \\$# > 0 )); do",
"\tcase \"\\${1\\}\" in",
"\t\t-f|--flag)",
"\t\techo flag: \"\\${1\\}\"",
"\t\tshift # shift once since flags have no values",
"\t\t;;",
"\t\t-s|--switch)",
"\t\techo \"switch: \\${1\\} with value: \\${2\\}\"",
"\t\tshift 2 # shift twice to bypass switch and its value",
"\t\tnumOfArgs=1 # number of switch arguments",
"\t\tif (( \\$# < numOfArgs + 1 )); then",
"\t\t\tshift \\$#",
"\t\telse",
"\t\t\techo \"switch: \\${1\\} with value: \\${2\\}\"",
"\t\t\tshift \\$((numOfArgs + 1)) # shift 'numOfArgs + 1' to bypass switch and its value",
"\t\tfi",
"\t\t;;",
"\t\t*) # unknown flag/switch",
"\t\tPOSITIONAL+=(\"\\${1\\}\")",
Expand Down
Loading

0 comments on commit 2304a94

Please sign in to comment.