Skip to content

Commit 01c8f0d

Browse files
committed
help text
1 parent adefdf8 commit 01c8f0d

File tree

2 files changed

+58
-32
lines changed

2 files changed

+58
-32
lines changed

src/alda/cli.clj

+57-31
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
(ns alda.cli
2-
(:require [boot.cli :refer (defclifn)]
3-
[boot.core :refer (merge-env!)]
4-
[alda.parser :refer (parse-input)]
5-
[alda.repl]))
2+
(:require [boot.cli :refer (defclifn)]
3+
[boot.core :refer (merge-env!)]
4+
[clojure.string :as str]
5+
[alda.parser :refer (parse-input)]
6+
[alda.repl]
7+
[alda.version :refer (-version-)]))
68

79
(defn fluid-r3!
810
"Fetches FluidR3 dependency and returns the input stream handle."
@@ -13,24 +15,26 @@
1315
(require '[midi.soundfont.fluid-r3 :as fluid-r3])
1416
fluid-r3/sf2)))
1517

16-
(defclifn parse
18+
(defclifn ^:alda-task parse
1719
"Parse some Alda code and print the results to the console."
18-
[f file FILE str "The path to a file containing Alda code."
19-
c code CODE str "A string of Alda code."
20+
[f file FILE str "The path to a file containing Alda code to parse."
21+
c code CODE str "The string of Alda code to parse."
2022
l lisp bool "Parse into alda.lisp code."
2123
m map bool "Evaluate the score and show the resulting instruments/events map."]
22-
(let [alda-lisp-code (parse-input (if code code (slurp file)))]
23-
(when lisp
24-
(prn alda-lisp-code))
25-
(when map
26-
(require 'alda.lisp)
27-
(println)
28-
(prn (eval alda-lisp-code)))))
24+
(if-not (or file code)
25+
(parse "--help")
26+
(let [alda-lisp-code (parse-input (if code code (slurp file)))]
27+
(when lisp
28+
(prn alda-lisp-code))
29+
(when map
30+
(require 'alda.lisp)
31+
(println)
32+
(prn (eval alda-lisp-code))))))
2933

30-
(defclifn play
34+
(defclifn ^:alda-task play
3135
"Parse some Alda code and play the resulting score."
32-
[f file FILE str "The path to a file containing Alda code."
33-
c code CODE str "A string of Alda code."
36+
[f file FILE str "The path to a file containing Alda code to play."
37+
c code CODE str "The string of Alda code to play."
3438
; TODO: implement smart buffering and remove the buffer options
3539
p pre-buffer MS int "The number of milliseconds of lead time for buffering. (default: 0)"
3640
P post-buffer MS int "The number of milliseconds to keep the synth open after the score ends. (default: 1000)"
@@ -42,13 +46,15 @@
4246
alda.sound/*play-opts* {:pre-buffer (or pre-buffer 0)
4347
:post-buffer (or post-buffer 1000)
4448
:one-off? true}]
45-
(let [parsed (parse-input (if code code (slurp file)))]
46-
(if (instaparse.core/failure? parsed)
47-
(prn parsed)
48-
(alda.sound/play! (eval parsed)))
49-
identity)))
49+
(if-not (or file code)
50+
(play "--help")
51+
(let [parsed (parse-input (if code code (slurp file)))]
52+
(if (instaparse.core/failure? parsed)
53+
(prn parsed)
54+
(alda.sound/play! (eval parsed)))
55+
identity))))
5056

51-
(defclifn alda-repl
57+
(defclifn ^:alda-task repl
5258
"Starts an Alda Read-Evaluate-Play-Loop."
5359
[p pre-buffer MS int "The number of milliseconds of lead time for buffering. (default: 0)"
5460
P post-buffer MS int "The number of milliseconds to wait after the score ends. (default: 0)"
@@ -61,21 +67,41 @@
6167

6268
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6369

70+
(def alda-tasks
71+
(-> (into {}
72+
(for [[sym var] (ns-publics *ns*)
73+
:when (:alda-task (meta var))
74+
:let [doc (:doc (meta var))
75+
help-blurb (apply str (take-while (partial not= \newline) doc))]]
76+
[sym help-blurb]))
77+
(merge {'help "Display this help text."
78+
'version "Display Alda version number."})))
79+
6480
(def help-text
65-
"alda help text - TODO")
81+
(format (str "alda v%s\n\nUsage:\n\n alda <task> <options>\n\n"
82+
"To see options for a task:\n\n alda <task> --help\n\n"
83+
"Tasks:\n\n%s")
84+
-version-
85+
(str/join \newline
86+
(for [[task blurb] alda-tasks]
87+
(str " " task \tab blurb)))))
6688

6789
(defn- delegate
6890
[cmd args]
6991
(if (empty? args)
70-
(cmd "--help")
92+
(cmd "")
7193
(apply cmd args)))
7294

7395
(defn -main [& [cmd & args]]
7496
(case cmd
75-
nil (println help-text)
76-
"help" (println help-text)
77-
"--help" (println help-text)
78-
"parse" (delegate parse args)
79-
"play" (delegate play args)
80-
"repl" (delegate alda-repl args)
97+
nil (println help-text)
98+
"help" (println help-text)
99+
"--help" (println help-text)
100+
"-h" (println help-text)
101+
"version" (printf "alda v%s\n" -version-)
102+
"--version" (printf "alda v%s\n" -version-)
103+
"-v" (printf "alda v%s\n" -version-)
104+
"parse" (delegate parse args)
105+
"play" (delegate play args)
106+
"repl" (delegate repl args)
81107
(printf "[alda] Invalid command '%s'.\n\n%s\n" cmd)))

src/alda/version.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
(ns alda.version)
22

3-
(def ^:const -version- "0.4.0")
3+
(def ^:const -version- "0.4.1")
44

0 commit comments

Comments
 (0)