packages feed

rasa-ext-cmd (empty) → 0.1.0.0

raw patch · 4 files changed

+96/−0 lines, 4 filesdep +basedep +containersdep +data-defaultsetup-changed

Dependencies added: base, containers, data-default, lens, rasa, text

Files

+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License++Copyright (c) 2016 Chris Penner++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
+ rasa-ext-cmd.cabal view
@@ -0,0 +1,33 @@+name:                rasa-ext-cmd+version:             0.1.0.0+synopsis:            Rasa Ext for running commands+description:         Rasa Ext for running commands+homepage:            https://github.com/ChrisPenner/rasa/+license:             MIT+license-file:        LICENSE+author:              Chris Penner+maintainer:          christopher.penner@gmail.com+copyright:           2016 Chris Penner+category:            Extension+build-type:          Simple+-- extra-source-files:+cabal-version:       >=1.10++library+  hs-source-dirs:      src+  exposed-modules:+                       Rasa.Ext.Cmd++  build-depends:       base >= 4.7 && < 5+                     , rasa+                     , data-default+                     , lens+                     , text+                     , containers+  default-language:    Haskell2010++  ghc-options:         -Wall++source-repository head+  type:     git+  location: https://github.com/ChrisPenner/rasa
+ src/Rasa/Ext/Cmd.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE TemplateHaskell #-}++module Rasa.Ext.Cmd+  ( addCmd+  , runCmd+  ) where++import Rasa.Ext++import Control.Lens+import Data.Map+import Data.Default+import Data.Typeable+import qualified Data.Text as T++data Cmd = Cmd+  { _commands :: Map T.Text (T.Text -> Action ())+  } deriving (Typeable)++instance Show Cmd where+  show (Cmd cmds) = show (keys cmds)++makeLenses ''Cmd++instance Default Cmd where+  def = Cmd+    { _commands=empty+    }++-- It would be nice to make this a little more generic, but I'm not sure how right now.+-- TODO try switching to T.Text -> (T.Text -> a) -> Action ()+addCmd :: T.Text -> (T.Text -> Action ()) -> Action ()+addCmd alias mkEvent = ext.commands.at alias ?= mkEvent++runCmd :: T.Text -> T.Text -> Action ()+runCmd alias args = do+  mCmd <- use (ext.commands.at alias)+  case mCmd of+    Just cmd -> cmd args+    Nothing -> return ()