summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-06-02 21:00:37 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2024-06-07 22:20:21 +0200
commitba789c3413ac996cb65314cb5ac9f77bd9617ff9 (patch)
treebef3d623dd4326a44d0af3996c4c5e446a40ea9b /src/Main.hs
parenta66cf7cf7d897e87fef715daf36dd773562241ec (diff)
Patchset parameter for `run' command
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs17
1 files changed, 14 insertions, 3 deletions
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