Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added package tasks intial one

  • Loading branch information...
commit c3cca8f7a634c3283e7a14cf570ca2eb4d09f69c 1 parent 9c95c07
Siva Jagadeesan authored
23 src/bob/core.clj
... ... @@ -1,5 +1,6 @@
1 1 (ns bob.core
2 2 (:gen-class)
  3 + (:use [bob.utils.ns :only [namespaces-matching]])
3 4 (:require [clojure.contrib.string :as contrib-str]))
4 5
5 6 (defn exit
@@ -16,18 +17,12 @@
16 17 (defn task-not-found [& _]
17 18 (abort "That's not a task. Use \"bob help\" to list all tasks."))
18 19
19   -(defn resolve-task1
20   - ([task not-found]
21   - (let [task-ns (symbol (str "bob.tasks." task))
22   - task (symbol task)]
23   - (try
24   - (when-not (find-ns task-ns)
25   - (require task-ns))
26   - (or (ns-resolve task-ns task)
27   - not-found)
28   - (catch java.io.FileNotFoundException e
29   - not-found))))
30   - ([task] (resolve-task1 task #'task-not-found)))
  20 +(defn require-task [task-ns]
  21 + (when-not (find-ns task-ns)
  22 + (require task-ns)))
  23 +
  24 +(defn require-tasks []
  25 + (doall (map require-task (namespaces-matching "bob.tasks"))))
31 26
32 27 (defn resolve-task
33 28 ([task-name not-found]
@@ -35,8 +30,7 @@
35 30 (let [task-ns (symbol (str "bob.tasks." nz-name))
36 31 task (symbol task)]
37 32 (try
38   - (when-not (find-ns task-ns)
39   - (require task-ns))
  33 + (require-task task-ns)
40 34 (or (ns-resolve task-ns task)
41 35 not-found)
42 36 (catch java.io.FileNotFoundException e
@@ -50,6 +44,7 @@
50 44
51 45 (defn -main
52 46 ([& [task-name & args]]
  47 + (require-tasks)
53 48 (let [task-name (or task-name "bob:help")]
54 49 (let [value (apply-task task-name args task-not-found)]
55 50 (when (integer? value)
30 src/bob/tasks/bob.clj
... ... @@ -0,0 +1,30 @@
  1 +(ns bob.tasks.bob
  2 + (:use [clojure.contrib.duck-streams :only [reader writer with-out-writer]]
  3 + [bob.utils.ns :only [namespaces-matching tasks-in ns-last-str]]))
  4 +
  5 +(def tasks (->> (namespaces-matching "bob.tasks")
  6 + (distinct)
  7 + (sort)))
  8 +
  9 +(defn help-string [task-ns]
  10 + (map #(let [m (meta %)] (str (ns-last-str %) ":" (:name m) " -- " (:doc m)))
  11 + (tasks-in task-ns)))
  12 +
  13 +
  14 +(defn help
  15 + "Prints help"
  16 + {:task true}
  17 + []
  18 + (println "I am Bob - I am always eager to impress and help team on projects")
  19 + (println "I can do these following tasks to help you")
  20 + (println "")
  21 + (println "Main Tasks")
  22 + (println "----------")
  23 + (doseq [task-ns tasks]
  24 + (doall (map println (help-string task-ns))))
  25 +
  26 + (println "")
  27 + (println "Tasks from installed Packages")
  28 + (println "-----------------------------")
  29 + (println "")
  30 + (println "Fire me up !!!"))
7 src/bob/tasks/package.clj
... ... @@ -0,0 +1,7 @@
  1 +(ns bob.tasks.package)
  2 +
  3 +(defn new
  4 + "ok da"
  5 + {:task true}
  6 + [name]
  7 + (println "Ok creating new package :" name))

0 comments on commit c3cca8f

Please sign in to comment.
Something went wrong with that request. Please try again.