I was trying to set up some alias command and function for gcloud.
I have written below function and running it in zsh in mac.
It runs fine when I pass c
and i
as individual arguments but not when I pass it is ci
.
However, if you see below translation is same.
gcp() {
local -A translation=(
[c]=compute
[i]=instances
[ci]="compute instances"
)
stg="stg-proj-12911"
tst="tst-proj-1797"
prd="prd-proj-817"
local -a args
for arg in "$@"; do
if [[ -v "translation[$arg]" ]]; then
args+=("${translation[$arg]}")
elif [[ -v ${arg} ]]; then
echo "project $arg has been set"
#args+="--project=eval echo \$$arg"
args+="--project=${(e)arg:+\$$arg}"
#statements
else
echo "$arg"
args+=("$arg")
fi
done
echo "${args[@]}"
gcloud "${args[@]}"
}
I get below error when I pass gcp ci list stg
as an argument , however it works fine with gcp c i list stg
ERROR: (gcloud) Invalid choice: 'compute instances'.
Maybe you meant:
gcloud compute instances
could it be because compute instances
is being passed as a single argument to gcloud
rather than two ?