Skip to content

Commit

Permalink
Add option to get cli version
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniils Petrovs committed Oct 1, 2021
1 parent 146b878 commit efc52c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject atoss-cli "0.2.1-SNAPSHOT"
(defproject atoss-cli "0.2.2-SNAPSHOT"
:description "A CLI tool for interacting with ATOSS time sheets"
:url "https://github.com/platogo/atoss-cli"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
Expand Down
18 changes: 16 additions & 2 deletions src/atoss_cli/cli.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
(ns atoss-cli.cli
(:require [atoss-cli.atoss :refer [valid-day-codes]])
(:require
[clojure.java.io :as io]
[atoss-cli.atoss :refer [valid-day-codes]])
(:import (java.text SimpleDateFormat)
(java.util Date)))
(java.util Date Properties)))

(def today-date (.format
(SimpleDateFormat. "dd.MM.yyyy")
Expand All @@ -18,6 +20,13 @@ Work seamlessly with ATOSS time sheets.")
log: Log time pair for today or a specific date
view: View month overview of logged time")

(defn read-project-version []
(-> (doto (Properties.)
(.load (-> "META-INF/maven/atoss-cli/atoss-cli/pom.properties"
(io/resource)
(io/reader))))
(.get "version")))

(def options
;; An option with a required argument
[["-d" "--date DATE" "Date in the format DD.MM.YYYY"
Expand All @@ -34,6 +43,8 @@ Work seamlessly with ATOSS time sheets.")
:id :verbosity
:default 0
:update-fn inc]
[nil "--version" "Print CLI version"
:default false]
;; A boolean option defaulting to nil
["-h" "--help" "Show this help printout."
:default false]])
Expand All @@ -46,3 +57,6 @@ Work seamlessly with ATOSS time sheets.")
(newline)
(newline)
(print args-summary))

(defn print-project-ver []
(println (format "Version: %s" (read-project-version))))
8 changes: 5 additions & 3 deletions src/atoss_cli/core.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
(ns atoss-cli.core
"Entrypoint module for the ATOSS CLI."
(:require [clojure.tools.cli :refer [parse-opts]]
[atoss-cli.atoss :as atoss]
[atoss-cli.cli :as cli])
(:require
[clojure.tools.cli :refer [parse-opts]]
[atoss-cli.atoss :as atoss]
[atoss-cli.cli :as cli])
(:import (java.util Collection))
(:gen-class))

Expand Down Expand Up @@ -43,6 +44,7 @@
options :options,
:as opts} (parse-opts args cli/options)]
(cond
(options :version) (cli/print-project-ver)
(options :help) (cli/print-help summary)
(= (first arguments) "view") (show-month-overview)
(= (first arguments) "log") (log-time opts)
Expand Down

0 comments on commit efc52c4

Please sign in to comment.