Skip to content

Commit

Permalink
bake.bash: 重构,消除定义变量用两行的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed Mar 28, 2024
1 parent f2b50ef commit 2d4cf27
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions bake.bash
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,7 @@ bake._show_cmd_help() {

eval "$(bake.parse "${FUNCNAME[0]}" "$@")"

local usage
usage="${_data["${cmd}/usage"]}"
local usage="${_data["${cmd}/usage"]}"
if [[ "$usage" != "" ]]; then
echo -e "\nUsage: $usage "
else
Expand Down Expand Up @@ -443,8 +442,7 @@ bake._show_cmd_help() {

echo "Available Options:"
for optPath in $(bake._opt_cmd_chain_opts "$cmd"); do
local opt
opt=$(bake._path_basename "$optPath")
local opt=$(bake._path_basename "$optPath")
local name=${_data["$optPath/name"]}
local type=${_data["$optPath/type"]}
local required=${_data["$optPath/required"]}
Expand Down Expand Up @@ -562,10 +560,8 @@ bake.parse() {
# collect opt from command chain : _root>pub>pub.get
# root option first , priority low -> priority high:
for optPath in $(bake._opt_cmd_chain_opts "$cmd" | bake._str_revertLines); do
local opt
opt=$(bake._path_basename "$optPath")
local abbr
abbr=${_data["$optPath/abbr"]}
local opt=$(bake._path_basename "$optPath")
local abbr=${_data["$optPath/abbr"]}
allOptOnCmdChain["--$opt"]="${optPath}"
if [[ "$abbr" != "" ]]; then allOptOnCmdChain["-$abbr"]="${optPath}"; fi
done
Expand All @@ -578,8 +574,7 @@ bake.parse() {
# while all args , until it is not opt
while (($# > 0)); do
# match $1 arg in allOptOnCmdChain, guess $1 is a "-h" "-help" ...
local optPath
optPath=${allOptOnCmdChain["$1"]}
local optPath=${allOptOnCmdChain["$1"]}
# if next arg not a opt , parsing complete;
if [[ "${optPath}" == "" ]]; then break; fi

Expand Down Expand Up @@ -614,8 +609,7 @@ bake.parse() {

local resultStr
for optPath in "${!optVars[@]}"; do
local declareStr
declareStr=$(declare -p "${optVars["$optPath"]}")
local declareStr=$(declare -p "${optVars["$optPath"]}")
resultStr+="${declareStr/#*_opt_value_/declare };\n"
done
resultStr+="declare optShift=$((totalArgs - $#));\n"
Expand Down

0 comments on commit 2d4cf27

Please sign in to comment.