mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-04-10 04:26:17 +02:00
fix(juju): plugin utilities
- Respect $JUJU_DATA env var in jcontroller() and jmodel() - Fix missing `local controller` declaration in jclean() - Fix jmodel() to handle controller names with special chars and "null" yq output - Change wjst() default poll interval from 5s to 1s
This commit is contained in:
parent
806f1a0ed3
commit
c4c34b1446
1 changed files with 15 additions and 8 deletions
|
|
@ -134,6 +134,7 @@ jclean() {
|
|||
fi
|
||||
|
||||
echo
|
||||
local controller
|
||||
for controller in ${=controllers}; do
|
||||
timeout 2m juju destroy-controller --destroy-all-models --destroy-storage --force --no-wait -y $controller
|
||||
timeout 2m juju kill-controller -y -t 0 $controller 2>/dev/null
|
||||
|
|
@ -167,10 +168,11 @@ jreld() {
|
|||
|
||||
# Return Juju current controller
|
||||
jcontroller() {
|
||||
local controller="$(awk '/current-controller/ {print $2}' ~/.local/share/juju/controllers.yaml)"
|
||||
if [[ -z "$controller" ]]; then
|
||||
return 1
|
||||
fi
|
||||
local file=${JUJU_DATA:=~/.local/share/juju}/controllers.yaml
|
||||
[[ -f "$file" ]] || return 1
|
||||
|
||||
local controller="$(awk '/current-controller/ {print $2}' "$file")"
|
||||
[[ -z "$controller" ]] && return 1
|
||||
|
||||
echo $controller
|
||||
return 0
|
||||
|
|
@ -178,6 +180,9 @@ jcontroller() {
|
|||
|
||||
# Return Juju current model
|
||||
jmodel() {
|
||||
local file=${JUJU_DATA:=~/.local/share/juju}/models.yaml
|
||||
[[ -f "$file" ]] || return 1
|
||||
|
||||
local yqbin="$(whereis yq | awk '{print $2}')"
|
||||
|
||||
if [[ -z "$yqbin" ]]; then
|
||||
|
|
@ -185,9 +190,10 @@ jmodel() {
|
|||
return 1
|
||||
fi
|
||||
|
||||
local model="$(yq e ".controllers.$(jcontroller).current-model" < ~/.local/share/juju/models.yaml | cut -d/ -f2)"
|
||||
local controller="$(jcontroller)"
|
||||
local model="$(yq e ".controllers.[\"${controller}\"].current-model" < "${file}" | cut -d/ -f2)"
|
||||
|
||||
if [[ -z "$model" ]]; then
|
||||
if [[ -z "$model" || $model == "null" ]]; then
|
||||
echo "--"
|
||||
return 1
|
||||
fi
|
||||
|
|
@ -196,9 +202,10 @@ jmodel() {
|
|||
return 0
|
||||
}
|
||||
|
||||
# Watch juju status, with optional interval (default: 5 sec)
|
||||
# Watch juju status, with optional interval (default: 1 sec)
|
||||
wjst() {
|
||||
local interval="${1:-5}"
|
||||
command -v juju >/dev/null 2>&1 || return 1
|
||||
local interval="${1:-1}"
|
||||
shift $(( $# > 0 ))
|
||||
watch -n "$interval" --color juju status --relations --color "$@"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue