module KMonad.Args.Cmd
( Cmd(..)
, HasCmd(..)
, getCmd
)
where
import KMonad.Prelude
import Options.Applicative
data Cmd = Cmd
{ _cfgFile :: FilePath
, _dryRun :: Bool
, _logLvl :: LogLevel
}
deriving Show
makeClassy ''Cmd
getCmd :: IO Cmd
getCmd = customExecParser (prefs showHelpOnEmpty) $ info (cmdP <**> helper)
( fullDesc
<> progDesc "Start KMonad"
<> header "kmonad - an onion of buttons."
)
cmdP :: Parser Cmd
cmdP = Cmd <$> fileP <*> dryrunP <*> levelP
fileP :: Parser FilePath
fileP = strArgument
( metavar "FILE"
<> help "The configuration file")
dryrunP :: Parser Bool
dryrunP = switch
( long "dry-run"
<> short 'd'
<> help "If used, do not start KMonad, only try parsing the config file"
)
levelP :: Parser LogLevel
levelP = option f
( long "log-level"
<> short 'l'
<> metavar "Log level"
<> value LevelWarn
<> help "How much info to print out (debug, info, warn, error)" )
where
f = maybeReader $ flip lookup [ ("debug", LevelDebug), ("warn", LevelWarn)
, ("info", LevelInfo), ("error", LevelError) ]