add assistant command
like watch, but more magic
This commit is contained in:
		
					parent
					
						
							
								cf9bf920e8
							
						
					
				
			
			
				commit
				
					
						3ee44cf8fe
					
				
			
		
					 5 changed files with 36 additions and 12 deletions
				
			
		| 
						 | 
				
			
			@ -55,10 +55,10 @@ import Utility.LogFile
 | 
			
		|||
 | 
			
		||||
import Control.Concurrent
 | 
			
		||||
 | 
			
		||||
startDaemon :: Bool -> Annex ()
 | 
			
		||||
startDaemon foreground
 | 
			
		||||
startDaemon :: Bool -> Bool -> Annex ()
 | 
			
		||||
startDaemon assistant foreground
 | 
			
		||||
	| foreground = do
 | 
			
		||||
		showStart "watch" "."
 | 
			
		||||
		showStart (if assistant then "assistant" else "watch") "."
 | 
			
		||||
		go id
 | 
			
		||||
	| otherwise = do
 | 
			
		||||
		logfd <- liftIO . openLog =<< fromRepo gitAnnexLogFile
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										18
									
								
								Command/Assistant.hs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								Command/Assistant.hs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,18 @@
 | 
			
		|||
{- git-annex assistant
 | 
			
		||||
 -
 | 
			
		||||
 - Copyright 2012 Joey Hess <joey@kitenet.net>
 | 
			
		||||
 -
 | 
			
		||||
 - Licensed under the GNU GPL version 3 or higher.
 | 
			
		||||
 -}
 | 
			
		||||
 | 
			
		||||
module Command.Assistant where
 | 
			
		||||
 | 
			
		||||
import Command
 | 
			
		||||
import qualified Command.Watch
 | 
			
		||||
 | 
			
		||||
def :: [Command]
 | 
			
		||||
def = [withOptions [Command.Watch.foregroundOption, Command.Watch.stopOption] $ 
 | 
			
		||||
	command "assistant" paramNothing seek "automatically handle changes"]
 | 
			
		||||
 | 
			
		||||
seek :: [CommandSeek]
 | 
			
		||||
seek = Command.Watch.mkSeek True
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +1,3 @@
 | 
			
		|||
{-# LANGUAGE CPP #-}
 | 
			
		||||
{-# LANGUAGE BangPatterns #-}
 | 
			
		||||
 | 
			
		||||
{- git-annex watch command
 | 
			
		||||
 -
 | 
			
		||||
 - Copyright 2012 Joey Hess <joey@kitenet.net>
 | 
			
		||||
| 
						 | 
				
			
			@ -19,10 +16,13 @@ def :: [Command]
 | 
			
		|||
def = [withOptions [foregroundOption, stopOption] $ 
 | 
			
		||||
	command "watch" paramNothing seek "watch for changes"]
 | 
			
		||||
 | 
			
		||||
seek :: [CommandSeek]
 | 
			
		||||
seek = [withFlag stopOption $ \stopdaemon -> 
 | 
			
		||||
mkSeek :: Bool -> [CommandSeek]
 | 
			
		||||
mkSeek assistant = [withFlag stopOption $ \stopdaemon -> 
 | 
			
		||||
	withFlag foregroundOption $ \foreground ->
 | 
			
		||||
	withNothing $ start foreground stopdaemon]
 | 
			
		||||
	withNothing $ start assistant foreground stopdaemon]
 | 
			
		||||
 | 
			
		||||
seek :: [CommandSeek]
 | 
			
		||||
seek = mkSeek False
 | 
			
		||||
 | 
			
		||||
foregroundOption :: Option
 | 
			
		||||
foregroundOption = Option.flag [] "foreground" "do not daemonize"
 | 
			
		||||
| 
						 | 
				
			
			@ -30,9 +30,9 @@ foregroundOption = Option.flag [] "foreground" "do not daemonize"
 | 
			
		|||
stopOption :: Option
 | 
			
		||||
stopOption = Option.flag [] "stop" "stop daemon"
 | 
			
		||||
 | 
			
		||||
start :: Bool -> Bool -> CommandStart
 | 
			
		||||
start foreground stopdaemon = notBareRepo $ do
 | 
			
		||||
start :: Bool -> Bool -> Bool -> CommandStart
 | 
			
		||||
start assistant foreground stopdaemon = notBareRepo $ do
 | 
			
		||||
	if stopdaemon
 | 
			
		||||
		then stopDaemon
 | 
			
		||||
		else startDaemon foreground -- does not return
 | 
			
		||||
		else startDaemon assistant foreground -- does not return
 | 
			
		||||
	stop
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,6 +59,7 @@ import qualified Command.Map
 | 
			
		|||
import qualified Command.Upgrade
 | 
			
		||||
import qualified Command.Version
 | 
			
		||||
import qualified Command.Watch
 | 
			
		||||
import qualified Command.Assistant
 | 
			
		||||
 | 
			
		||||
cmds :: [Command]
 | 
			
		||||
cmds = concat
 | 
			
		||||
| 
						 | 
				
			
			@ -101,6 +102,7 @@ cmds = concat
 | 
			
		|||
	, Command.Upgrade.def
 | 
			
		||||
	, Command.Version.def
 | 
			
		||||
	, Command.Watch.def
 | 
			
		||||
	, Command.Assistant.def
 | 
			
		||||
	]
 | 
			
		||||
 | 
			
		||||
options :: [Option]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -180,6 +180,10 @@ subdirectories).
 | 
			
		|||
  To not daemonize, run with --foreground ; to stop a running daemon,
 | 
			
		||||
  run with --stop
 | 
			
		||||
 | 
			
		||||
* assistant
 | 
			
		||||
 | 
			
		||||
  Like watch, but also automatically syncs changes to other remotes.
 | 
			
		||||
 | 
			
		||||
# REPOSITORY SETUP COMMANDS
 | 
			
		||||
 | 
			
		||||
* init [description]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue