stack-run 0.1.0.2 → 0.1.0.3
raw patch · 2 files changed
+35/−22 lines, 2 files
Files
- src/Main.hs +34/−21
- stack-run.cabal +1/−1
src/Main.hs view
@@ -23,14 +23,20 @@ usage :: String usage = unlines [ ""- , " Usage: stack run [name]"+ , " Usage: stack run <name|sub-command> [args]" , "" , " Commands:" , ""- , " stack run [name] Compiles and runs the executable specified or the default"+ , " stack run [name] [args] Compiles and runs the executable specified or the default"+ , " stack run -- <name> [args] Like stack run, but will never match a sub-command"+ , " stack run -- -- [args] Pass-in arguments to the default executable"+ , "" , " stack run set-default <name> Sets the default executable to run"- , " stack run -- <name> Like stack run, but will never match a sub-command" , ""+ , " stack run help Print this help message"+ , " stack run --help"+ , " stack run -h"+ , "" ] setDefault :: String -> IO ()@@ -70,37 +76,43 @@ f -> exitWith f ec <- prettyRunCommand "stack build" case ec of- ExitSuccess ->- setSGR [Reset] >>- hFlush stdout >>- runCommand ("stack exec " ++ name ++ " -- " ++ join " " as) >>=- waitForProcess >>=- exitWith+ ExitSuccess -> do+ let cmd = "stack exec " ++ name ++ " -- " ++ join " " as+ logCommand cmd+ hSetSGR stderr [Reset]+ hFlush stderr+ ph <- runCommand cmd+ ec' <- waitForProcess ph+ exitWith ec' f -> exitWith f prettyRunCommand :: String -> IO ExitCode prettyRunCommand cmd = do- setSGR [ SetColor Foreground Vivid White- , SetConsoleIntensity BoldIntensity- ]- putStr "$ "- setSGR [Reset]- setSGR [SetColor Foreground Vivid Cyan]- putStrLn cmd- setSGR [Reset]+ logCommand cmd (Inherited, out, err, cph) <- streamingProcess (shell cmd) out =$= Conduit.Binary.lines $$ Conduit.List.mapM_ putLineGray err =$= Conduit.Binary.lines $$ Conduit.List.mapM_ putLineRed waitForStreamingProcess cph where putLineSGR sgr b = do- setSGR sgr- putStr " "- ByteString.putStrLn b- setSGR [Reset]+ hSetSGR stderr sgr+ hPutStr stderr " "+ ByteString.hPutStrLn stderr b+ hSetSGR stderr [Reset] putLineGray = putLineSGR [SetColor Foreground Dull White] putLineRed = putLineSGR [SetColor Foreground Vivid Black] +logCommand :: String -> IO ()+logCommand cmd = do+ hSetSGR stderr [ SetColor Foreground Vivid White+ , SetConsoleIntensity BoldIntensity+ ]+ hPutStr stderr "$ "+ hSetSGR stderr [Reset]+ hSetSGR stderr [SetColor Foreground Vivid Cyan]+ hPutStrLn stderr cmd+ hSetSGR stderr [Reset]+ main :: IO () main = do args <- getArgs@@ -113,6 +125,7 @@ ("--help":_) -> exitUsage ("-h":_) -> exitUsage ("help":_) -> exitUsage+ ("--":"--":as) -> flip stackRun as =<< findDefault ("--":name:as) -> stackRun name as (name:as) -> stackRun name as [] -> flip stackRun [] =<< findDefault
stack-run.cabal view
@@ -1,5 +1,5 @@ name: stack-run-version: 0.1.0.2+version: 0.1.0.3 synopsis: An equivalent to cabal run for stack. description: Finds the project root, compiles your code and runs the first or set default executable. It's a shorthand for