1 {-# LANGUAGE TupleSections #-}
2 module Hcompta.CLI.Args where
4 import Control.Monad (Monad(..), liftM)
5 import Data.List (map, foldl')
6 import Data.String (String)
7 import qualified Data.Text.Lazy as TL
8 import Prelude (($), (.), IO)
9 import System.Console.GetOpt
15 import Hcompta.CLI.Context (Context)
16 import qualified Hcompta.CLI.Write as Write
17 import Hcompta.Lib.Leijen ((<>))
18 import qualified Hcompta.Lib.Leijen as W
21 = [OptDescr (context -> IO context)]
25 -> (Context -> IO String)
26 -> (Context -> Options c)
29 parse c usage options (ctx, args) =
30 case getOpt RequireOrder (options c) args of
31 (parsers, cmds, []) -> do
33 Data.List.foldl' (>>=) (return ctx) parsers
35 usage c >>= Write.fatal c .
36 (W.vsep (map (W.text . TL.pack) errs) <>) .