From 7bb2775667386659402ebb7559c7bc4af46ec268 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 15 Jan 2021 19:12:19 -0500 Subject: 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. --- Biz/Cli.hs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Biz/Cli.hs (limited to 'Biz/Cli.hs') 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 -- cgit v1.2.3