git-annex/Command/Watch.hs

37 lines
991 B
Haskell
Raw Normal View History

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