diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-01-23 19:29:26 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-01-23 19:29:26 +0100 |
commit | 9c31e8cbf9708922e5a080dff28f102dfa58eeec (patch) | |
tree | f6a00d9eebdf3177be79423d59151875cdc7a9b3 /src/Command.hs | |
parent | aa113848a5884f95d543c2acecb55321db23b3ba (diff) |
Look for repo in directory containing config file
Diffstat (limited to 'src/Command.hs')
-rw-r--r-- | src/Command.hs | 21 |
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) |