Conscript (empty) → 0.1.0.0
raw patch · 4 files changed
+91/−0 lines, 4 filesdep +basedep +processsetup-changed
Dependencies added: base, process
Files
- Conscript.cabal +22/−0
- Conscript.hs +44/−0
- LICENSE +23/−0
- Setup.hs +2/−0
+ Conscript.cabal view
@@ -0,0 +1,22 @@+-- Initial Conscript.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/++name: Conscript+version: 0.1.0.0+synopsis: Restart a command on STDIN activity+description: Restart a command on STDIN activity+homepage: https://github.com/sordina/Conscript+license: MIT+license-file: LICENSE+author: Lyndon Maydwell+maintainer: lyndon@sordina.net+category: System+build-type: Simple+cabal-version: >=1.8++executable conscript+ main-is: Conscript.hs+ build-depends:+ base >= 4.5 && < 4.7,+ process >= 1.1 && < 1.3+ ghc-options: -O3 -threaded -with-rtsopts -N2
+ Conscript.hs view
@@ -0,0 +1,44 @@+import System.Environment+import System.Process+import System.Exit+import System.IO+import Control.Monad+import Control.Concurrent++main :: IO ()+main = getArgs >>= options++options :: [String] -> IO ()+options [] = help+options ("-h" :_) = help+options ("--help":_) = help+options args = run args++run :: [String] -> IO ()+run args = do+ hSetBuffering stdin LineBuffering+ hSetBuffering stdout LineBuffering+ blocker <- newEmptyMVar+ running <- newEmptyMVar+ void $ forkIO $ forever $ starter args blocker running+ mapM_ (killer blocker running) . lines =<< getContents++killer :: MVar () -> MVar ProcessHandle -> String -> IO ()+killer blocker running _input = void $ takeMVar running >>= terminateProcess >> takeMVar blocker++starter :: [String] -> MVar () -> MVar ProcessHandle -> IO ()+starter args blocker running = do+ putMVar blocker ()+ p <- startProcess args+ putMVar running p+ code <- waitForProcess p+ case code of ExitFailure 15 -> return () -- Killed!+ ExitFailure i -> putStrLn $ "Process [" ++ unwords args ++ "] failed with exit-status [" ++ show i ++ "]"+ ExitSuccess -> return ()++startProcess :: [String] -> IO ProcessHandle+startProcess (h:t) = (\(_,_,_,ph) -> ph) `fmap` createProcess (proc h t)+startProcess [] = help >> exitFailure++help :: IO ()+help = putStrLn "Usage: conscript command [args*]"
+ LICENSE view
@@ -0,0 +1,23 @@+The MIT License (MIT)++Copyright (c) 2013 Lyndon Maydwell++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.++
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain