1 {-# LANGUAGE TupleSections #-}
2 module Hcompta.CLI.Args where
4 import Control.Monad (liftM)
5 import qualified Data.List
6 import qualified Data.Text.Lazy as TL
7 import System.Console.GetOpt
13 import Hcompta.CLI.Context (Context)
14 import qualified Hcompta.CLI.Write as Write
15 import Hcompta.Lib.Leijen ((<>))
16 import qualified Hcompta.Lib.Leijen as W
19 = [OptDescr (Context -> context -> IO context)]
25 -> (context, [String])
26 -> IO (context, [String])
27 parse context usage options (ctx, args) =
28 case getOpt RequireOrder options args of
29 (parsers, cmds, []) -> do
31 Data.List.foldl' (\acc parser -> acc >>= parser context) (return ctx) parsers
33 usage >>= Write.fatal context .
34 (W.vsep (map (W.text .TL.pack) errs) <>) .