Skip to content

A peer-to-peer stack for code collaboration

Fix list command parsing (#419)

Merle Breitkreuzae70b05e35b5
diff --git a/bin/rad-diff b/bin/rad-diff
index c4fd45e..2cd64e2 100755
--- a/bin/rad-diff
+++ b/bin/rad-diff
@@ -9,7 +9,8 @@
(load! (find-module-file! "monadic/diff.rad"))
(load! (find-module-file! "prelude/io-utils.rad"))
(load! (find-module-file! "monadic/project.rad"))
-(load! (find-module-file! "prelude/cmd-parsing.rad"))
+
+(import prelude/cmd-parsing :unqualified)
(import prelude/validation :as 'validation)
(def chain-name (fn [] (get-rsm-of-type! :rad-diff)))
@@ -314,7 +315,7 @@
(def /list-cmd
(fn [opts]
- (/cmd-1-opts "list" opts valid-list-options list-options help)))
+ (/cmd-1-opts "list" opts list-options)))
(def args (get-args!))
(match args
diff --git a/bin/rad-issues b/bin/rad-issues
index 6eeef9c..229b79d 100755
--- a/bin/rad-issues
+++ b/bin/rad-issues
@@ -4,10 +4,10 @@
(load! (find-module-file! "monadic/issues.rad"))
(load! (find-module-file! "monadic/project.rad"))
(load! (find-module-file! "prelude/io-utils.rad"))
-(load! (find-module-file! "prelude/cmd-parsing.rad"))
(import prelude/validation :as 'validation)
(import prelude/chain :as 'chain)
+(import prelude/cmd-parsing :unqualified)
(def chain-name (fn [] (get-rsm-of-type! :rad-issues)))
@@ -203,12 +203,12 @@
os)))
(def /list-cmd
- (fn [chain-name opts]
- (/cmd-2-opts "list" chain-name opts valid-list-options list-options help)))
+ (fn [opts]
+ (/cmd-1-opts "list" opts list-options)))
(def args (get-args!))
(match args
- ["list"] (list-items (chain-name) [])
+ (/list-cmd 'options) (list-items (chain-name) options)
(/cmd-0 "names" help) (names)
(/cmd-1 "make-key" 'nick help) (make-key nick)
(/cmd-0 "new" help) (new-issue (chain-name))
diff --git a/bin/rad-project b/bin/rad-project
index 784ee86..1aa26e9 100755
--- a/bin/rad-project
+++ b/bin/rad-project
@@ -5,9 +5,9 @@
(load! (find-module-file! "monadic/diff.rad"))
(load! (find-module-file! "monadic/project.rad"))
(load! (find-module-file! "prelude/io-utils.rad"))
-(load! (find-module-file! "prelude/cmd-parsing.rad"))
(import prelude/validation :as 'validation)
+(import prelude/cmd-parsing :unqualified)
(def help
"rad-project - Radicle project CLI
diff --git a/rad/prelude.rad b/rad/prelude.rad
index 6d4a298..bf2c85c 100644
--- a/rad/prelude.rad
+++ b/rad/prelude.rad
@@ -24,6 +24,7 @@
(file-module! "prelude/io-utils.rad")
(file-module! "prelude/time.rad")
(file-module! "prelude/test.rad")
+(file-module! "prelude/cmd-parsing.rad")
(import prelude/basic :unqualified)
(import prelude/patterns :unqualified)
diff --git a/rad/prelude/cmd-parsing.rad b/rad/prelude/cmd-parsing.rad
index be15e70..536c598 100644
--- a/rad/prelude/cmd-parsing.rad
+++ b/rad/prelude/cmd-parsing.rad
@@ -1,9 +1,10 @@
{:module 'prelude/cmd-parsing
:doc "Functions for parsing commands."
:exports
- '[parse-failure /cmd-0 /cmd-1 /cmd-2 /cmd-2-opts]}
+ '[parse-failure /cmd-0 /cmd-1 /cmd-2 /cmd-1-opts]}
(import prelude/validation :as 'validation)
+(import prelude/patterns :unqualified)
(def parse-failure
"Prints the passed error message and help text and exits."
@@ -22,28 +23,30 @@
(def /cmd-1-opts
"Matches a command `cmd` with one argument and an optional
- combination of options from `valid-opts`."
- (fn [cmd opts valid-opts opts-map help]
+ combination of options that are allowed by opts-map"
+ (fn [cmd opts opts-map]
(fn [v]
(match v
- [cmd] [:just {opts []}]
- (/cons cmd (/cons 'c-n 'os)) (if (member? c-n valid-opts)
- (parse-failure (missing-arg-error arg-1 cmd) help)
- [:just {opts (opts-map os)}])
- _ :nothing))))
+ [cmd] [:just {opts []}]
+ (/cons cmd 'os) [:just {opts (opts-map os)}]
+ _ :nothing))))
-(def /cmd-2-opts
- "Matches a command `cmd` with one argument and an optional
- combination of options from `valid-opts`."
- (fn [cmd arg-1 opts valid-opts opts-map help]
- (fn [v]
- (match v
- [cmd] (parse-failure (string-append "Missing arguments for command " cmd) help)
- (/cons cmd (/cons 'c-n 'os)) (if (member? c-n valid-opts)
- (parse-failure (missing-arg-error arg-1 cmd) help)
- [:just {arg-1 c-n
- opts (opts-map os)}])
- _ :nothing))))
+(:test "/cmd-1-opts"
+ [:setup
+ (do
+ (def opts-map
+ (fn [opts]
+ (map
+ (fn [opt]
+ (if (elem? opt ["--new" "--old"])
+ (drop 2 opt)
+ "unknown filter")) opts))))]
+ [ ((/cmd-1-opts "list" 'opts opts-map) ["list"]) ==> [:just {opts []}]]
+ [ ((/cmd-1-opts "list" 'opts opts-map) ["no-list"]) ==> :nothing]
+ [ ((/cmd-1-opts "list" 'opts opts-map) ["list" "--old"]) ==> [:just {opts ["old"]}]]
+ [ ((/cmd-1-opts "list" 'opts opts-map) ["list" "--old" "--new"]) ==> [:just {opts ["old" "new"]}]]
+ [ ((/cmd-1-opts "list" 'opts opts-map) ["list" "--filter"]) ==> [:just {opts ["unknown filter"]}]]
+ [ ((/cmd-1-opts "list" 'opts opts-map) ["list" "--old" "--current"]) ==> [:just {opts ["old" "unknown filter"]}]])
(def /cmd-2
"Matches a command `cmd` with exactly two arguments."