summaryrefslogtreecommitdiff
path: root/Biz/Cli.hs
blob: f2d7fad7c7e33831d1aa589b4c1cf312508a099a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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