diff options
Diffstat (limited to 'src/Command.hs')
-rw-r--r-- | src/Command.hs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/Command.hs b/src/Command.hs index 0ca6710..2c2235f 100644 --- a/src/Command.hs +++ b/src/Command.hs @@ -1,8 +1,12 @@ module Command ( + CommonOptions(..), + defaultCommonOptions, + Command(..), CommandArgumentsType(..), CommandExec(..), + getCommonOptions, getConfig, ) where @@ -17,6 +21,15 @@ import System.Console.GetOpt import Config +data CommonOptions = CommonOptions + { optJobs :: Int + } + +defaultCommonOptions :: CommonOptions +defaultCommonOptions = CommonOptions + { optJobs = 2 + } + class CommandArgumentsType (CommandArguments c) => Command c where commandName :: proxy c -> String commandDescription :: proxy c -> String @@ -54,8 +67,11 @@ instance CommandArgumentsType (Maybe Text) where argsFromStrings _ = throwError "expected at most one argument" -newtype CommandExec a = CommandExec (ReaderT Config IO a) +newtype CommandExec a = CommandExec (ReaderT ( CommonOptions, Config ) IO a) deriving (Functor, Applicative, Monad, MonadIO) +getCommonOptions :: CommandExec CommonOptions +getCommonOptions = CommandExec (asks fst) + getConfig :: CommandExec Config -getConfig = CommandExec ask +getConfig = CommandExec (asks snd) |