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