]> Git — Sourcephile - comptalang.git/blob - cli/Hcompta/CLI/Args.hs
Correction : build-depends : transformers >= 0.4
[comptalang.git] / cli / Hcompta / CLI / Args.hs
1 {-# LANGUAGE TupleSections #-}
2 module Hcompta.CLI.Args where
3
4 import System.Console.GetOpt
5 ( getOpt
6 , ArgOrder(..)
7 , OptDescr(..)
8 )
9
10 import Hcompta.CLI.Context (Context)
11 import qualified Hcompta.CLI.Write as Write
12
13 type Options context
14 = [OptDescr (context -> IO context)]
15
16 parse
17 :: Context
18 -> (IO String)
19 -> Options context
20 -> (context, [String])
21 -> IO (context, [String])
22 parse context usage options (ctx, args) =
23 case getOpt RequireOrder options args of
24 (ctx_, cmds, []) -> do
25 foldl (>>=) (return ctx) ctx_
26 >>= return . (, cmds)
27 (_, _, errs) -> do
28 usage >>= Write.fatal context . (concat errs ++)