From 7378d1390b43b4846b25bb26b8a3168dfea56938 Mon Sep 17 00:00:00 2001 From: Robby Stokoe Date: Tue, 28 Aug 2018 07:57:37 -0600 Subject: [PATCH 1/4] Look for credentials in a configuration file --- bee | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bee b/bee index f112182..85e0f45 100755 --- a/bee +++ b/bee @@ -1,8 +1,6 @@ #! /bin/bash base='https://www.beeminder.com/api/v1/' -# user='' -# key='' goal=$1 date=$2 @@ -69,17 +67,29 @@ function goal_status() { curl -s "${base}users/${user}/goals/${goal}.json?auth_token=${key}" |sed 's/^.*\"headsum\":\"\([^"]*\)\".*$/\1\n/' } +function get_credentials() { + if [[ -e ~/.beeminder ]] + then + . ~/.beeminder + else + echo "Credential file ~/.beeminder not found" >&2 + exit 5 + fi +} + case $# in 3|4 ) # submit data point check_data process_date + get_credentials check_goal submit exit 0 ;; 1 ) # get goal status + get_credentials check_goal goal_status ;; From b7223666f9539fc402b71ba0802a7421a66fc54d Mon Sep 17 00:00:00 2001 From: Robby Stokoe Date: Tue, 28 Aug 2018 08:03:23 -0600 Subject: [PATCH 2/4] Rearrange error messages so they still descend --- bee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bee b/bee index 85e0f45..c53664d 100755 --- a/bee +++ b/bee @@ -12,7 +12,7 @@ function check_data() { if [[ ! $data =~ ^-?[0-9]+(\.[0-9]+)?$ ]] then echo "data must be a number" >&2 - exit 3 + exit 4 fi } @@ -37,7 +37,7 @@ else if [[ $? != 0 ]] then # invalid date - exit 2 + exit 3 fi fi } @@ -73,7 +73,7 @@ function get_credentials() { . ~/.beeminder else echo "Credential file ~/.beeminder not found" >&2 - exit 5 + exit 2 fi } @@ -96,6 +96,6 @@ case $# in * ) # wrong number of arguments echo "Usage: $(basename $0) [comment]" >&2 - exit 4 + exit 5 ;; esac From 387471eee9b09c8b5a268c888b532b7bb990ced6 Mon Sep 17 00:00:00 2001 From: Robby Stokoe Date: Tue, 28 Aug 2018 08:11:37 -0600 Subject: [PATCH 3/4] Document configuration file & format in readme --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 60d732f..db2cd15 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,19 @@ Tells when datapoint has been created. `` should be the day of the month or `^` for today. Multiple `^` (e.g. `^^` for yesterday) are not supported. +### Configuration File +The username and API key to be used for the transaction +should be stored in a configuration file, `~/.beeminder` by default. +The format should be a shell script which puts the credentials in the variables +`key`, and `user`. +e.g. +``` +# ~/.beeminder +------ +user='some_user_name' +key='Jqt6szDj5WJfm2YyBANU' +``` + ### Viewing goal status ``` > bee From a519a55e321eafb8ee07eb5d34f1cd09a376a27f Mon Sep 17 00:00:00 2001 From: Robby Stokoe Date: Tue, 28 Aug 2018 08:11:51 -0600 Subject: [PATCH 4/4] Update error table to reflect rearrangement --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index db2cd15..9748015 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,10 @@ Exit status | Meaning ----------: | :--------- 0 | Everything went properly 1 | Goal not found -2 | Invalid day argument -3 | Datum is not a number -4 | Wrong number of arguments +2 | Configuration file not found +3 | Invalid day argument +4 | Datum is not a number +5 | Wrong number of arguments Errors are checked in descending order, so if multiple errors exist, the largest exit status takes precedence.