diff options
Diffstat (limited to 'cac')
-rwxr-xr-x | cac | 75 |
1 files changed, 20 insertions, 55 deletions
@@ -214,17 +214,7 @@ __cac_cli__powerop() {( reply=$(_cac_post_api_v1 powerop sid="$sid" action="$action") - case $(echo $reply | jq -r .status) in - ok) - echo $reply | jq -r . >&2 - __cac_cli__update - ;; - *) - echo bad reply: >&2 - echo $reply | jq -r . >&2 - exit 23 - ;; - esac + _cac_handle_reply 'cac powerop' "$reply" )} #? cac pushconfig SERVERSPEC [PREFIX=/] @@ -265,17 +255,7 @@ __cac_cli__setlabel() {( reply=$(_cac_post_api_v1 renameserver sid="$sid" name="$label") - case $(echo $reply | jq -r .status) in - ok) - echo $reply | jq -r . >&2 - __cac_cli__update - ;; - *) - echo bad reply: >&2 - echo $reply | jq -r . >&2 - exit 23 - ;; - esac + _cac_handle_reply 'cac setlabel' "$reply" )} #? cac setmode SERVERSPEC (normal|safe) @@ -288,17 +268,7 @@ __cac_cli__setmode() {( reply=$(_cac_post_api_v1 runmode sid="$sid" mode="$mode") - case $(echo $reply | jq -r .status) in - ok) - echo $reply | jq -r . >&2 - __cac_cli__update - ;; - *) - echo bad reply: >&2 - echo $reply | jq -r . - exit 23 - ;; - esac + _cac_handle_reply 'cac setmode' "$reply" )} #? cac ssh SERVERSPEC @@ -379,17 +349,7 @@ __cac_cli__build() {( os="$os" \ ) - case $(echo $reply | jq -r .status) in - ok) - echo $reply | jq -r . >&2 - __cac_cli__update - ;; - *) - echo bad reply: >&2 - echo $reply | jq -r . >&2 - exit 23 - ;; - esac + _cac_handle_reply 'cac build' "$reply" )} #? cac delete SERVERSPEC @@ -401,17 +361,7 @@ __cac_cli__delete() {( reply=$(_cac_post_api_v1 cloudpro/delete sid="$sid") - case $(echo $reply | jq -r .status) in - ok) - echo $reply | jq -r . >&2 - __cac_cli__update - ;; - *) - echo bad reply: >&2 - echo $reply | jq -r . >&2 - exit 23 - ;; - esac + _cac_handle_reply 'cac delete' "$reply" )} @@ -494,7 +444,22 @@ pushdir() { +_cac_handle_reply() {( + label=$1 + reply=$2 + case $(echo $reply | jq -r .status) in + ok) + echo $reply | jq -r . >&2 + __cac_cli__update + ;; + *) + echo $label: bad reply: >&2 + echo $reply | jq -r . >&2 + exit 23 + ;; + esac +)} _cac_get_api_v1() { |