diff options
Diffstat (limited to 'stdlib/source')
-rw-r--r-- | stdlib/source/lux/cli.lux | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/stdlib/source/lux/cli.lux b/stdlib/source/lux/cli.lux index afe784e98..d171dc899 100644 --- a/stdlib/source/lux/cli.lux +++ b/stdlib/source/lux/cli.lux @@ -121,6 +121,19 @@ #;Nil (#;Right [inputs []]) _ (#;Left (Text/append "Unknown parameters: " (text;join-with " " inputs)))))) +(def: #export (after param subject) + (All [p s] (-> (CLI p) (CLI s) (CLI s))) + (do Monad<CLI> + [_ param] + subject)) + +(def: #export (before param subject) + (All [p s] (-> (CLI p) (CLI s) (CLI s))) + (do Monad<CLI> + [output subject + _ param] + (wrap output))) + (def: #export (assert message test) {#;doc "Fails with the given message if the test is false."} (-> Text Bool (CLI Unit)) @@ -215,15 +228,15 @@ ## [Syntax] (type: Program-Args (#Raw-Program-Args Text) - (#Parsed-Program-Args (List [Text AST]))) + (#Parsed-Program-Args (List [AST AST]))) (def: program-args^ (Syntax Program-Args) (s;alt s;local-symbol (s;form (s;some (s;either (do s;Monad<Syntax> [name s;local-symbol] - (wrap [name (` any)])) - (s;record (s;seq s;local-symbol s;any))))))) + (wrap [(ast;symbol ["" name]) (` any)])) + (s;tuple (s;seq s;any s;any))))))) (syntax: #export (program: [args program-args^] body) {#;doc (doc "Defines the entry-point to a program (similar to the \"main\" function/method in other programming languages)." @@ -249,13 +262,13 @@ (#Parsed-Program-Args args) (with-gensyms [g!args g!_ g!output g!message] (wrap (list (` (;_lux_program (~ g!args) - (case ((: (CLI (io;IO Unit)) - (do Monad<CLI> + (case ((: (;;CLI (io;IO Unit)) + (do ;;Monad<CLI> [(~@ (|> args - (List/map (function [[name parser]] - (list (ast;symbol ["" name]) parser))) + (List/map (function [[binding parser]] + (list binding parser))) List/join)) - (~ g!_) end] + (~ g!_) ;;end] ((~' wrap) (~ body)))) (~ g!args)) (#;Right [(~ g!_) (~ g!output)]) |