7 | import public Collie.Core
8 | import public Collie.Parser
9 | import public Collie.Usage
11 | import public Collie.Options.Domain
12 | import public Collie.Options.Usual
13 | import public Collie.Modifiers
14 | import public Data.Record
15 | import public Data.Record.SmartConstructors
17 | import public Data.DPair
18 | import public Data.Magma
20 | import public Data.SnocList
22 | import public System
27 | (.parseArgs) : (cmd : Command nm) -> HasIO io =>
28 | io (String `Either` ParseTreeT Maybe Maybe cmd)
36 | let Pure res = parse cmd args'
37 | | err => pure $
Left (show (() <$ err))
42 | record Handlers (a : Type) (cmd : Field Command) where
43 | constructor MkHandlers
44 | here : ParsedCommand (cmd .fst) (cmd .snd) -> a
45 | there : Checkable (Handlers a) cmd.snd.subcommands
52 | (::) : (ParsedCommand (cmd .fst) (cmd .snd) -> a) ->
53 | Checkable (Handlers a) cmd.snd.subcommands ->
61 | 0 (~~>) : (Command arg) -> Type -> Type
62 | (~~>) cmd a = Handlers a (
_ ** cmd)
68 | handle : {0 cmd : Field Command} ->
69 | ParseTree cmd.snd -> Handlers a cmd -> a
70 | handle (Here res) h = h.here res
71 | handle (There pos p) h = handle p $
content h.there.mkCheckable !! pos
77 | (.handleWith) : {nm : String} -> (cmd : Command nm) -> (cmd ~~> IO a) -> IO a
79 | = do Right args <- cmd.parseArgs
80 | | _ => do putStrLn (cmd .usage)
82 | let Pure args = ParsedTree.finalising args
83 | | Fail err => exitWith err