summaryrefslogtreecommitdiff
path: root/Biz/Cli.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2021-01-15 19:12:19 -0500
committerBen Sima <ben@bsima.me>2021-01-15 20:03:07 -0500
commit7bb2775667386659402ebb7559c7bc4af46ec268 (patch)
tree0e41af56809c1c7aec5a399f32cd3dadd7129ef3 /Biz/Cli.hs
parent25c02fbf517888238097cf82879eef3cd3828626 (diff)
Implement Biz.Cli
Wraps docopt rather nicely. It's much nicer than optparse-applicative and runs tests with the --test argument automatically. Next I just need to implement a test framework.
Diffstat (limited to 'Biz/Cli.hs')
-rw-r--r--Biz/Cli.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/Biz/Cli.hs b/Biz/Cli.hs
new file mode 100644
index 0000000..f2d7fad
--- /dev/null
+++ b/Biz/Cli.hs
@@ -0,0 +1,36 @@
+{-# LANGUAGE RecordWildCards #-}
+{-# LANGUAGE NoImplicitPrelude #-}
+
+-- : dep docopt
+module Biz.Cli
+ ( Plan (..),
+ main,
+ Docopt.Docopt (..),
+ Docopt.Arguments,
+ Docopt.argument,
+ Docopt.docopt,
+ Docopt.getAllArgs,
+ )
+where
+
+import Alpha
+import qualified System.Console.Docopt as Docopt
+import qualified System.Environment as Environment
+
+data Plan = Plan
+ { help :: Docopt.Docopt,
+ move :: Docopt.Arguments -> IO (),
+ test :: Docopt.Arguments -> IO ()
+ }
+
+main :: Plan -> IO ()
+main Plan {..} =
+ Environment.getArgs
+ >>= Docopt.parseArgsOrExit help
+ >>= \args ->
+ if args `has` Docopt.longOption "test"
+ then test args
+ else move args
+
+has :: Docopt.Arguments -> Docopt.Option -> Bool
+has = Docopt.isPresent