Skip to content

Commit d544191

Browse files
committed
add option to clean file
Some refactoring were also performed to make the code cleaner along the way.
1 parent 0ce5185 commit d544191

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

src/jlog/core.clj

+25-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
(use '[clojure.java.shell :only [sh]])
77

8+
(def jlog-file "jlog.txt")
9+
810
(defn valid-jlog-time?
911
"Checks if the argument provided is of format HhMMm (basic support for JIRA time-log)."
1012
[timelog]
@@ -48,20 +50,27 @@
4850
(.format (java.text.SimpleDateFormat. "MM/dd/yyyy") (new java.util.Date)))
4951

5052
(defn spit-log
51-
"Spits a Jira worklog into a jlog.txt file, containing the date, jira issue key, and message."
53+
"Spits a Jira worklog into the worklogs file, containing the date, jira issue key, and message."
5254
[timelog issue message]
53-
(spit (str (get-jar-root) "jlog.txt")
55+
(spit (str (get-jar-root) jlog-file)
5456
(str (get-date) " --- " issue " *" (space-hrs&mins timelog) "* --- " message "\n")
5557
:append true)
5658
(println "Worklog saved successfully!"))
5759

5860
(defn print-worklogs
59-
"Lists/Prints worklogs contained in the jlog.txt file in the console."
61+
"Lists/Prints worklogs contained in the worklogs file in the console."
62+
[]
63+
(doseq [i ["\n" "Your Jira Worklogs:\n" (slurp (str (get-jar-root) jlog-file))]] (println i)))
64+
65+
(defn clean-worklog-file
66+
"Clean the worklogs file of all existing worklogs."
6067
[]
61-
(doseq [i ["\n" "Your Jira Worklogs:\n" (slurp (str (get-jar-root) "jlog.txt"))]] (println i)))
68+
(do
69+
@(future (sh "rm" (str (get-jar-root) jlog-file)))
70+
@(future (sh "touch" (str (get-jar-root) jlog-file)))))
6271

6372
(defn jlog
64-
"Appends a worklog to a jlog.txt file. This is the jlog main function."
73+
"Appends a worklog to the worklogs file. This is the jlog main function."
6574
[arg1 arg2 message]
6675
(if (= arg1 "-b")
6776
(if (valid-jlog-time? arg2)
@@ -71,23 +80,26 @@
7180
(if (valid-jira-issue? arg2)
7281
(spit-log arg1 (upper-case arg2) message)
7382
(throw (Exception. "Invalid Jira issue key format provided.")))
74-
(throw (Exception. "Invalid timelog format provided."))))
75-
(shutdown-agents))
83+
(throw (Exception. "Invalid timelog format provided.")))))
7684

7785
(defn print-help
7886
"Prints the possible jlog commands to the console."
7987
[]
8088
(println (str "\nValid commands for jlog are:\n\n"
8189
" jlog -h - Prints the help menu to the console.\n"
82-
" jlog -l - Prints worklogs contained in the jlog.txt file to the console.\n"
83-
" jlog -o - Opens your jlog.txt file.\n"
84-
" jlog -b <timelog> <message in quotes> - Writes a worklog to the jlog.txt file, retrieving the issue-key from your branch.\n"
85-
" jlog <timelog> <issue key> <message in quotes> - Writes a worklog to the jlog.txt file using the provided information.\n")))
90+
" jlog -l - Prints worklogs contained in the worklogs file to the console.\n"
91+
" jlog -c - Clean worklogs file from all existing worklogs.\n"
92+
" jlog -o - Opens your worklogs file.\n"
93+
" jlog -b <timelog> <message in quotes> - Writes a worklog to the worklogs file, retrieving the issue-key from your branch.\n"
94+
" jlog <timelog> <issue key> <message in quotes> - Writes a worklog to the worklogs file using the provided information.\n")))
8695

8796
(defn -main [& args]
97+
@(future (sh "touch" (str (get-jar-root) jlog-file)))
8898
(cond
8999
(= "-h" (first args)) (print-help)
90100
(= "-l" (first args)) (print-worklogs)
91-
(= "-o" (first args)) ((sh "open" (str (get-jar-root) "jlog.txt")) (shutdown-agents))
101+
(= "-c" (first args)) (clean-worklog-file)
102+
(= "-o" (first args)) (sh "open" (str (get-jar-root) jlog-file))
92103
(= (count (take 3 args)) 3) (apply jlog (take 3 args))
93-
:else ((println "Syntax error.") (print-help))))
104+
:else ((println "Syntax error.") (print-help)))
105+
(shutdown-agents))
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Leiningen
2-
#Tue Jun 20 23:28:21 EDT 2017
2+
#Thu Jun 20 11:14:17 EDT 2019
33
version=0.1.0-SNAPSHOT
4-
revision=38dd03ffe0ad2693062a5020994a3c823916d3e0\n
4+
revision=0ce5185f96c1bcb421eb86ecba0d9f9b4db27bc8
55
groupId=jlog
66
artifactId=jlog
3.24 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{:dependencies {org.clojure/clojure {:vsn "1.8.0", :native-prefix nil}, compliment {:vsn "0.2.0", :native-prefix nil}, org.clojure/tools.trace {:vsn "0.7.8", :native-prefix nil}, cljs-tooling {:vsn "0.1.3", :native-prefix nil}, org.clojure/tools.namespace {:vsn "0.2.5", :native-prefix nil}, org.clojure/java.classpath {:vsn "0.2.0", :native-prefix nil}, org.clojure/tools.nrepl {:vsn "0.2.12", :native-prefix nil}, clojure-complete {:vsn "0.2.4", :native-prefix nil}, cider/cider-nrepl {:vsn "0.8.1", :native-prefix nil}, org.tcrawley/dynapath {:vsn "0.2.3", :native-prefix nil}}, :native-path "target/native"} {:native-path "target/native", :dependencies {org.clojure/clojure {:vsn "1.8.0", :native-prefix nil, :native? false}, compliment {:vsn "0.2.0", :native-prefix nil, :native? false}, org.clojure/tools.trace {:vsn "0.7.8", :native-prefix nil, :native? false}, cljs-tooling {:vsn "0.1.3", :native-prefix nil, :native? false}, org.clojure/tools.namespace {:vsn "0.2.5", :native-prefix nil, :native? false}, org.clojure/java.classpath {:vsn "0.2.0", :native-prefix nil, :native? false}, org.clojure/tools.nrepl {:vsn "0.2.12", :native-prefix nil, :native? false}, clojure-complete {:vsn "0.2.4", :native-prefix nil, :native? false}, cider/cider-nrepl {:vsn "0.8.1", :native-prefix nil, :native? false}, org.tcrawley/dynapath {:vsn "0.2.3", :native-prefix nil, :native? false}}}]
1+
[{:dependencies {org.clojure/clojure {:vsn "1.8.0", :native-prefix nil}}, :native-path "target/native"} {:native-path "target/native", :dependencies {org.clojure/clojure {:vsn "1.8.0", :native-prefix nil, :native? false}}}]

0 commit comments

Comments
 (0)