WIP NAT runCommand and defcommand
This commit is contained in:
@@ -1,13 +1,4 @@
|
|||||||
(defmethod selectEntry [:Entry e]
|
(defmethod :Void _collectAndValidateArg [:CommandArg arg :Dynamic->Void continuation]
|
||||||
(set selectedEntries [e]))
|
|
||||||
|
|
||||||
(defmethod selectEntries [:Array<Entry> e]
|
|
||||||
(set selectedEntries e))
|
|
||||||
|
|
||||||
(defmethod selectLastChangeSet []
|
|
||||||
(set selectedEntries lastChangeSet))
|
|
||||||
|
|
||||||
(defmethod :Void collectAndValidateArg [:CommandArg arg :Dynamic->Void continuation]
|
|
||||||
(case arg.type
|
(case arg.type
|
||||||
(SelectedEntry
|
(SelectedEntry
|
||||||
(if (= 1 selectedEntries.length)
|
(if (= 1 selectedEntries.length)
|
||||||
@@ -78,36 +69,50 @@
|
|||||||
(ui.reportError "The requested command expects between $min and $max entries. You chose: $entries.length")
|
(ui.reportError "The requested command expects between $min and $max entries. You chose: $entries.length")
|
||||||
(continuation selectedEntries)))))))
|
(continuation selectedEntries)))))))
|
||||||
|
|
||||||
/*(defmethod :Void runCommand [command]
|
(defmethod :Void->Void _composeArgCollector [:Array<Dynamic> collectedArgs :CommandArg arg :Void->Void lastCollector]
|
||||||
|
(lambda :Void []
|
||||||
|
(_collectAndValidateArg arg ->:Void [:Dynamic argValue] {(collectedArgs.push argValue) (lastCollector)})))
|
||||||
|
|
||||||
|
(defmethod :Void runCommand [:Command command]
|
||||||
(let [collectedArgs
|
(let [collectedArgs
|
||||||
[]
|
[]
|
||||||
callHandler
|
&mut lastCollector
|
||||||
(lambda []
|
(lambda []
|
||||||
(set lastChangeSet (the ChangeSet (Reflect.callMethod command.handler collectedArgs)))
|
(set lastChangeSet (the ChangeSet (Reflect.callMethod null command.handler collectedArgs)))
|
||||||
(ui.handleChanges lastChangeSet))])
|
(ui.handleChanges lastChangeSet))]
|
||||||
// If the command has no arguments, it can run synchronously with no hassle
|
// To facilitate asynchronous arg input via UI, we need to construct an insanely complicated nested callback to give the UI
|
||||||
(if !command.args
|
(doFor arg (reversed command.args)
|
||||||
(callHandler)
|
(set lastCollector (_composeArgCollector collectedArgs arg lastCollector)))
|
||||||
// To facilitate asynchronous arg input via UI, we need to construct an insanely complicated nested callback to give the UI
|
(lastCollector)))
|
||||||
(let [argsToCollect
|
|
||||||
(reversed command.args)
|
(defmacro defcommand [name args &rest body]
|
||||||
composeArgCollector
|
(let [argPairs
|
||||||
(lambda :Void->Void [:CommandArg arg :Void->Void lastResolver]
|
(groups (expList args) 2)
|
||||||
(lambda :Void []
|
methodArgs
|
||||||
(case arg.type
|
~(for [name type] argPairs
|
||||||
((SelectedEntry
|
// TODO write a macroCase macro that simplifies this terrible mess,
|
||||||
|
// and maybe adds back precise pattern matching instead of relying
|
||||||
|
// on partial string matching
|
||||||
|
(let [expAsStr (Std.string type)]
|
||||||
|
(cond
|
||||||
|
((< -1 ~(max (expAsStr.indexOf "SelectedEntry") (expAsStr.indexOf "OneEntry"))) (typed "Entry" name))
|
||||||
|
((< -1 ~(max (expAsStr.indexOf "SelectedEntries") (expAsStr.indexof "Entries"))) (typed "Array<Entry>" name))
|
||||||
|
((< -1 ~(expAsStr.indexOf "Text")) (typed "String" name))
|
||||||
|
((< -1 ~(expAsStr.indexOf "Number")) (typed "Float" name)))))
|
||||||
|
commandArgs
|
||||||
|
(for [name type] argPairs
|
||||||
|
// TODO this is also a mess because for some reason quasiquote wouldn't work here
|
||||||
|
~(call (symbol "object") [(symbol "name") (symbolNameExp name) (symbol "type") type]))]
|
||||||
|
`{
|
||||||
|
(defmethod ,name ,methodArgs ,body)
|
||||||
|
(dictSet commands ,(symbolNameExp name) (object args ,commandArgs handler ,name))}))
|
||||||
|
|
||||||
|
(defmethod selectEntries [:Array<Entry> e]
|
||||||
|
(set selectedEntries e))
|
||||||
|
|
||||||
|
(defmethod selectLastChangeSet []
|
||||||
|
(set selectedEntries lastChangeSet))
|
||||||
|
|
||||||
(ui.chooseEntry arg.prompt )))
|
|
||||||
(collectedArgs.push arg)
|
|
||||||
(lastResolver)
|
|
||||||
))
|
|
||||||
resolve (lambda [:Dynamic arg]
|
|
||||||
())
|
|
||||||
])
|
|
||||||
(doFor arg (reversed command.args)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)*/
|
|
||||||
|
|
||||||
(defnew [&prop :Archive archive
|
(defnew [&prop :Archive archive
|
||||||
&prop :ArchiveUI ui]
|
&prop :ArchiveUI ui]
|
||||||
@@ -115,4 +120,7 @@
|
|||||||
&mut :ChangeSet lastChangeSet []
|
&mut :ChangeSet lastChangeSet []
|
||||||
:Map<String,Command> commands (new Map)]
|
:Map<String,Command> commands (new Map)]
|
||||||
|
|
||||||
|
(defcommand selectEntry [e OneEntry]
|
||||||
|
(set selectedEntries [e]))
|
||||||
|
|
||||||
)
|
)
|
@@ -4,6 +4,7 @@ import kiss.Prelude;
|
|||||||
import kiss.List;
|
import kiss.List;
|
||||||
import kiss.Operand;
|
import kiss.Operand;
|
||||||
import sys.FileSystem;
|
import sys.FileSystem;
|
||||||
|
import nat.ArchiveController.CommandArgType;
|
||||||
|
|
||||||
@:build(kiss.Kiss.build())
|
@:build(kiss.Kiss.build())
|
||||||
class CLI implements ArchiveUI {}
|
class CLI implements ArchiveUI {}
|
||||||
|
@@ -4,8 +4,7 @@
|
|||||||
(new ArchiveController
|
(new ArchiveController
|
||||||
(new Archive archiveDir)
|
(new Archive archiveDir)
|
||||||
(new CLI))]
|
(new CLI))]
|
||||||
(controller.collectAndValidateArg (object name "numerical" type (Number -5 5 1)) ->:Void val ~val)
|
(controller.runCommand (object args [(object name "str" type (Text 3 55)) (object name "int" type (Number 0 5 1))] handler (lambda [fuck shit] ~"string $fuck number $shit")))))
|
||||||
(controller.collectAndValidateArg (object name "string" type (Text 5 null)) ->:Void val ~val)))
|
|
||||||
|
|
||||||
(defnew [])
|
(defnew [])
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user