:task/args
This commit is contained in:
parent
6abe9a6851
commit
4617076104
2 changed files with 31 additions and 31 deletions
|
|
@ -558,10 +558,10 @@ Use -- to separate script command line args from bb command line args.
|
||||||
(defn resolve-task [task {:keys [:command-line-args]}]
|
(defn resolve-task [task {:keys [:command-line-args]}]
|
||||||
(case (:task/type task)
|
(case (:task/type task)
|
||||||
:babashka
|
:babashka
|
||||||
(let [cmd-line-args (get task :args)]
|
(let [cmd-line-args (get task :task/args)]
|
||||||
(parse-opts (seq (map str (concat cmd-line-args command-line-args)))))
|
(parse-opts (seq (map str (concat cmd-line-args command-line-args)))))
|
||||||
:shell
|
:shell
|
||||||
(let [args (get task :args)
|
(let [args (get task :task/args)
|
||||||
args (into (vec args) command-line-args)]
|
args (into (vec args) command-line-args)]
|
||||||
{:exec (fn []
|
{:exec (fn []
|
||||||
[nil
|
[nil
|
||||||
|
|
@ -570,7 +570,7 @@ Use -- to separate script command line args from bb command line args.
|
||||||
:exit)])})
|
:exit)])})
|
||||||
:main
|
:main
|
||||||
(let [main-arg (:main task)
|
(let [main-arg (:main task)
|
||||||
cmd-line-args (:args task)]
|
cmd-line-args (:task/args task)]
|
||||||
(parse-opts (seq (map str (concat ["--main" main-arg] cmd-line-args command-line-args)))))
|
(parse-opts (seq (map str (concat ["--main" main-arg] cmd-line-args command-line-args)))))
|
||||||
(error (str "No such task: " (:task/type task)) 1)))
|
(error (str "No such task: " (:task/type task)) 1)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
(deftest babashka-task-test
|
(deftest babashka-task-test
|
||||||
(with-config {:tasks {:sum {:task/type :babashka
|
(with-config {:tasks {:sum {:task/type :babashka
|
||||||
:args ["-e" "(+ 1 2 3)"]}}}
|
:task/args ["-e" "(+ 1 2 3)"]}}}
|
||||||
(let [res (bb :sum)]
|
(let [res (bb :sum)]
|
||||||
(is (= 6 res)))))
|
(is (= 6 res)))))
|
||||||
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
(let [temp-dir (fs/create-temp-dir)
|
(let [temp-dir (fs/create-temp-dir)
|
||||||
temp-file (fs/create-file (fs/path temp-dir "temp-file.txt"))]
|
temp-file (fs/create-file (fs/path temp-dir "temp-file.txt"))]
|
||||||
(with-config {:tasks {:clean {:task/type :shell
|
(with-config {:tasks {:clean {:task/type :shell
|
||||||
:args ["rm" (str temp-file)]}}}
|
:task/args ["rm" (str temp-file)]}}}
|
||||||
(is (fs/exists? temp-file))
|
(is (fs/exists? temp-file))
|
||||||
(bb :clean)
|
(bb :clean)
|
||||||
(is (not (fs/exists? temp-file))))))
|
(is (not (fs/exists? temp-file))))))
|
||||||
|
|
@ -40,11 +40,11 @@
|
||||||
(let [temp-dir (fs/create-temp-dir)
|
(let [temp-dir (fs/create-temp-dir)
|
||||||
temp-file (fs/create-file (fs/path temp-dir "temp-file.txt"))]
|
temp-file (fs/create-file (fs/path temp-dir "temp-file.txt"))]
|
||||||
(with-config {:tasks {:clean {:task/type :shell
|
(with-config {:tasks {:clean {:task/type :shell
|
||||||
:args ["rm" (str temp-file)]}
|
:task/args ["rm" (str temp-file)]}
|
||||||
:sum {:task/type :babashka
|
:sum {:task/type :babashka
|
||||||
:args ["-e" "(+ 1 2 3)"]}
|
:task/args ["-e" "(+ 1 2 3)"]}
|
||||||
:all {:task/type :babashka
|
:all {:task/type :babashka
|
||||||
:args [:do :clean :and-do :sum]}}}
|
:task/args [:do :clean :and-do :sum]}}}
|
||||||
(is (fs/exists? temp-file))
|
(is (fs/exists? temp-file))
|
||||||
(let [res (bb :all)]
|
(let [res (bb :all)]
|
||||||
(is (= 6 res)))
|
(is (= 6 res)))
|
||||||
|
|
@ -53,65 +53,65 @@
|
||||||
(let [temp-dir (fs/create-temp-dir)
|
(let [temp-dir (fs/create-temp-dir)
|
||||||
temp-file (fs/create-file (fs/path temp-dir "temp-file.txt"))]
|
temp-file (fs/create-file (fs/path temp-dir "temp-file.txt"))]
|
||||||
(with-config {:tasks {:clean {:task/type :shell
|
(with-config {:tasks {:clean {:task/type :shell
|
||||||
:args ["rm" (str temp-file)]}
|
:task/args ["rm" (str temp-file)]}
|
||||||
:sum {:task/type :babashka
|
:sum {:task/type :babashka
|
||||||
:args ["-e" "(+ 1 2 3)"]}
|
:task/args ["-e" "(+ 1 2 3)"]}
|
||||||
:all {:task/type :babashka
|
:all {:task/type :babashka
|
||||||
:args [:do :clean :and-do :sum]}}}
|
:task/args [:do :clean :and-do :sum]}}}
|
||||||
(is (fs/exists? temp-file))
|
(is (fs/exists? temp-file))
|
||||||
(let [res (bb :clean:sum)]
|
(let [res (bb :clean:sum)]
|
||||||
(is (= 6 res)))
|
(is (= 6 res)))
|
||||||
(is (not (fs/exists? temp-file)))))))
|
(is (not (fs/exists? temp-file)))))))
|
||||||
(testing ":do always continuing"
|
(testing ":do always continuing"
|
||||||
(with-config {:tasks {:sum-1 {:task/type :babashka
|
(with-config {:tasks {:sum-1 {:task/type :babashka
|
||||||
:args ["-e" "(do (+ 4 5 6) nil)"]}
|
:task/args ["-e" "(do (+ 4 5 6) nil)"]}
|
||||||
:sum-2 {:task/type :babashka
|
:sum-2 {:task/type :babashka
|
||||||
:args ["-e" "(+ 1 2 3)"]}
|
:task/args ["-e" "(+ 1 2 3)"]}
|
||||||
:all {:task/type :babashka
|
:all {:task/type :babashka
|
||||||
:args [:do :sum-1 :do :sum-2]}}}
|
:task/args [:do :sum-1 :do :sum-2]}}}
|
||||||
(is (= 6 (bb :all))))
|
(is (= 6 (bb :all))))
|
||||||
(with-config {:tasks {:div-by-zero {:task/type :babashka
|
(with-config {:tasks {:div-by-zero {:task/type :babashka
|
||||||
:args ["-e" "(/ 1 0)"]}
|
:task/args ["-e" "(/ 1 0)"]}
|
||||||
:sum {:task/type :babashka
|
:sum {:task/type :babashka
|
||||||
:args ["-e" "(+ 1 2 3)"]}
|
:task/args ["-e" "(+ 1 2 3)"]}
|
||||||
:all {:task/type :babashka
|
:all {:task/type :babashka
|
||||||
:args [:do :div-by-zero :do :sum]}}}
|
:task/args [:do :div-by-zero :do :sum]}}}
|
||||||
(is (= 6 (bb :all)))))
|
(is (= 6 (bb :all)))))
|
||||||
(testing ":and-do failing"
|
(testing ":and-do failing"
|
||||||
(with-config {:tasks {:div-by-zero {:task/type :babashka
|
(with-config {:tasks {:div-by-zero {:task/type :babashka
|
||||||
:args ["-e" "(/ 1 0)"]}
|
:task/args ["-e" "(/ 1 0)"]}
|
||||||
:sum {:task/type :babashka
|
:sum {:task/type :babashka
|
||||||
:args ["-e" "(+ 1 2 3)"]}
|
:task/args ["-e" "(+ 1 2 3)"]}
|
||||||
:all {:task/type :babashka
|
:all {:task/type :babashka
|
||||||
:args [:do :div-by-zero :and-do :sum]}}}
|
:task/args [:do :div-by-zero :and-do :sum]}}}
|
||||||
(is (thrown-with-msg? Exception #"Divide"
|
(is (thrown-with-msg? Exception #"Divide"
|
||||||
(bb :all)))))
|
(bb :all)))))
|
||||||
(testing ":or-do short-cutting"
|
(testing ":or-do short-cutting"
|
||||||
(with-config {:tasks {:sum-1 {:task/type :babashka
|
(with-config {:tasks {:sum-1 {:task/type :babashka
|
||||||
:args ["-e" "(+ 1 2 3)"]}
|
:task/args ["-e" "(+ 1 2 3)"]}
|
||||||
:sum-2 {:task/type :babashka
|
:sum-2 {:task/type :babashka
|
||||||
:args ["-e" "(+ 4 5 6)"]}
|
:task/args ["-e" "(+ 4 5 6)"]}
|
||||||
:all {:task/type :babashka
|
:all {:task/type :babashka
|
||||||
:args [:do :sum-1 :or-do :sum-2]}}}
|
:task/args [:do :sum-1 :or-do :sum-2]}}}
|
||||||
(is (= 6 (bb :all)))))
|
(is (= 6 (bb :all)))))
|
||||||
(testing ":or-do succeeding after failing"
|
(testing ":or-do succeeding after failing"
|
||||||
(with-config {:tasks {:div-by-zero {:task/type :babashka
|
(with-config {:tasks {:div-by-zero {:task/type :babashka
|
||||||
:args ["-e" "(/ 1 0)"]}
|
:task/args ["-e" "(/ 1 0)"]}
|
||||||
:sum {:task/type :babashka
|
:sum {:task/type :babashka
|
||||||
:args ["-e" "(+ 1 2 3)"]}
|
:task/args ["-e" "(+ 1 2 3)"]}
|
||||||
:all {:task/type :babashka
|
:all {:task/type :babashka
|
||||||
:args [:do :div-by-zero :or-do :sum]}}}
|
:task/args [:do :div-by-zero :or-do :sum]}}}
|
||||||
(is (= 6 (bb :all))))))
|
(is (= 6 (bb :all))))))
|
||||||
|
|
||||||
(deftest prioritize-user-task-test
|
(deftest prioritize-user-task-test
|
||||||
(is (map? (bb :describe)))
|
(is (map? (bb :describe)))
|
||||||
(with-config {:tasks {:describe {:task/type :babashka
|
(with-config {:tasks {:describe {:task/type :babashka
|
||||||
:args ["-e" "(+ 1 2 3)"]}}}
|
:task/args ["-e" "(+ 1 2 3)"]}}}
|
||||||
(is (= 6 (bb :describe)))))
|
(is (= 6 (bb :describe)))))
|
||||||
|
|
||||||
(deftest help-task-test
|
(deftest help-task-test
|
||||||
(with-config {:tasks {:cool-task {:task/type :babashka
|
(with-config {:tasks {:cool-task {:task/type :babashka
|
||||||
:args ["-e" "(+ 1 2 3)"]
|
:task/args ["-e" "(+ 1 2 3)"]
|
||||||
:task/help "Usage: bb :cool-task
|
:task/help "Usage: bb :cool-task
|
||||||
|
|
||||||
Addition is a pretty advanced topic. Let us start with the identity element
|
Addition is a pretty advanced topic. Let us start with the identity element
|
||||||
|
|
@ -122,7 +122,7 @@ Addition is a pretty advanced topic. Let us start with the identity element
|
||||||
|
|
||||||
(deftest list-tasks-test
|
(deftest list-tasks-test
|
||||||
(with-config {:tasks {:cool-task-1 {:task/type :babashka
|
(with-config {:tasks {:cool-task-1 {:task/type :babashka
|
||||||
:args ["-e" "(+ 1 2 3)"]
|
:task/args ["-e" "(+ 1 2 3)"]
|
||||||
:task/description "Return the sum of 1, 2 and 3."
|
:task/description "Return the sum of 1, 2 and 3."
|
||||||
:task/help "Usage: bb :cool-task
|
:task/help "Usage: bb :cool-task
|
||||||
|
|
||||||
|
|
@ -130,7 +130,7 @@ Addition is a pretty advanced topic. Let us start with the identity element
|
||||||
0. ..."}
|
0. ..."}
|
||||||
:cool-task-2 {:task/type :babashka
|
:cool-task-2 {:task/type :babashka
|
||||||
:task/description "Return the sum of 4, 5 and 6."
|
:task/description "Return the sum of 4, 5 and 6."
|
||||||
:args ["-e" "(+ 4 5 6)"]
|
:task/args ["-e" "(+ 4 5 6)"]
|
||||||
:task/help "Usage: bb :cool-task
|
:task/help "Usage: bb :cool-task
|
||||||
|
|
||||||
Addition is a pretty advanced topic. Let us start with the identity element
|
Addition is a pretty advanced topic. Let us start with the identity element
|
||||||
|
|
@ -145,7 +145,7 @@ Addition is a pretty advanced topic. Let us start with the identity element
|
||||||
(with-config {:paths ["test-resources/task_scripts"]
|
(with-config {:paths ["test-resources/task_scripts"]
|
||||||
:tasks {:main-task {:task/type :main
|
:tasks {:main-task {:task/type :main
|
||||||
:main 'tasks ;; this calls tasks/-main
|
:main 'tasks ;; this calls tasks/-main
|
||||||
:args [1 2 3]}}}
|
:task/args [1 2 3]}}}
|
||||||
(is (= '("1" "2" "3") (bb :main-task)))
|
(is (= '("1" "2" "3") (bb :main-task)))
|
||||||
(let [res (apply test-utils/bb nil
|
(let [res (apply test-utils/bb nil
|
||||||
(map str [:help :main-task]))]
|
(map str [:help :main-task]))]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue