git-annex/Command/Watch.hs

37 lines
1,003 B
Haskell
Raw Normal View History

2012-06-13 16:36:33 +00:00
{- git-annex watch command
2012-06-11 19:41:26 +00:00
-
- Copyright 2012 Joey Hess <id@joeyh.name>
2012-06-11 19:41:26 +00:00
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.Watch where
import Common.Annex
2012-06-13 16:36:33 +00:00
import Assistant
import Command
import Utility.HumanTime
cmd :: [Command]
cmd = [notBareRepo $ withOptions [foregroundOption, stopOption] $
command "watch" paramNothing seek SectionCommon "watch for changes and autocommit"]
seek :: CommandSeek
seek ps = do
stopdaemon <- getOptionFlag stopOption
foreground <- getOptionFlag foregroundOption
withNothing (start False foreground stopdaemon Nothing) ps
2012-06-11 04:39:09 +00:00
foregroundOption :: Option
2014-01-26 20:25:55 +00:00
foregroundOption = flagOption [] "foreground" "do not daemonize"
2012-06-11 04:39:09 +00:00
2012-06-11 06:01:20 +00:00
stopOption :: Option
2014-01-26 20:25:55 +00:00
stopOption = flagOption [] "stop" "stop daemon"
2012-06-11 06:01:20 +00:00
start :: Bool -> Bool -> Bool -> Maybe Duration -> CommandStart
start assistant foreground stopdaemon startdelay = do
2012-06-11 06:01:20 +00:00
if stopdaemon
2012-06-13 16:36:33 +00:00
then stopDaemon
2013-11-17 18:58:35 +00:00
else startDaemon assistant foreground startdelay Nothing Nothing Nothing -- does not return
2012-06-10 21:40:35 +00:00
stop