diff options
author | Julio Capote <jcapote@gmail.com> | 2022-08-21 01:46:13 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2022-08-21 01:46:13 +0000 |
commit | bfec59e271a9c95f6ab755cc6d6795b4012bb62b (patch) | |
tree | 842d27129b7bc130cf7c4f7f82214e643daca367 /libexec/recit-add-entry | |
parent | a768fe79588068444003148eb92165084968fa8c (diff) | |
download | recit-bfec59e271a9c95f6ab755cc6d6795b4012bb62b.tar.gz |
rename open-projects to projects, add FK constraint
Diffstat (limited to '')
-rwxr-xr-x | libexec/recit-add-entry | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/libexec/recit-add-entry b/libexec/recit-add-entry index ae0be2f..7cb5bb7 100755 --- a/libexec/recit-add-entry +++ b/libexec/recit-add-entry @@ -8,21 +8,42 @@ source lib/loader recfile=$(load_recit) -uuid=$(uuidgen) - notes="" query_time="" +project="" + +while getopts "p:m:t:" options; do + + case "${options}" in + p) + project=${OPTARG} + ;; + m) + notes=${OPTARG} + ;; + t) + query_time=${OPTARG} + ;; + :) + echo "Error: -${OPTARG} requires an argument." + exit 1 + ;; + *) + exit 1 + ;; + esac +done + +uuid=$(uuidgen) -if [[ -z "$1" ]]; then +if [[ "$query_time" = "" ]]; then query_time="now" -else - query_time="$1" fi -if [[ -z "$2" ]]; then +if [[ "$notes" = "" ]]; then if [[ -z ${EDITOR+x} ]]; then - echo "$EDITOR is not defined please pass a message" + echo "$EDITOR is not defined please pass a message with -m" exit 1 fi @@ -30,8 +51,6 @@ if [[ -z "$2" ]]; then command $EDITOR "$tmpfile" notes=$(cat "$tmpfile") rm "$tmpfile" -else - notes=$2 fi if [[ "$query_time" == "now" || "$query_time" == "today" ]]; then @@ -42,5 +61,15 @@ else fmt_date=$query_time fi -recins --verbose -f Id -v "$uuid" -f Time -v "$fmt_date" -f Notes -v "$notes" -t Entry "${recfile}" -echo "$uuid"
\ No newline at end of file +if [[ "$project" = "" ]]; then + recins --verbose -f Id -v "$uuid" -f Time -v "$fmt_date" -f Notes -v "$notes" -t Entry "${recfile}" + echo "$uuid" +else + if recsel -t Project -p Id ${recfile} | grep "$project" > /dev/null; then + recins --verbose -f Id -v "$uuid" -f Time -v "$fmt_date" -f Notes -v "$notes" -f ProjectRef -v "$project" -t Entry "${recfile}" + echo "$uuid" + else + echo "$project not found, list of available projects:" + recsel -t Project -p Id ${recfile} + fi +fi
\ No newline at end of file |