echo "Generates input for ledger-cli time tracking"
echo -e "\nUsage: time COMMAND [options] [arguments] \n"
echo "Commands:"
echo " in - starts a new time entry"
echo " out - completes an old time entry"
echo " bal - outputs current timesheet"
echo ""
echo "Options:"
echo " -h --help - prints this help message (if one of commands is passed, prints help message for that command)"
echo " -v --verbose - enables verbose logging"
if [ ! -z "$1" ]; then
exit 1
fi
}
usage_in () {
echo "Time In"
echo "Starts a new time entry - requires a project"
echo -e "\nUsage: time in [options] <project> [<comment>] \n"
echo "Arguments:"
echo " project - name of project tracking time to"
echo " comment - additional information - optional"
echo ""
echo "Options:"
echo " -h --help - prints this help message"
echo " -v --verbose - enables verbose logging"
echov "Examples:"
echov " > time in project:test"
echov ""
echov " > time in project:test parsing"
}
usage_out () {
echo "Time Out"
echo "Stops an existing time entry - requires a project"
echo -e "\nUsage: time out [options] <project>\n"
echo "Arguments:"
echo " project - name of project tracking time to"
echo ""
echo "Options:"
echo " -h --help - prints this help message"
echo " -v --verbose - enables verbose logging"
echov "Examples:"
echov " > time out project:test"
}
usage_bal () {
echo "Time balance"
echo "Prints out current timesheet - takes in a project optionally"
echo -e "\nUsage: time bal [options] <project> \n"
echo "Arguments:"
echo " project - name of project to get balance of"
echo ""
echo "Options:"
echo " -h --help - prints this help message"
echo " -v --verbose - enables verbose logging"
echov "Examples:"
echov " > time bal project:test"
}
POSITIONAL=()
HELP=0
VERBOSE=0
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h|--help)
HELP=1
shift # past argument
;;
-v|--verbose)
VERBOSE=1
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
COMMAND="${POSITIONAL[0]}"
echov "Detected command: $COMMAND"
if [ $HELP -eq 1 ]; then
usage $COMMAND
exit 0
fi
PROJECT="${POSITIONAL[1]}"
COMMENT="${POSITIONAL[2]}"
echov "Project: $PROJECT"
echov "Comment: $COMMENT"
if [ -z "$TIMESHEET_LEDGER_HOME" ]; then
echo "TIMESHEET_LEDGER_HOME variable not defined. It must point to a directory that hosts your main.journal as well as timesheets/ directory with yearly .journal files (e.g. timesheets/2023.journal)"