summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Command.hs21
-rw-r--r--src/Command/Run.hs14
-rw-r--r--src/Main.hs19
3 files changed, 40 insertions, 14 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)
diff --git a/src/Command/Run.hs b/src/Command/Run.hs
index 52b70f3..b998a60 100644
--- a/src/Command/Run.hs
+++ b/src/Command/Run.hs
@@ -14,7 +14,9 @@ import Data.Text qualified as T
import Data.Text.IO qualified as T
import System.Console.GetOpt
+import System.Directory
import System.Exit
+import System.FilePath
import System.IO
import System.Process
@@ -138,9 +140,17 @@ cmdRun :: RunCommand -> CommandExec ()
cmdRun (RunCommand RunOptions {..} args) = do
CommonOptions {..} <- getCommonOptions
tout <- getTerminalOutput
+ configPath <- getConfigPath
+ let baseDir = takeDirectory configPath
liftIO $ do
- Just repo <- openRepo "."
+ repo <- openRepo baseDir >>= \case
+ Just repo -> return repo
+ Nothing -> do
+ absPath <- makeAbsolute baseDir
+ T.hPutStrLn stderr $ "No repository found at `" <> T.pack absPath <> "'"
+ exitFailure
+
ranges <- forM (args ++ roRanges) $ \changeset -> do
( base, tip ) <- case T.splitOn ".." changeset of
base : tip : _ -> return ( base, tip )
@@ -156,7 +166,7 @@ cmdRun (RunCommand RunOptions {..} args) = do
branches <- mapM (watchBranchSource repo) roNewCommitsOn
- mngr <- newJobManager "./.minici" optJobs
+ mngr <- newJobManager (baseDir </> ".minici") optJobs
source <- mergeSources $ concat [ ranges, branches ]
headerLine <- newLine tout ""
diff --git a/src/Main.hs b/src/Main.hs
index d24642d..a6dfe07 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -138,13 +138,12 @@ runSomeCommand ciOptions (SC tproxy) args = do
putStr $ usageInfo (T.unpack $ commandUsage tproxy) (fullCommandOptions tproxy)
exitSuccess
- Just configPath <- findConfig
- BL.readFile configPath >>= return . parseConfig >>= \case
- Left err -> do
- putStr err
- exitFailure
- Right ciConfig -> do
- let cmd = commandInit tproxy (fcoSpecific opts) cmdargs
- let CommandExec exec = commandExec cmd
- ciTerminalOutput <- initTerminalOutput
- flip runReaderT CommandInput {..} exec
+ ciConfigPath <- findConfig
+ ciConfig <- case ciConfigPath of
+ Just path -> parseConfig <$> BL.readFile path
+ Nothing -> return $ Left "no config file found"
+
+ let cmd = commandInit tproxy (fcoSpecific opts) cmdargs
+ let CommandExec exec = commandExec cmd
+ ciTerminalOutput <- initTerminalOutput
+ flip runReaderT CommandInput {..} exec