From 535aba7d41d82597471988fd847b496014c24344 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 27 Jan 2018 18:02:01 +0100 Subject: harvester: Construct arguments to 'hcl' Add a new function `hcl_log` that turns the project, time, date, and description arguments into the format the 'hcl' program expects. --- harvester | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/harvester b/harvester index f585026..fdf51ee 100755 --- a/harvester +++ b/harvester @@ -14,6 +14,31 @@ Flags: __EOF__ } +function error_flag () { + local flag="$1" + + echo "harvester: error: required flag $flag not provided, try --help" + + exit 1 +} + +function hcl_log () { + local project="$1" + local time="$2" + local date="$3" + local description="$4" + + if [ -z "$project" ]; then + error_flag '--project' + fi + + if [ ! -z "$time" ]; then + time="+${time}" + fi + + echo "${date} @${project} ${time} ${description}" +} + function main () { local project='' local time='' @@ -82,7 +107,7 @@ function main () { esac done - echo "Project '$project'; Time '$time'; Date '$date'; Description '$description'" + hcl_log "$project" "$time" "$date" "$description" } main "$@" -- cgit v1.2.3