From 9c31e8cbf9708922e5a080dff28f102dfa58eeec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Thu, 23 Jan 2025 19:29:26 +0100 Subject: Look for repo in directory containing config file --- src/Command.hs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/Command.hs') 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) -- cgit v1.2.3