A peer-to-peer stack for code collaboration
Extract help commands to cmd-parsing (#594)
Merle Breitkreuz6fc62c0970a9
diff --git a/bin/rad-issue b/bin/rad-issueindex dfc75d9..c696382 100755--- a/bin/rad-issue+++ b/bin/rad-issue@@ -160,8 +160,6 @@(/cmd-1 "mark-read" 'n help) (whole-issue-num "mark as read" n (fn [n] (newness/mark-read! (machine-name) n)))(/cmd-1 "mark-unread" 'n help) (whole-issue-num "mark as unread" n (fn [n] (newness/mark-unread! (machine-name) n)))(/cmd-0 "all-read" help) (mark-all-read! (machine-name))- ["help"] (put-str! help)- ["-h"] (put-str! help)- ["--help"] (put-str! help)+ (/cmd-help) (put-str! help)(/cons 'cmd _) (cmd-parse-failure (error/unknown-command cmd))[] (put-str! help))))diff --git a/bin/rad-key b/bin/rad-keyindex af873dc..67e7d6f 100755--- a/bin/rad-key+++ b/bin/rad-key@@ -41,8 +41,6 @@ If you are sure that you want to replace your key pair, run `rad key create --fo(match args["create" "--force"] (make-keys)(/cmd-0 "create" help) (safe-make-keys)- ["help"] (put-str! help)- ["-h"] (put-str! help)- ["--help"] (put-str! help)+ (/cmd-help) (put-str! help)(/cons 'cmd _) (cmd-parse-failure (string-append "Unknown command: " cmd))_ (put-str! help))diff --git a/bin/rad-patch b/bin/rad-patchindex 47fad4d..655e50e 100755--- a/bin/rad-patch+++ b/bin/rad-patch@@ -275,8 +275,6 @@(/cmd-2 "comment" 'n 'comment help) (whole-patch-num "comment on" n (fn [n] (create-comment! (machine-name) n comment)))(/cmd-0 "create-machine" help) (new-patch-machine! (machine-name))(/cmd-0 "all-read" help) (mark-all-read! (machine-name))- ["help"] (put-str! help)- ["-h"] (put-str! help)- ["--help"] (put-str! help)+ (/cmd-help) (put-str! help)(/cons 'cmd _) (cmd-parse-failure (error/unknown-command cmd))[] (put-str! help))))diff --git a/bin/rad-project b/bin/rad-projectindex 57503c5..93fd647 100755--- a/bin/rad-project+++ b/bin/rad-project@@ -197,8 +197,6 @@(/cmd-0 "init" help) (new-project!)(/cmd-0 "show-id" help) (show-project-id)(/cmd-1 "checkout" 'project-id help) (checkout! project-id)- ["help"] (put-str! help)- ["-h"] (put-str! help)- ["--help"] (put-str! help)+ (/cmd-help) (put-str! help)(/cons 'cmd _) (parse-failure (error/unknown-command cmd) help)[] (put-str! help))))diff --git a/bin/rad-replicate b/bin/rad-replicateindex 6a4f823..c88287f 100755--- a/bin/rad-replicate+++ b/bin/rad-replicate@@ -65,9 +65,7 @@(machine/catch-daemon!(fn [](match args- ["help"] (put-str! help)- ["-h"] (put-str! help)- ["--help"] (put-str! help)+ (/cmd-help) (put-str! help)['url] (replicate-all [:just url])[] (replicate-all :nothing))))diff --git a/rad/prelude/cmd-parsing.rad b/rad/prelude/cmd-parsing.radindex 9d81574..1bbe700 100644--- a/rad/prelude/cmd-parsing.rad+++ b/rad/prelude/cmd-parsing.rad@@ -1,7 +1,7 @@{:module 'prelude/cmd-parsing:doc "Functions for parsing commands.":exports- '[parse-failure /cmd-0 /cmd-1 /cmd-2 /cmd-opts whole-num]}+ '[parse-failure /cmd-0 /cmd-1 /cmd-2 /cmd-opts /cmd-help whole-num]}(import prelude/basic :unqualified)(import prelude/dict :unqualified)@@ -186,6 +186,22 @@[ (/cmd ["cmd-1"]) ==> :nothing][ (catch-for-testing /cmd ["cmd-0" 1]) ==> "Too many arguments for command \"cmd-0\" help"])+(def /cmd-help+ "Matches a help command. Additional arguments are ignored."+ (fn []+ (fn [value]+ (def help-cmds ["help" "-h" "--help"])+ (match value+ (/cons 'cmd _) (if (elem? cmd help-cmds) [:just {}] :nothing)+ [] :nothing))))++(:test "/cmd-help"+ [ ((/cmd-help) ["help"]) ==> [:just {}]]+ [ ((/cmd-help) ["-h"]) ==> [:just {}]]+ [ ((/cmd-help) ["--help"]) ==> [:just {}]]+ [ ((/cmd-help) ["--help" "foo"]) ==> [:just {}]]+ [ ((/cmd-help) []) ==> :nothing])+(def whole-num"Try to parse an argument which should be a whole-number. If parsed succesfullythe integer is passed to handler function. If not, an error is show to the