-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new module l.parse_args. And l.parse_params is deprecated.
User should use l.parse_args instead of l.parse_params. The l.parse_params has some limitations on use. So it is deprecated and will be removed in soon.
- Loading branch information
Showing
7 changed files
with
728 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,7 @@ bump-minor: | |
|
||
bump-patch: | ||
./tools/release patch | ||
|
||
.PHONY: build | ||
build: | ||
./build -y ./dist/lobash.bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit -o nounset -o pipefail -o errtrace | ||
(shopt -p inherit_errexit &>/dev/null) && shopt -s inherit_errexit | ||
|
||
SCRIPT_DIR="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" | ||
readonly SCRIPT_DIR | ||
# shellcheck source=./init.bash | ||
source "$SCRIPT_DIR"/init.bash | ||
|
||
declare -A opts=() | ||
declare -a args=() | ||
declare -A params_def=( | ||
[opts]=opts | ||
[args]=args | ||
[-f --flag]='bool default:1' | ||
[-b]='bool' | ||
) | ||
|
||
foo() { | ||
l.parse_args params_def "$@" | ||
} | ||
|
||
foo -a 3 -b12 -c=5 foo -d= bar -e -3 -4 a -F=abc -gh w -ij=5 -km= -5n -xzy --beep=boop baz --no-wow | ||
|
||
echo 'foo -a 3 -b12 -c=5 foo -d= bar -e -3 -4 a -F=abc -gh w -ij=5 -km= -5n -xzy --beep=boop baz --no-wow' | ||
echo "[${#opts[@]} Options]" | ||
for key in "${!opts[@]}"; do | ||
echo "$key: ${opts[$key]}" | ||
done | ||
|
||
printf "\n[%s Arguments]\n" "${#args[@]}" | ||
declare i=0 | ||
for key in "${args[@]}"; do | ||
echo "$i: $key" | ||
((i += 1)) | ||
done | ||
|
||
echo "------Use Options------" | ||
|
||
# NOTE: Use ${opts[c]:-} instead of ${opts[c]}. If `set -o nounset`, ${opts[c]} will throw error when option omitted. | ||
if [[ -n ${opts[c]:-} ]]; then | ||
echo "c=${opts[c]}" | ||
fi | ||
|
||
echo "------Use Arguments------" | ||
echo "${args[0]} ${args[1]} ${args[2]}" |
Oops, something went wrong.