Skip to content

Commit 0a02ff2

Browse files
committed
implement full working first version
1 parent 481769e commit 0a02ff2

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: clojure

src/jlog/core.clj

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
(ns jlog.core
22
(:require [clojure.string :as str])
3+
(:require [clojure.java.shell :only [sh]])
34
(:gen-class))
45

6+
(use '[clojure.java.shell :only [sh]])
7+
58
(defn has-length?
69
"Checks if a list or string is of length n."
710
[args-list n]
@@ -37,7 +40,23 @@
3740
(str/replace timelog "h" "h ")
3841
timelog)))
3942

43+
(defn jar-path
44+
"utility function to get the jar path without the jar file."
45+
[& [ns]]
46+
(str/replace (-> (or ns (class *ns*))
47+
.getProtectionDomain .getCodeSource .getLocation .getPath) #"[^/]+$" ""))
48+
49+
(def jira-issue
50+
(future
51+
(let [out (:out (sh "hg" "branch"))]
52+
(if-not (str/blank? out)
53+
(re-find #"[a-zA-Z]{3,4}-\d{1,4}" out)
54+
(throw (Exception. "Cannot retrieve your current branch. Make sure you are in a repository's."))))))
55+
4056
(defn -main [& args]
4157
(if (valid-jlog-args-list? (get-two-args args))
42-
(spit "jlog.txt" (str (.format (java.text.SimpleDateFormat. "MM/dd/yyyy") (new java.util.Date)) " --- " (space-hrs&mins (second args)) "\n") :append true)
43-
(println "Invalid syntax. Run jlog with 'jlog -t 1h'")))
58+
(spit (str (jar-path) "jlog.txt") (str @jira-issue " --- " (.format (java.text.SimpleDateFormat. "MM/dd/yyyy") (new java.util.Date)) " --- " (space-hrs&mins (second args)) "\n") :append true)
59+
(println "Invalid syntax. Run jlog with 'jlog -t 1h'"))
60+
)
61+
62+

0 commit comments

Comments
 (0)