summaryrefslogtreecommitdiff
path: root/src/Command.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Command.hs')
-rw-r--r--src/Command.hs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/Command.hs b/src/Command.hs
index c765cfd..c73b857 100644
--- a/src/Command.hs
+++ b/src/Command.hs
@@ -8,6 +8,7 @@ module Command (
CommandExec(..),
CommandInput(..),
getCommonOptions,
+ getConfigPath,
getConfig,
getTerminalOutput,
) where
@@ -20,6 +21,8 @@ import Data.Text (Text)
import Data.Text qualified as T
import System.Console.GetOpt
+import System.Exit
+import System.IO
import Config
import Terminal
@@ -78,15 +81,29 @@ newtype CommandExec a = CommandExec (ReaderT CommandInput IO a)
data CommandInput = CommandInput
{ ciOptions :: CommonOptions
- , ciConfig :: Config
+ , ciConfigPath :: Maybe FilePath
+ , ciConfig :: Either String Config
, ciTerminalOutput :: TerminalOutput
}
getCommonOptions :: CommandExec CommonOptions
getCommonOptions = CommandExec (asks ciOptions)
+getConfigPath :: CommandExec FilePath
+getConfigPath = CommandExec $ do
+ asks ciConfigPath >>= \case
+ Nothing -> liftIO $ do
+ hPutStrLn stderr "no config file found"
+ exitFailure
+ Just path -> return path
+
getConfig :: CommandExec Config
-getConfig = CommandExec (asks ciConfig)
+getConfig = CommandExec $ do
+ asks ciConfig >>= \case
+ Left err -> liftIO $ do
+ hPutStrLn stderr err
+ exitFailure
+ Right config -> return config
getTerminalOutput :: CommandExec TerminalOutput
getTerminalOutput = CommandExec (asks ciTerminalOutput)