packages feed

execs (empty) → 0.1.0.0

raw patch · 5 files changed

+154/−0 lines, 5 filesdep +basedep +directorydep +execssetup-changed

Dependencies added: base, directory, execs, process, text

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Sergey N. Yashin (c) 2016++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Sergey N. Yashin nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ app/Main.hs view
@@ -0,0 +1,85 @@+{-# LANGUAGE OverloadedStrings #-}++module Main where++  import           Control.Exception+  import           Control.Monad+  import qualified Data.List          as DL+  import qualified Data.Text          as T+  import qualified Data.Text.IO       as TIO+  import qualified System.Directory   as SD+  import qualified System.Environment as SE+  import qualified System.Process     as SP++  cabalExt :: String+  cabalExt = ".cabal"++  commandsSimpleMode :: [String]+  commandsSimpleMode = []++  commandsRebuildMode :: [String]+  commandsRebuildMode = ["stack clean", "stack build"]++  stackExec :: String+  stackExec = "stack exec"++  main :: IO ()+  main = do+    cbm <- getCabalFilename+    flip (maybe (error "Have no .cabal files found.")) cbm $ \cabal -> do+      mode <- getCommandsMode+      execs <- getExecutables . T.lines <$> TIO.readFile cabal+      if null execs+        then error "Have no executables found."+        else exe mode $ T.unpack (head execs)++  getCommandsMode :: IO [String]+  getCommandsMode = do+    args <- SE.getArgs+    if "-r" `elem` args+      then return commandsRebuildMode+      else return commandsSimpleMode++  exe :: [String] -> String -> IO ()+  exe _ [] = error "Empty executable name."+  exe cmds exename = do+    let+      cmd :: String+      cmd = stackExec ++ " " ++ exename+    r <- exe' cmds+    when r $ run' cmd+    where+      exe' :: [String] -> IO Bool+      exe' (a:as) = do+        r <- runFail a+        if r+          then exe' as+          else return r+      exe' _ = return True++      run' :: String -> IO ()+      run' cmd = void (try (SP.callCommand cmd) :: IO (Either SomeException ()))++      runFail :: String -> IO Bool+      runFail cmd = catch (SP.callCommand cmd >> return True) handlerFail++      handlerFail :: SomeException -> IO Bool+      handlerFail _ = return False++  getExecutables :: [T.Text] -> [T.Text]+  getExecutables [] = []+  getExecutables (l:ls)+    | T.null l = getExecutables ls+    | otherwise =+      let+        lc :: T.Text+        lc = T.strip . T.toLower $ l+      in+        if "executable" `T.isPrefixOf` lc+          then last (T.words lc) : getExecutables ls+          else getExecutables ls++  getCabalFilename :: IO (Maybe FilePath)+  getCabalFilename = do+    files <- SD.getCurrentDirectory >>= SD.getDirectoryContents+    return $ DL.find (cabalExt `DL.isSuffixOf`) files
+ execs.cabal view
@@ -0,0 +1,36 @@+name:                execs+version:             0.1.0.0+synopsis:            Tool to run stack exec prj-exe more easy+description:         Tool to run stack exec prj-exe more easy+homepage:            https://github.com/wapxmas/execs#readme+license:             MIT+license-file:        LICENSE+author:              Sergey N. Yashin+maintainer:          yashin.sergey@gmail.com+copyright:           2016 Sergey N. Yashin+category:            Utils+build-type:          Simple+-- extra-source-files:+cabal-version:       >=1.10++library+  hs-source-dirs:      src+  exposed-modules:     Execs+  build-depends:       base >= 4.7 && < 5+  ghc-options:         -W -Wall+  default-language:    Haskell2010++executable execs+  hs-source-dirs:      app+  main-is:             Main.hs+  ghc-options:         -W -Wall -threaded -rtsopts -with-rtsopts=-N+  build-depends:       base+                     , execs+                     , directory >= 1.2 && < 1.4+                     , text >= 1.2 && < 1.4+                     , process >= 1.2 && < 1.4+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/wapxmas/execs
+ src/Execs.hs view
@@ -0,0 +1,1 @@+module Execs where