packages feed

hs-snowtify (empty) → 0.1.0.0

raw patch · 5 files changed

+163/−0 lines, 5 filesdep +basedep +eitherdep +safesetup-changed

Dependencies added: base, either, safe, safe-exceptions, text, turtle

Files

+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License (MIT)++Copyright (c) 2017 aiya000++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.
+ README.md view
@@ -0,0 +1,40 @@+# :snowman: hs-snowtify :snowman:+snowtify send your result of `stack build` (`stack test`) to notify-daemon :dog2:++![screenshot](screenshot.png)+++# :notes: Usage :notes:+```console+$ snowtify test+(`stack test` results is shown, it is like above screenshot)+$ snowtify build+(same as snowtify test, but stack build is executed)+$ snowtify+(same as snowtify build, snowtify run build by default)+```+++# :muscle: Example :muscle:+```console+$ dunst &+(dunst is a notify-daemon)+$ cd <some haskell project directory>+$ watchexec -w . 'snotify test'+(`stack test` results is shown after you update some file)+```+++# :diamonds: How to install this ? :diamonds:++- This way is never supported now ~~1. Use haskell-stack~~++```console+$ stack install snowtify+```++- 2. Use cabal++```console+$ cabal install snowtify+```
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hs-snowtify.cabal view
@@ -0,0 +1,25 @@+name:                hs-snowtify+version:             0.1.0.0+synopsis:            snowtify send your result of `stack build` (`stack test`) to notify-daemon :dog2:+description:         snowtify send your result of `stack build` (`stack test`) to notify-daemon :dog2:+homepage:            https://github.com/aiya000/hs-snowtify#README.md+license:             MIT+license-file:        LICENSE+author:              aiya000+maintainer:          aiya000.develop@gmail.com+copyright:           aiya000+category:            Simple+build-type:          Simple+cabal-version:       >=1.10+extra-source-files:  README.md++executable snowtify+  hs-source-dirs:      src+  main-is:             Main.hs+  default-language:    Haskell2010+  build-depends:       base >= 4.7 && < 5+                     , either+                     , safe+                     , safe-exceptions+                     , text+                     , turtle
+ src/Main.hs view
@@ -0,0 +1,75 @@+{-# LANGUAGE OverloadedStrings #-}++module Main (main) where++import Control.Exception.Safe (MonadThrow, SomeException)+import Control.Monad (void, forM_, when)+import Control.Monad.IO.Class (MonadIO, liftIO)+import Control.Monad.Trans.Either (runEitherT)+import Data.Either (isLeft)+import Data.List (foldl')+import Data.Monoid ((<>))+import Data.Text (Text)+import Safe (headMay)+import Turtle (Shell, sh, arguments, procStrictWithErr, ExitCode(..), cut, Pattern, newline, spaces, proc)+import qualified Data.Text as T+import qualified Data.Text.IO as TIO+++-- | Call `execute` with a haskell-stack command+main :: IO ()+main = runEitherT getBuildCommand >>= sh . execute+  where+    -- Get a sub command of haskell-stack from CLI arguments.+    -- This must be "build" or "test", or empty.+    -- If CLI arguments is not given, return "build".+    -- If CLI arguments is neither "build" nor "test", throw an exception.+    getBuildCommand :: (MonadIO m, MonadThrow m) => m Text+    getBuildCommand = do+      args <- headMay <$> liftIO arguments+      case args of+        Nothing      -> return "build" -- run 'build' by default+        Just "test"  -> return "test"+        Just "build" -> return "build"+        Just unknown -> fail . T.unpack $ "snowtify doesn't know '" <> unknown <> "' command x("+++execute :: Either SomeException Text -> Shell ()+execute (Left err)      = liftIO $ print err+execute (Right command) = do+  (exitCode, out, err) <- procStrictWithErr "stack" [command] ""+  let result = out <> err+  let notifyer = if exitCode == ExitSuccess+                    then notifySucceeding+                    else notifyErrors+  notifyer result+++-- | Show succeeding with the notify-daemon+notifySucceeding :: Text -> Shell ()+notifySucceeding = void . notifySend . ("stack test is succeed: " <>)++-- | Show errors with the notify-daemon+notifyErrors :: Text -> Shell ()+notifyErrors result = do+  let blobs = cut sections result+  notifySend "stack test is finished with errors"+  forM_ blobs $ \blob ->+    when (isErrorSection blob) . void $ notifySend blob+  where+    sections :: Pattern ()+    sections = void $ do+      newline+      spaces+      newline++    isErrorSection :: Text -> Bool+    isErrorSection x =+      case headMay $ T.lines x of+        Nothing        -> False+        Just firstLine -> any (== "error:") $ T.words firstLine+++-- | Send a message to the notify-daemon+notifySend :: Text -> Shell ExitCode+notifySend msg = proc "notify-send" ["snowtify", msg] ""