bash v3
This commit is contained in:
parent
c46260d048
commit
4f243a31c9
41
barg
41
barg
@ -188,7 +188,7 @@ parse_arguments() {
|
||||
positional)
|
||||
local pos="${pos_stack[-1]}"
|
||||
aliases["${parent}.pos::${pos}"]="$id"
|
||||
pos_stack[-1]=$((pos + 1))
|
||||
((pos_stack[-1] = pos + 1))
|
||||
;;
|
||||
rest)
|
||||
aliases["${parent}.rest"]="$id"
|
||||
@ -218,28 +218,27 @@ parse_arguments() {
|
||||
local -a pos_stack=()
|
||||
local token_idx=0
|
||||
|
||||
# Process each token
|
||||
# Bootstrap: Pre-populate with root command
|
||||
local root_id="${aliases["cmd::root"]}"
|
||||
cmd_stack+=("$root_id")
|
||||
pos_stack+=(0)
|
||||
|
||||
# Process each token - all follow same bubble-up pattern
|
||||
while [[ $token_idx -lt ${#tokens[@]} ]]; do
|
||||
local tagged_token="${tokens[$token_idx]}"
|
||||
local token_tag="${tagged_token%%::*}"
|
||||
local token="${tagged_token#*::}"
|
||||
|
||||
local found=false
|
||||
local level
|
||||
|
||||
# Special handling for root - must be processed first
|
||||
# Special case: root token just sets the name, skip matching
|
||||
if [[ "$token_tag" == "root" ]]; then
|
||||
local root_id="${aliases["cmd::root"]}"
|
||||
if [[ -n "$root_id" ]]; then
|
||||
schema["${root_id}.name"]="$token"
|
||||
cmd_stack+=("$root_id")
|
||||
pos_stack+=(0)
|
||||
found=true
|
||||
fi
|
||||
schema["${root_id}.name"]="$token"
|
||||
((token_idx++))
|
||||
continue
|
||||
fi
|
||||
|
||||
local found=false
|
||||
local level
|
||||
|
||||
# Bubble up: try matching from current level to root
|
||||
for ((level = ${#cmd_stack[@]} - 1; level >= 0; level--)); do
|
||||
local entry_id=""
|
||||
@ -261,7 +260,7 @@ parse_arguments() {
|
||||
local pos="${pos_stack[$level]}"
|
||||
entry_id="${aliases["${current_cmd}.pos::${pos}"]}"
|
||||
if [[ -n "$entry_id" ]]; then
|
||||
pos_stack[$level]=$((pos + 1))
|
||||
((pos_stack[level] = pos + 1))
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
@ -357,11 +356,14 @@ parse_arguments() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Handle duplicate destinations
|
||||
if [[ -n "${values[$dest]}" ]]; then
|
||||
values["${cmd_name}_${dest}"]="$value"
|
||||
else
|
||||
values["$dest"]="$value"
|
||||
# Only collect if value was actually set
|
||||
if [[ -n "$value" ]]; then
|
||||
# Handle duplicate destinations
|
||||
if [[ -n "${values[$dest]}" ]]; then
|
||||
values["${cmd_name}_${dest}"]="$value"
|
||||
else
|
||||
values["$dest"]="$value"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
@ -421,6 +423,7 @@ INPUTS=(
|
||||
"dev stop mycontainer --kill -- not specified one"
|
||||
"dev build --from alpine --image node:20 mybox -- echo hi"
|
||||
"dev build --aaaaa --from alpine --image node:20 --bbbbb orb mybox ccccc -- echo hi"
|
||||
"dev build --global --aaaaa --from alpine -qvvi node:20 --bbbbb orb mybox ccccc "
|
||||
)
|
||||
|
||||
# Run tests
|
||||
|
||||
Loading…
Reference in New Issue
Block a user