CLI chooseEntries
This commit is contained in:
@@ -83,7 +83,7 @@
|
|||||||
&mut lastCollector
|
&mut lastCollector
|
||||||
(lambda []
|
(lambda []
|
||||||
(set lastChangeSet (the ChangeSet (Reflect.callMethod null command.handler collectedArgs)))
|
(set lastChangeSet (the ChangeSet (Reflect.callMethod null command.handler collectedArgs)))
|
||||||
(ui.handleChanges lastChangeSet))]
|
(ui.handleChanges archive lastChangeSet))]
|
||||||
// To facilitate asynchronous arg input via UI, we need to construct an insanely complicated nested callback to give the UI
|
// To facilitate asynchronous arg input via UI, we need to construct an insanely complicated nested callback to give the UI
|
||||||
(doFor arg (reversed command.args)
|
(doFor arg (reversed command.args)
|
||||||
(set lastCollector (_composeArgCollector collectedArgs arg lastCollector)))
|
(set lastCollector (_composeArgCollector collectedArgs arg lastCollector)))
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ interface ArchiveUI {
|
|||||||
/**
|
/**
|
||||||
* Update the interface to reflect changes made to Entries through commands
|
* Update the interface to reflect changes made to Entries through commands
|
||||||
*/
|
*/
|
||||||
function handleChanges(changeSet:ChangeSet):Void;
|
function handleChanges(archive:Archive, changeSet:ChangeSet):Void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell the user something useful
|
* Tell the user something useful
|
||||||
|
|||||||
@@ -38,28 +38,58 @@
|
|||||||
(break)}))))
|
(break)}))))
|
||||||
|
|
||||||
(defmethod :Void chooseEntry [prompt :Archive archive resolve]
|
(defmethod :Void chooseEntry [prompt :Archive archive resolve]
|
||||||
|
(_chooseEntry prompt archive resolve ->(chooseEntry "empty name doesn't match any entries. Try again?" archive resolve)))
|
||||||
|
|
||||||
|
(defmethod :Void _chooseEntry [prompt :Archive archive resolve onEmptyString]
|
||||||
// TODO allow narrowing down with a tag string
|
// TODO allow narrowing down with a tag string
|
||||||
(enterText "entry name for $prompt"
|
(enterText "entry name for $prompt"
|
||||||
->name {
|
->name {
|
||||||
(let [matchingEntries []]
|
(if !name
|
||||||
(.process (archive.addSystem
|
(onEmptyString)
|
||||||
(stringComponentSystem archive Name name
|
(let [matchingEntries []]
|
||||||
(lambda [archive e]
|
(.process (archive.addSystem
|
||||||
(matchingEntries.push e)))) archive)
|
(stringComponentSystem archive Name name
|
||||||
|
(lambda [archive e]
|
||||||
|
(matchingEntries.push e)))) archive)
|
||||||
|
|
||||||
(case (the Array<Entry> matchingEntries)
|
(case (the Array<Entry> matchingEntries)
|
||||||
([e] (resolve e))
|
([e] (resolve e))
|
||||||
([] (throw "name $name doesn't match any entries"))
|
([] (chooseEntry "name $name doesn't match any entries. Try again?" archive resolve))
|
||||||
// TODO disambiguate entries with the same names by listing stringified versions of them and using enterNumber
|
// TODO disambiguate entries with the same names by listing stringified versions of them and using enterNumber
|
||||||
(multipleEntries (throw "ambiguous between multiple entries"))))}
|
(multipleEntries (throw "ambiguous between multiple entries")))))}
|
||||||
0 Math.POSITIVE_INFINITY))
|
0 Math.POSITIVE_INFINITY))
|
||||||
|
|
||||||
(defmethod :Void chooseEntries [prompt archive resolve min max]
|
(defmethod :Void chooseEntries [prompt archive resolve min max]
|
||||||
(resolve []))
|
(_chooseEntries prompt archive resolve min max []))
|
||||||
|
|
||||||
(defmethod handleChanges [changeSet])
|
(defmethod :Void _chooseEntries [prompt archive resolve min max :Array<Entry> collectedEntries]
|
||||||
|
(let [onEmptyString
|
||||||
|
->(if (<= min collectedEntries.length)
|
||||||
|
(resolve collectedEntries)
|
||||||
|
(throw "not enough entries chosen"))
|
||||||
|
&mut :Void->Void chooseNextEntry
|
||||||
|
null
|
||||||
|
_chooseNextEntry
|
||||||
|
->:Void {(_chooseEntry
|
||||||
|
prompt
|
||||||
|
archive
|
||||||
|
->:Void e {(collectedEntries.push e)
|
||||||
|
// If the maximum is reached, return it
|
||||||
|
(if (= max collectedEntries.length)
|
||||||
|
(resolve collectedEntries)
|
||||||
|
// Otherwise, recurse
|
||||||
|
(chooseNextEntry))}
|
||||||
|
onEmptyString)}]
|
||||||
|
(set chooseNextEntry _chooseNextEntry)
|
||||||
|
(_chooseNextEntry)))
|
||||||
|
|
||||||
|
|
||||||
|
(defmethod handleChanges [:Archive archive :ChangeSet changeSet]
|
||||||
|
(doFor e changeSet
|
||||||
|
(print (archive.fullString e))))
|
||||||
|
|
||||||
(defmethod :Void displayMessage [message]
|
(defmethod :Void displayMessage [message]
|
||||||
(print message))
|
(print message))
|
||||||
|
|
||||||
(defmethod :Void reportError [error] ~error)
|
(defmethod :Void reportError [error]
|
||||||
|
(print error))
|
||||||
Reference in New Issue
Block a user