From bfec59e271a9c95f6ab755cc6d6795b4012bb62b Mon Sep 17 00:00:00 2001 From: Julio Capote Date: Sat, 20 Aug 2022 21:46:13 -0400 Subject: rename open-projects to projects, add FK constraint --- libexec/recit-add-entry | 51 +++++++++++++++++++++++++++++++++++---------- libexec/recit-open-projects | 8 ------- libexec/recit-projects | 8 +++++++ 3 files changed, 48 insertions(+), 19 deletions(-) delete mode 100755 libexec/recit-open-projects create mode 100755 libexec/recit-projects (limited to 'libexec') 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 diff --git a/libexec/recit-open-projects b/libexec/recit-open-projects deleted file mode 100755 index efb323f..0000000 --- a/libexec/recit-open-projects +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -source lib/loader - -recfile=$(load_recit) - -recsel -t Project ${recfile} - diff --git a/libexec/recit-projects b/libexec/recit-projects new file mode 100755 index 0000000..efb323f --- /dev/null +++ b/libexec/recit-projects @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +source lib/loader + +recfile=$(load_recit) + +recsel -t Project ${recfile} + -- cgit v1.2.3