add --interrupt-only so yesod does not interrupt on enter
Useful when running multiple jobs in the same shell
This commit is contained in:
parent
84c53fb74f
commit
12d0832f50
@ -7,6 +7,7 @@
|
|||||||
module Devel
|
module Devel
|
||||||
( devel
|
( devel
|
||||||
, DevelOpts(..)
|
, DevelOpts(..)
|
||||||
|
, DevelTermOpt(..)
|
||||||
, defaultDevelOpts
|
, defaultDevelOpts
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@ -100,6 +101,8 @@ removeLock opts = do
|
|||||||
removeFileIfExists (lockFile opts)
|
removeFileIfExists (lockFile opts)
|
||||||
removeFileIfExists "dist/devel-terminate" -- for compatibility with old devel.hs
|
removeFileIfExists "dist/devel-terminate" -- for compatibility with old devel.hs
|
||||||
|
|
||||||
|
data DevelTermOpt = TerminateOnEnter | TerminateOnlyInterrupt
|
||||||
|
deriving (Show, Eq)
|
||||||
data DevelOpts = DevelOpts
|
data DevelOpts = DevelOpts
|
||||||
{ isCabalDev :: Bool
|
{ isCabalDev :: Bool
|
||||||
, forceCabal :: Bool
|
, forceCabal :: Bool
|
||||||
@ -111,13 +114,14 @@ data DevelOpts = DevelOpts
|
|||||||
, develPort :: Int
|
, develPort :: Int
|
||||||
, proxyTimeout :: Int
|
, proxyTimeout :: Int
|
||||||
, useReverseProxy :: Bool
|
, useReverseProxy :: Bool
|
||||||
|
, terminateWith :: DevelTermOpt
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
getBuildDir :: DevelOpts -> String
|
getBuildDir :: DevelOpts -> String
|
||||||
getBuildDir opts = fromMaybe "dist" (buildDir opts)
|
getBuildDir opts = fromMaybe "dist" (buildDir opts)
|
||||||
|
|
||||||
defaultDevelOpts :: DevelOpts
|
defaultDevelOpts :: DevelOpts
|
||||||
defaultDevelOpts = DevelOpts False False False (-1) Nothing Nothing Nothing 3000 10 True
|
defaultDevelOpts = DevelOpts False False False (-1) Nothing Nothing Nothing 3000 10 True TerminateOnEnter
|
||||||
|
|
||||||
cabalProgram :: DevelOpts -> FilePath
|
cabalProgram :: DevelOpts -> FilePath
|
||||||
cabalProgram opts | isCabalDev opts = "cabal-dev"
|
cabalProgram opts | isCabalDev opts = "cabal-dev"
|
||||||
@ -195,12 +199,19 @@ devel opts passThroughArgs = withSocketsDo $ withManager $ \manager -> do
|
|||||||
checkDevelFile
|
checkDevelFile
|
||||||
writeLock opts
|
writeLock opts
|
||||||
|
|
||||||
putStrLn "Yesod devel server. Press ENTER to quit"
|
let (terminator, after) = case terminateWith opts of
|
||||||
_ <- forkIO $ do
|
TerminateOnEnter ->
|
||||||
|
("Press ENTER", void getLine)
|
||||||
|
TerminateOnlyInterrupt -> -- run for one year
|
||||||
|
("Interrupt", threadDelay $ 1000 * 1000 * 60 * 60 * 24 * 365)
|
||||||
|
|
||||||
|
|
||||||
|
putStrLn $ "Yesod devel server. " ++ terminator ++ " to quit"
|
||||||
|
void $ forkIO $ do
|
||||||
filesModified <- newEmptyMVar
|
filesModified <- newEmptyMVar
|
||||||
watchTree manager "." (const True) (\_ -> void (tryPutMVar filesModified ()))
|
watchTree manager "." (const True) (\_ -> void (tryPutMVar filesModified ()))
|
||||||
evalStateT (mainOuterLoop iappPort filesModified) Map.empty
|
evalStateT (mainOuterLoop iappPort filesModified) Map.empty
|
||||||
_ <- getLine
|
after
|
||||||
writeLock opts
|
writeLock opts
|
||||||
exitSuccess
|
exitSuccess
|
||||||
where
|
where
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP #-}
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
|
|
||||||
import Control.Monad (unless)
|
import Control.Monad (unless)
|
||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
@ -9,7 +9,7 @@ import System.Exit (ExitCode (ExitSuccess), exitWith)
|
|||||||
import System.Process (rawSystem)
|
import System.Process (rawSystem)
|
||||||
|
|
||||||
import AddHandler (addHandler)
|
import AddHandler (addHandler)
|
||||||
import Devel (DevelOpts (..), devel)
|
import Devel (DevelOpts (..), devel, DevelTermOpt(..))
|
||||||
import Keter (keter)
|
import Keter (keter)
|
||||||
import Options (injectDefaults)
|
import Options (injectDefaults)
|
||||||
import qualified Paths_yesod_bin
|
import qualified Paths_yesod_bin
|
||||||
@ -60,6 +60,7 @@ data Command = Init { _initBare :: Bool }
|
|||||||
, _develPort :: Int
|
, _develPort :: Int
|
||||||
, _proxyTimeout :: Int
|
, _proxyTimeout :: Int
|
||||||
, _noReverseProxy :: Bool
|
, _noReverseProxy :: Bool
|
||||||
|
, _interruptOnly :: Bool
|
||||||
}
|
}
|
||||||
| Test
|
| Test
|
||||||
| AddHandler
|
| AddHandler
|
||||||
@ -75,36 +76,45 @@ cabalCommand mopt
|
|||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
o <- execParser =<< injectDefaults "yesod" [ ("yesod.devel.extracabalarg" , \o args -> o { optCommand =
|
o <- execParser =<< injectDefaults "yesod"
|
||||||
case optCommand o of
|
[ ("yesod.devel.extracabalarg" , \o args -> o { optCommand =
|
||||||
d@Devel{} -> d { develExtraArgs = args }
|
case optCommand o of
|
||||||
c -> c
|
d@Devel{} -> d { develExtraArgs = args }
|
||||||
})
|
c -> c
|
||||||
, ("yesod.devel.ignore" , \o args -> o { optCommand =
|
})
|
||||||
case optCommand o of
|
, ("yesod.devel.ignore" , \o args -> o { optCommand =
|
||||||
d@Devel{} -> d { develIgnore = args }
|
case optCommand o of
|
||||||
c -> c
|
d@Devel{} -> d { develIgnore = args }
|
||||||
})
|
c -> c
|
||||||
, ("yesod.build.extracabalarg" , \o args -> o { optCommand =
|
})
|
||||||
case optCommand o of
|
, ("yesod.build.extracabalarg" , \o args -> o { optCommand =
|
||||||
b@Build{} -> b { buildExtraArgs = args }
|
case optCommand o of
|
||||||
c -> c
|
b@Build{} -> b { buildExtraArgs = args }
|
||||||
})
|
c -> c
|
||||||
] optParser'
|
})
|
||||||
let cabal xs = rawSystem' (cabalCommand o) xs
|
] optParser'
|
||||||
|
let cabal = rawSystem' (cabalCommand o)
|
||||||
case optCommand o of
|
case optCommand o of
|
||||||
Init bare -> scaffold bare
|
Init bare -> scaffold bare
|
||||||
Configure -> cabal ["configure"]
|
Configure -> cabal ["configure"]
|
||||||
Build es -> touch' >> cabal ("build":es)
|
Build es -> touch' >> cabal ("build":es)
|
||||||
Touch -> touch'
|
Touch -> touch'
|
||||||
Devel da s f r b _ig es p t nrp -> devel (DevelOpts (optCabalPgm o == CabalDev) da (optVerbose o) r s f b p t (not nrp)) es
|
Keter noRebuild -> keter (cabalCommand o) noRebuild
|
||||||
Keter noRebuild -> keter (cabalCommand o) noRebuild
|
Version -> putStrLn ("yesod-bin version: " ++ showVersion Paths_yesod_bin.version)
|
||||||
Version -> do putStrLn ("yesod-bin version: " ++ showVersion Paths_yesod_bin.version)
|
AddHandler -> addHandler
|
||||||
AddHandler -> addHandler
|
Test -> cabalTest cabal
|
||||||
Test -> do touch'
|
Devel{..} -> devel (DevelOpts
|
||||||
cabal ["configure", "--enable-tests", "-flibrary-only"]
|
(optCabalPgm o == CabalDev) _develDisableApi (optVerbose o)
|
||||||
cabal ["build"]
|
_develRescan _develSuccessHook _develFailHook
|
||||||
cabal ["test"]
|
_develBuildDir _develPort _proxyTimeout
|
||||||
|
(not _noReverseProxy)
|
||||||
|
(if _interruptOnly then TerminateOnlyInterrupt else TerminateOnEnter )
|
||||||
|
) develExtraArgs
|
||||||
|
where
|
||||||
|
cabalTest cabal = do touch'
|
||||||
|
_ <- cabal ["configure", "--enable-tests", "-flibrary-only"]
|
||||||
|
_ <- cabal ["build"]
|
||||||
|
cabal ["test"]
|
||||||
|
|
||||||
optParser' :: ParserInfo Options
|
optParser' :: ParserInfo Options
|
||||||
optParser' = info (helper <*> optParser) ( fullDesc <> header "Yesod Web Framework command line utility" )
|
optParser' = info (helper <*> optParser) ( fullDesc <> header "Yesod Web Framework command line utility" )
|
||||||
@ -114,7 +124,7 @@ optParser = Options
|
|||||||
<$> flag Cabal CabalDev ( long "dev" <> short 'd' <> help "use cabal-dev" )
|
<$> flag Cabal CabalDev ( long "dev" <> short 'd' <> help "use cabal-dev" )
|
||||||
<*> switch ( long "verbose" <> short 'v' <> help "More verbose output" )
|
<*> switch ( long "verbose" <> short 'v' <> help "More verbose output" )
|
||||||
<*> subparser ( command "init"
|
<*> subparser ( command "init"
|
||||||
(info (Init <$> (switch (long "bare" <> help "Create files in current folder")))
|
(info (Init <$> switch (long "bare" <> help "Create files in current folder"))
|
||||||
(progDesc "Scaffold a new site"))
|
(progDesc "Scaffold a new site"))
|
||||||
<> command "configure" (info (pure Configure)
|
<> command "configure" (info (pure Configure)
|
||||||
(progDesc "Configure a project for building"))
|
(progDesc "Configure a project for building"))
|
||||||
@ -158,6 +168,8 @@ develOptions = Devel <$> switch ( long "disable-api" <> short 'd'
|
|||||||
<> help "Devel server timeout before returning 'not ready' message (in seconds, 0 for none)" )
|
<> help "Devel server timeout before returning 'not ready' message (in seconds, 0 for none)" )
|
||||||
<*> switch ( long "disable-reverse-proxy" <> short 'n'
|
<*> switch ( long "disable-reverse-proxy" <> short 'n'
|
||||||
<> help "Disable reverse proxy" )
|
<> help "Disable reverse proxy" )
|
||||||
|
<*> switch ( long "interrupt-only" <> short 'c'
|
||||||
|
<> help "Disable exiting when enter is pressed")
|
||||||
|
|
||||||
extraCabalArgs :: Parser [String]
|
extraCabalArgs :: Parser [String]
|
||||||
extraCabalArgs = many (strOption ( long "extra-cabal-arg" <> short 'e' <> metavar "ARG"
|
extraCabalArgs = many (strOption ( long "extra-cabal-arg" <> short 'e' <> metavar "ARG"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
name: yesod-bin
|
name: yesod-bin
|
||||||
version: 1.2.4.1
|
version: 1.2.5
|
||||||
license: MIT
|
license: MIT
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
author: Michael Snoyman <michael@snoyman.com>
|
author: Michael Snoyman <michael@snoyman.com>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user