diff --git a/src/atoss_cli/cli.clj b/src/atoss_cli/cli.clj new file mode 100644 index 0000000..3b1a189 --- /dev/null +++ b/src/atoss_cli/cli.clj @@ -0,0 +1,48 @@ +(ns atoss-cli.cli + (:require [atoss-cli.atoss :refer [valid-day-codes]]) + (:import (java.text SimpleDateFormat) + (java.util Date))) + +(def today-date (.format + (SimpleDateFormat. "dd.MM.yyyy") + (new Date))) + +(def desc "ATOSS CLI by Platogo Interactive Entertainment Gmbh. +Work seamlessly with ATOSS time sheets.") + +(def help-header " +\033[1;37mUSAGE\u001b[0m + atoss-cli [args] + +\033[1;37mCOMMANDS\u001b[0m + log: Log time pair for today or a specific date + view: View month overview of logged time") + +(def options + ;; An option with a required argument + [["-d" "--date DATE" "Date in the format DD.MM.YYYY" + :default today-date] ;; FIXME: Add validation + ["-c" "--day-code CODE" "Valid ATOSS day code (e.g. wh for WFH) can also be left blank." + :default nil + :validate [#(contains? valid-day-codes %) "Must be a valid ATOSS time code."]] + ["-s" "--start-time TIME" "Work start time in the format HH:MM" + :default "9:00"] + ["-e" "--end-time TIME" "Work end time in the format HH:MM" + :default "17:00"] + ;; A non-idempotent option (:default is applied first) + ["-v" nil "Verbosity level" + :id :verbosity + :default 0 + :update-fn inc] + ;; A boolean option defaulting to nil + ["-h" "--help" "Show this help printout." + :default false]]) + +(defn print-help + [args-summary] + (print desc) + (newline) + (print help-header) + (newline) + (newline) + (print args-summary)) diff --git a/src/atoss_cli/core.clj b/src/atoss_cli/core.clj index 90fbf2c..e81320e 100644 --- a/src/atoss_cli/core.clj +++ b/src/atoss_cli/core.clj @@ -1,54 +1,11 @@ (ns atoss-cli.core "Entrypoint module for the ATOSS CLI." (:require [clojure.tools.cli :refer [parse-opts]] - [atoss-cli.atoss :as atoss]) - (:import (java.util Date Collection) [java.text SimpleDateFormat]) + [atoss-cli.atoss :as atoss] + [atoss-cli.cli :as cli]) + (:import (java.util Collection)) (:gen-class)) -(def today-date (.format - (SimpleDateFormat. "dd.MM.yyyy") - (new Date))) - -(def desc "ATOSS CLI by Platogo Interactive Entertainment Gmbh. -Work seamlessly with ATOSS time sheets.") - -(def help-header " -\033[1;37mUSAGE\u001b[0m - atoss-cli [args] - -\033[1;37mCOMMANDS\u001b[0m - log: Log time pair for today or a specific date - view: View month overview of logged time") - -(def cli-options - ;; An option with a required argument - [["-d" "--date DATE" "Date in the format DD.MM.YYYY" - :default today-date] ;; FIXME: Add validation - ["-c" "--day-code CODE" "Valid ATOSS day code (e.g. wh for WFH) can also be left blank." - :default nil - :validate [#(contains? atoss/valid-day-codes %) "Must be a valid ATOSS time code."]] - ["-s" "--start-time TIME" "Work start time in the format HH:MM" - :default "9:00"] - ["-e" "--end-time TIME" "Work end time in the format HH:MM" - :default "17:00"] - ;; A non-idempotent option (:default is applied first) - ["-v" nil "Verbosity level" - :id :verbosity - :default 0 - :update-fn inc] - ;; A boolean option defaulting to nil - ["-h" "--help" "Show this help printout." - :default false]]) - -(defn -print-help - [args-summary] - (print desc) - (newline) - (print help-header) - (newline) - (newline) - (print args-summary)) - (defn log-time "Log a time pair for a given day." [{opts :options}] @@ -84,10 +41,10 @@ Work seamlessly with ATOSS time sheets.") (let [{^Collection arguments :arguments summary :summary, options :options, - :as opts} (parse-opts args cli-options)] + :as opts} (parse-opts args cli/options)] (cond - (options :help) (-print-help summary) + (options :help) (cli/print-help summary) (= (first arguments) "view") (show-month-overview) (= (first arguments) "log") (log-time opts) - :else (-print-help summary)) + :else (cli/print-help summary)) (flush)))