diff options
-rwxr-xr-x | cac | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -17,9 +17,10 @@ cac_templates_cache=${cac_templates_cache-$HOME/tmp/cac_templates_cache.json} cac_secrets=${cac_secrets-$HOME/.secrets/cac} _load_secrets() { - if test -e "$cac_secrets" ;then - echo "unable to load secrets from '$cac_secrets'" >&2 - __cac_cli_help + if test ! -r "$cac_secrets" ;then + echo "unable to load secrets from cac_secrets='$cac_secrets'" >&2 + __cac_cli__help + return 1 else . "$cac_secrets" fi @@ -76,10 +77,18 @@ __cac_cli__console() {( _cac_post_api_v1 console sid="$sid" | jq -r .console )} +_maybe_update(){ + + if test ! -r "$1" -o -n "${always_update:-}" ;then + echo "updating cache file" 2>&1 + __cac_cli__update + fi +} #? cac servers #? Print cached servers JSON. #? __cac_cli__servers() { + _maybe_update $cac_servers_cache jq -r . $cac_servers_cache } @@ -87,6 +96,7 @@ __cac_cli__servers() { #? Print cached tasks JSON. #? __cac_cli__tasks() { + _maybe_update $cac_tasks_cache jq -r . $cac_tasks_cache } @@ -94,6 +104,7 @@ __cac_cli__tasks() { #? Print cached templates JSON. #? __cac_cli__templates() { + _maybe_update $cac_templates_cache jq -r . $cac_templates_cache } @@ -101,6 +112,7 @@ __cac_cli__templates() { #? Print CloudPRO resources JSON. #? __cac_cli__resources() { + _maybe_update $cac_resources_cache jq -r . $cac_resources_cache } @@ -141,7 +153,7 @@ __cac_cli__getserver() {( v=${1#*:} ;; esac - + _maybe_update $cac_servers_cache if result=$(jq \ -e \ --arg k "$k" \ @@ -329,6 +341,9 @@ __cac_cli__delete() {( #? cac_tasks_cache=$HOME/tmp/cac_tasks_cache.json #? cac_templates_cache=$HOME/tmp/cac_templates_cache.json #? cac_secrets=$HOME/.secrets/cac +#? run=true < set to false to be able to source this file +#? always_update= < set to true to always update when using cache files +#? #? You can override these by setting them beforehand. #? #? `cac_secrets` will be sourced and may provide the following two entries: @@ -439,7 +454,7 @@ _cac_exec() { } _main() { - _load_secrets + _load_secrets || exit 1 case ${run-true} in true) cac "$@";; esac |