From ba789c3413ac996cb65314cb5ac9f77bd9617ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 2 Jun 2024 21:00:37 +0200 Subject: Patchset parameter for `run' command --- src/Main.hs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index 1300024..f65c023 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,6 +1,7 @@ module Main (main) where import Control.Monad +import Control.Monad.Except import Control.Monad.Reader import Data.List @@ -52,7 +53,7 @@ lookupCommand name = find p commands main :: IO () main = do args <- getArgs - (opts, cmdargs) <- case getOpt Permute options args of + (opts, cmdargs) <- case getOpt RequireOrder options args of (o, cmdargs, []) -> return (foldl (flip id) defaultCmdlineOptions o, cmdargs) (_, _, errs) -> do hPutStrLn stderr $ concat errs <> "Try `minici --help' for more information." @@ -81,9 +82,19 @@ main = do runSomeCommand ncmd cargs runSomeCommand :: SomeCommandType -> [ String ] -> IO () -runSomeCommand (SC tproxy) _ = do +runSomeCommand (SC tproxy) args = do + let exitWithErrors errs = do + hPutStr stderr $ concat errs + exitFailure + + (opts, cmdargs) <- case getOpt Permute (commandOptions tproxy) args of + (o, strargs, []) -> case runExcept $ argsFromStrings strargs of + Left err -> exitWithErrors [ err <> "\n" ] + Right cmdargs -> return (foldl (flip id) (defaultCommandOptions tproxy) o, cmdargs) + (_, _, errs) -> exitWithErrors errs + Just configPath <- findConfig config <- parseConfig configPath - let cmd = commandInit tproxy + let cmd = commandInit tproxy opts cmdargs let CommandExec exec = commandExec cmd flip runReaderT config exec -- cgit v1.2.3