twitch 0.1.2.2 → 0.1.3.0
raw patch · 7 files changed
+63/−15 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Twitch: Config :: (Issue -> IO ()) -> [FilePath] -> WatchConfig -> Config
+ Twitch: Options :: LoggerType -> Maybe FilePath -> [FilePath] -> Bool -> DebounceType -> Double -> Int -> Bool -> Maybe FilePath -> Options
+ Twitch: currentDir :: Options -> Maybe FilePath
+ Twitch: data Config
+ Twitch: data Options
+ Twitch: debounce :: Options -> DebounceType
+ Twitch: debounceAmount :: Options -> Double
+ Twitch: defaultMainWithOptions :: Options -> Dep -> IO ()
+ Twitch: dirs :: Config -> [FilePath]
+ Twitch: dirsToWatch :: Options -> [FilePath]
+ Twitch: log :: Options -> LoggerType
+ Twitch: logFile :: Options -> Maybe FilePath
+ Twitch: logger :: Config -> Issue -> IO ()
+ Twitch: pollInterval :: Options -> Int
+ Twitch: recurseThroughDirectories :: Options -> Bool
+ Twitch: runWithConfig :: FilePath -> Config -> Dep -> IO WatchManager
+ Twitch: usePolling :: Options -> Bool
+ Twitch: watchConfig :: Config -> WatchConfig
Files
- src/Twitch.hs +7/−1
- src/Twitch/Internal.hs +32/−0
- src/Twitch/InternalRule.hs +8/−9
- src/Twitch/Main.hs +11/−3
- src/Twitch/Rule.hs +3/−0
- src/Twitch/Run.hs +1/−1
- twitch.cabal +1/−1
src/Twitch.hs view
@@ -73,12 +73,18 @@ , delete , addModify , name- -- Running as a library+ -- * Advanced Main+ , Options (..)+ , defaultMainWithOptions+ -- * Running as a library+ , Config (..) , run+ , runWithConfig -- * Extra , DepM ) where import Twitch.Internal +import Twitch.InternalRule (Config (..)) import Twitch.Main import Twitch.Run import Twitch.Rule (Rule, RuleAction, Name, PatternText)
src/Twitch/Internal.hs view
@@ -60,30 +60,62 @@ infixl 8 |+, |%, |-, |>, |# (|+), (|%), (|-), (|>) :: Dep -> (FilePath -> IO a) -> Dep -- | Add a \'add\' callback+-- ex.+--+-- > "*.png" |+ addToManifest x |+ f = modHeadRule x $ Rule.addF f -- | Add a \'modify\' callback+-- ex.+--+-- > "*.c" |% [s|gcc -o$directory$basename.o $path|] x |% f = modHeadRule x $ Rule.modifyF f -- | Add a \'delete' callback+-- ex.+--+-- > "*.c" |- [s|gcc -o$directory$basename.o $path|] x |- f = modHeadRule x $ Rule.deleteF f -- | Add the same callback for the \'add\' and the \'modify\' events.+-- ex.+--+-- > "*.md" |> [s|pandoc -t html $path|]+-- +-- Defined as: x '|>' f = x '|+' f '|%' f x |> f = x |+ f |% f -- | Set the name of a rule. Useful for debugging when logging is enabled. -- Rules names default to the glob pattern.+-- ex.+--+-- > "*.md" |> [s|pandoc -t html $path|] |# "markdown to html" (|#) :: Dep -> Text -> Dep r |# p = modHeadRule r $ Rule.nameF p -- Prefix API ----------------------------------------------------------------- add, modify, delete, addModify :: (FilePath -> IO a) -> Dep -> Dep -- | Add a \'add\' callback+-- ex.+--+-- > add addToManifest "*.png" add = flip (|+) -- | Add a \'modify\' callback+-- ex.+--+-- > mod [s|gcc -o$directory$basename.o $path|] "*.c" modify = flip (|%) -- | Add a \'delete' callback+-- ex.+--+-- > delete [s|gcc -o$directory$basename.o $path|] "*.c" delete = flip (|-) -- | Add the same callback for the \'add\' and the \'modify\' events.+-- ex.+--+-- > addModify [s|pandoc -t html $path|] "*.md" addModify = flip (|>) -- | Set the name of a rule. Useful for debugging when logging is enabled. -- Rules names default to the glob pattern.+-- ex.+--+-- > name "markdown to html" $ addModify [s|pandoc -t html $path|] "*.md" name :: Text -> Dep -> Dep name = flip (|#)
src/Twitch/InternalRule.hs view
@@ -66,9 +66,9 @@ -- | Configuration to run the file watcher data Config = Config - { log :: Issue -> IO ()+ { logger :: Issue -> IO () -- ^ A logger for the issues - , dirsToWatch :: [FilePath]+ , dirs :: [FilePath] -- ^ The directories to watch , watchConfig :: WatchConfig -- ^ config for the file watcher@@ -77,13 +77,13 @@ instance Show Config where show Config {..} = "Config { dirsToWatch = " - ++ show dirsToWatch+ ++ show dirs ++ "}" instance Default Config where def = Config- { log = def- , dirsToWatch = def+ { logger = def+ , dirs = def , watchConfig = defaultConfig } @@ -121,7 +121,7 @@ testAndFireRule Config {..} event rule = do let shouldFire = fileTest rule (filePath event) (time event) when shouldFire $ do - log $ IRuleFired event rule+ logger $ IRuleFired event rule fireRule event rule -- TODO in the future this should use the recursive directory functions@@ -131,13 +131,12 @@ setupRuleForDir config@(Config {..}) man rules dirPath = do -- TODO Instead of const True, this should use the rule's fileTests void $ watchDir man dirPath (const True) $ \event -> do - print event- log $ IEvent event+ logger $ IEvent event forM_ rules $ testAndFireRule config event -- | Setup all of the directory watches using the rules setupRules :: Config -> [InternalRule] -> IO WatchManager setupRules config@(Config {..}) rules = do man <- startManagerConf watchConfig- forM_ dirsToWatch $ setupRuleForDir config man rules+ forM_ dirs $ setupRuleForDir config man rules return man
src/Twitch/Main.hs view
@@ -176,8 +176,8 @@ } let config = IR.Config- { log = logger- , dirsToWatch = dirsToWatch''+ { logger = logger+ , dirs = dirsToWatch'' , watchConfig = watchConfig } return (currentDir', config, mhandle)@@ -192,11 +192,19 @@ <> progDesc "Print a greeting for TARGET" <> header "hello - a test for optparse-applicative" )- (currentDir, config, mhandle) <- optionsToConfig =<< execParser opts+ options <- execParser opts+ defaultMainWithOptions options dep++-- | A main file that uses manually supplied options instead of parsing the passed in arguments.+defaultMainWithOptions :: Options -> Dep -> IO ()+defaultMainWithOptions options dep = do+ (currentDir, config, mhandle) <- optionsToConfig options let currentDir' = F.decodeString currentDir manager <- runWithConfig currentDir' config dep putStrLn "Type anything to quit" _ <- getLine for_ mhandle hClose FS.stopManager manager+ +
src/Twitch/Rule.hs view
@@ -66,6 +66,9 @@ infixl 8 |+, |%, |-, |>, |# (|+), (|%), (|-), (|>) :: Rule -> (FilePath -> IO a) -> Rule -- | Set the 'add' field+-- ex.+-- +-- > "doodle.md |+ ringBell " x |+ f = x { add = void . f } -- | Set the modify field x |% f = x { modify = void . f }
src/Twitch/Run.hs view
@@ -19,7 +19,7 @@ run dep = do currentDir <- decodeString <$> getCurrentDirectory dirs <- findAllDirs currentDir- runWithConfig currentDir (def { log = print, dirsToWatch = dirs }) dep+ runWithConfig currentDir (def { logger = print, dirs = dirs }) dep runWithConfig :: FilePath -> Config -> Dep -> IO WatchManager runWithConfig currentDir config dep = do
twitch.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: twitch-version: 0.1.2.2+version: 0.1.3.0 synopsis: A high level file watcher DSL description: Twitch is a monadic DSL and library for file watching.