import System.Cmd import System.Environment main :: IO () main = do args <- getArgs case args of [] -> usage (cmd:rest) -> parseBefore cmd rest where parseBefore cmd rest = case break (== "--") (reverse rest) of (_, []) -> parseAfter cmd [] rest (after, (_:before)) -> parseAfter cmd before (reverse after) parseAfter cmd before rest = case break (== "---") rest of (_, []) -> run cmd before rest [] (xs, (_:after)) -> run cmd before xs after run :: String -> [String] -> [String] -> [String] -> IO () run cmd before args after = (`mapM_` args) $ \arg -> do rawSystem cmd (before ++ (arg:after)) usage :: IO () usage = mapM_ putStrLn [ "" , "Usage: mdo COMMAND [BEFORE... --] ITEMS... [--- AFTER...]" , "" , " Run COMMAND on each of the ITEMS." , "" , " Arguments in BEFORE are used as initial arguments to each invocation." , "" , " Arguments in AFTER are used as trailing arguments to each invocation." , "" ]