diff options
author | makefu <github@syntax-fehler.de> | 2015-11-25 23:09:28 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2015-11-25 23:09:28 +0100 |
commit | d0c3a0b6185df7d473285c68e55815bbe914e659 (patch) | |
tree | cff1999048b7409669fc10f65e38f04a74f8ab37 /cac | |
parent | 55347fef150377a33352168c73a04d5b8c25f343 (diff) |
add always_update
Diffstat (limited to 'cac')
-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 |