now the webapp has the same options as the assistant

This commit is contained in:
Joey Hess 2012-07-27 15:40:52 -04:00
parent 02ec8ea012
commit adae40a292

View file

@ -12,37 +12,33 @@ import Command
import Assistant import Assistant
import Utility.WebApp import Utility.WebApp
import Utility.Daemon (checkDaemon) import Utility.Daemon (checkDaemon)
import Option import qualified Command.Watch
def :: [Command] def :: [Command]
def = [withOptions [restartOption] $ def = [withOptions [Command.Watch.foregroundOption, Command.Watch.stopOption] $
command "webapp" paramNothing seek "launch webapp"] command "webapp" paramNothing seek "launch webapp"]
restartOption :: Option
restartOption = Option.flag [] "restart" "restart the assistant daemon"
seek :: [CommandSeek] seek :: [CommandSeek]
seek = [withFlag restartOption $ \restart -> withNothing $ start restart] seek = [withFlag Command.Watch.stopOption $ \stopdaemon ->
withFlag Command.Watch.foregroundOption $ \foreground ->
withNothing $ start foreground stopdaemon]
start :: Bool -> CommandStart start :: Bool -> Bool -> CommandStart
start restart = notBareRepo $ do start foreground stopdaemon = notBareRepo $ do
f <- liftIO . absPath =<< fromRepo gitAnnexHtmlShim if stopdaemon
if restart then stopDaemon
then do else do
stopDaemon f <- liftIO . absPath =<< fromRepo gitAnnexHtmlShim
void $ liftIO . nukeFile =<< fromRepo gitAnnexPidFile ifM (checkpid <&&> checkshim f) $
startassistant f ( liftIO $ go f
else ifM (checkpid <&&> checkshim f) $ , startDaemon True foreground $ Just $ go f
( liftIO $ go f )
, startassistant f
)
stop stop
where where
checkpid = do checkpid = do
pidfile <- fromRepo gitAnnexPidFile pidfile <- fromRepo gitAnnexPidFile
liftIO $ isJust <$> checkDaemon pidfile liftIO $ isJust <$> checkDaemon pidfile
checkshim f = liftIO $ doesFileExist f checkshim f = liftIO $ doesFileExist f
startassistant = startDaemon True False . Just . go
go f = unlessM (runBrowser url) $ go f = unlessM (runBrowser url) $
error $ "failed to start web browser on url " ++ url error $ "failed to start web browser on url " ++ url
where where