]> Git — Sourcephile - comptalang.git/blob - cli/Hcompta/CLI/Args.hs
Ajout : Makefile
[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 -> 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 (parsers, cmds, []) -> do
25 foldl (\acc parser -> acc >>= parser context) (return ctx) parsers
26 >>= return . (, cmds)
27 (_, _, errs) -> do
28 usage >>= Write.fatal context . (concat errs ++)