From 01ffc7bedf4d07bb2817c999384db54dbb950aa7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 19 Apr 2018 20:51:42 +0200 Subject: Set `$CACHE_FILE` in `preflight()` We had initialised the `$CACHE_FILE` variable at the start of the script, but because at that point `$GITHUB_OWNER_REPO` is empty, the cache file just ends up getting called ".json". In order to get the name we want, we need to wait until the `$GITHUB_OWNER_REPO` variable is initialised by the command line argument. Initialise `$CACHE_FILE` in `preflight()` because it makes sense to put it in that kind of setup function. Move `preflight()` after `parse_arguments()` to ensure the program variables (including `$GITHUB_OWNER_REPO`) are properly validated and initialised before running setup code. --- redprine | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/redprine b/redprine index 8580479..d02864e 100755 --- a/redprine +++ b/redprine @@ -17,7 +17,7 @@ REDMINE_JSON_PARAMS='' XDG_DATA_HOME=${XDG_DATA_HOME:-"${HOME}/.local/share"} REDPRINE_DATA_DIR=${REDPRINE_DATA_DIR:-"${XDG_DATA_HOME}/redprine"} -CACHE_FILE="${REDPRINE_DATA_DIR}/${GITHUB_OWNER_REPO/\//--}.json" +CACHE_FILE='' CACHE_ONLY=0 @@ -207,6 +207,8 @@ function exit_with_error () { function preflight () { mkdir -p "$REDPRINE_DATA_DIR" + CACHE_FILE="${REDPRINE_DATA_DIR}/${GITHUB_OWNER_REPO/\//--}.json" + if [ ! -f "$CACHE_FILE" ]; then echo '[]' > "$CACHE_FILE" fi @@ -333,6 +335,6 @@ function parse_arguments () { } -preflight parse_arguments "$@" +preflight main -- cgit v1.2.3