1 {-# LANGUAGE TupleSections #-}
2 module Hcompta.CLI.Args where
4 import Control.Monad (Monad(..))
5 import Data.Function ((.))
6 import qualified Data.List as List
7 import Data.Monoid ((<>))
8 import Data.Functor ((<$>))
9 import Data.String (String)
10 import qualified Data.Text.Lazy as TL
11 import System.Console.GetOpt
17 import qualified Text.WalderLeijen.ANSI.Text as W
19 import Hcompta.CLI.Context (Context)
20 import qualified Hcompta.CLI.Write as Write
23 = [OptDescr (context -> IO context)]
27 -> (Context -> IO String)
28 -> (Context -> Options c)
31 parse c usage options (ctx, args) =
32 case getOpt RequireOrder (options c) args of
33 (parsers, cmds, []) ->
35 List.foldl' (>>=) (return ctx) parsers
39 (W.vsep (W.text . TL.pack <$> errs) <>) .