module Main (main) where import Control.Monad import Control.Monad.Except import Control.Monad.Reader import Data.List import Data.Proxy import System.Console.GetOpt import System.Environment import System.Exit import System.IO import Command import Command.Run import Config import Version data CmdlineOptions = CmdlineOptions { optShowHelp :: Bool , optShowVersion :: Bool } defaultCmdlineOptions :: CmdlineOptions defaultCmdlineOptions = CmdlineOptions { optShowHelp = False , optShowVersion = False } options :: [OptDescr (CmdlineOptions -> CmdlineOptions)] options = [ Option ['h'] ["help"] (NoArg $ \opts -> opts { optShowHelp = True }) "show this help and exit" , Option ['V'] ["version"] (NoArg $ \opts -> opts { optShowVersion = True }) "show version and exit" ] data SomeCommandType = forall c. Command c => SC (Proxy c) commands :: [ SomeCommandType ] commands = [ SC $ Proxy @RunCommand ] lookupCommand :: String -> Maybe SomeCommandType lookupCommand name = find p commands where p (SC cmd) = commandName cmd == name main :: IO () main = do args <- getArgs (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." exitFailure when (optShowHelp opts) $ do let header = "Usage: minici [