module KMonad.Args
( run )
where
import KMonad.Prelude
import KMonad.App
import KMonad.Args.Cmd
import KMonad.Args.Joiner
import KMonad.Args.Parser
import KMonad.Args.Types
run :: IO ()
run = getCmd >>= runCmd
runCmd :: Cmd -> IO ()
runCmd c = do
o <- logOptionsHandle stdout False <&> setLogMinLevel (c^.logLvl)
withLogFunc o $ \f -> runRIO f $ do
cfg <- loadConfig $ c^.cfgFile
unless (c^.dryRun) $ startApp cfg
loadConfig :: HasLogFunc e => FilePath -> RIO e AppCfg
loadConfig pth = do
tks <- loadTokens pth
cgt <- joinConfigIO tks
lf <- view logFuncL
snk <- liftIO . _snk cgt $ lf
src <- liftIO . _src cgt $ lf
pure $ AppCfg
{ _keySinkDev = snk
, _keySourceDev = src
, _keymapCfg = _km cgt
, _firstLayer = _fstL cgt
, _fallThrough = _flt cgt
, _allowCmd = _allow cgt
}