use options library for command line options
This commit is contained in:
parent
0ee840da44
commit
0fcb55960c
@ -145,7 +145,7 @@ rebuildGhc bf ld ar = do
|
|||||||
|
|
||||||
rebuildCabal :: String -> IO Bool
|
rebuildCabal :: String -> IO Bool
|
||||||
rebuildCabal cmd = do
|
rebuildCabal cmd = do
|
||||||
putStrLn "Rebuilding application... (cabal)"
|
putStrLn $ "Rebuilding application... (" ++ cmd ++ ")"
|
||||||
exit <- rawSystemFilter cmd ["build"]
|
exit <- rawSystemFilter cmd ["build"]
|
||||||
return $ case exit of
|
return $ case exit of
|
||||||
ExitSuccess -> True
|
ExitSuccess -> True
|
||||||
|
|||||||
24
yesod/Types.hs
Normal file
24
yesod/Types.hs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
|
||||||
|
module Types where
|
||||||
|
|
||||||
|
import Options
|
||||||
|
|
||||||
|
|
||||||
|
mkOptCabalDev name = option name (\o -> o
|
||||||
|
{ optionLongFlags = ["dev", "use-cabal-dev"]
|
||||||
|
, optionShortFlags = ['d']
|
||||||
|
, optionType = optionTypeBool
|
||||||
|
, optionDefault = "false"
|
||||||
|
, optionDescription = "use cabal-dev to build the package"
|
||||||
|
})
|
||||||
|
|
||||||
|
mkOptNoApi name = option name (\o -> o
|
||||||
|
{ optionLongFlags = ["no-ghc-api"]
|
||||||
|
, optionShortFlags = ['n']
|
||||||
|
, optionType = optionTypeBool
|
||||||
|
, optionDefault = "false"
|
||||||
|
, optionDescription = "do not use the GHC API to build, use `cabal build' instead"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP, TemplateHaskell #-}
|
||||||
|
|
||||||
import Scaffolding.Scaffolder
|
import Scaffolding.Scaffolder
|
||||||
import System.Environment (getArgs)
|
import System.Environment (getArgs)
|
||||||
@ -6,48 +6,63 @@ import System.Exit (exitWith)
|
|||||||
import System.Process (rawSystem)
|
import System.Process (rawSystem)
|
||||||
import Yesod.Core(yesodVersion)
|
import Yesod.Core(yesodVersion)
|
||||||
|
|
||||||
#ifndef WINDOWS
|
import Options
|
||||||
|
import Types
|
||||||
|
|
||||||
import Build (touch)
|
import Build (touch)
|
||||||
#endif
|
|
||||||
import Devel (devel)
|
import Devel (devel)
|
||||||
|
|
||||||
windowsWarning :: String
|
defineOptions "NoOptions" (return ())
|
||||||
#ifdef WINDOWS
|
|
||||||
windowsWarning = "\n (does not work on Windows)"
|
defineOptions "DevelOptions" $ do
|
||||||
#else
|
mkOptNoApi "develOptNoApi"
|
||||||
windowsWarning = ""
|
|
||||||
#endif
|
defineOptions "MainOptions" $ do
|
||||||
|
mkOptCabalDev "optCabalDev"
|
||||||
|
|
||||||
|
type InitOptions = NoOptions
|
||||||
|
type ConfigureOptions = NoOptions
|
||||||
|
type BuildOptions = NoOptions
|
||||||
|
type TouchOptions = NoOptions
|
||||||
|
type VersionOptions = NoOptions
|
||||||
|
|
||||||
|
cabalCommand :: MainOptions -> String
|
||||||
|
cabalCommand mopt
|
||||||
|
| optCabalDev mopt = "cabal-dev"
|
||||||
|
| otherwise = "cabal"
|
||||||
|
|
||||||
|
main = runSubcommand
|
||||||
|
[ subcommand "init" cmdInit
|
||||||
|
, subcommand "configure" cmdConfigure
|
||||||
|
#ifndef WINDOWS
|
||||||
|
, subcommand "build" cmdBuild
|
||||||
|
, subcommand "touch" cmdTouch
|
||||||
|
#endif
|
||||||
|
, subcommand "devel" cmdDevel
|
||||||
|
, subcommand "version" cmdVersion
|
||||||
|
]
|
||||||
|
|
||||||
|
cmdInit :: MainOptions -> InitOptions -> [String] -> IO ()
|
||||||
|
cmdInit _ _ _ = scaffold
|
||||||
|
|
||||||
|
cmdConfigure :: MainOptions -> ConfigureOptions -> [String] -> IO ()
|
||||||
|
cmdConfigure mopt opts args = exitWith =<< rawSystem (cabalCommand mopt) ("configure":args)
|
||||||
|
|
||||||
|
cmdBuild :: MainOptions -> BuildOptions -> [String] -> IO ()
|
||||||
|
cmdBuild mopt opts args = do
|
||||||
|
touch
|
||||||
|
exitWith =<< rawSystem (cabalCommand mopt) ("build":args)
|
||||||
|
|
||||||
|
cmdTouch :: MainOptions -> TouchOptions -> [String] -> IO ()
|
||||||
|
cmdTouch _ _ _ = touch
|
||||||
|
|
||||||
|
cmdDevel :: MainOptions -> DevelOptions -> [String] -> IO ()
|
||||||
|
cmdDevel mopt opts args = devel (optCabalDev mopt) args
|
||||||
|
where
|
||||||
|
forceCabal = develOptNoApi opts
|
||||||
|
|
||||||
|
cmdVersion :: MainOptions -> VersionOptions -> [String] -> IO ()
|
||||||
|
cmdVersion _ _ _ = putStrLn $ "yesod-core version: " ++ yesodVersion
|
||||||
|
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = do
|
|
||||||
args' <- getArgs
|
|
||||||
let (isDev, args) =
|
|
||||||
case args' of
|
|
||||||
"--dev":rest -> (True, rest)
|
|
||||||
_ -> (False, args')
|
|
||||||
let cmd = if isDev then "cabal-dev" else "cabal"
|
|
||||||
#ifndef WINDOWS
|
|
||||||
let build rest = rawSystem cmd $ "build":rest
|
|
||||||
#endif
|
|
||||||
case args of
|
|
||||||
["init"] -> scaffold
|
|
||||||
#ifndef WINDOWS
|
|
||||||
"build":rest -> touch >> build rest >>= exitWith
|
|
||||||
["touch"] -> touch
|
|
||||||
#endif
|
|
||||||
"devel":rest -> devel isDev rest
|
|
||||||
["version"] -> putStrLn $ "yesod-core version:" ++ yesodVersion
|
|
||||||
"configure":rest -> rawSystem cmd ("configure":rest) >>= exitWith
|
|
||||||
_ -> do
|
|
||||||
putStrLn "Usage: yesod <command>"
|
|
||||||
putStrLn "Available commands:"
|
|
||||||
putStrLn " init Scaffold a new site"
|
|
||||||
putStrLn " configure Configure a project for building"
|
|
||||||
putStrLn $ " build Build project (performs TH dependency analysis)"
|
|
||||||
++ windowsWarning
|
|
||||||
putStrLn $ " touch Touch any files with altered TH dependencies but do not build"
|
|
||||||
++ windowsWarning
|
|
||||||
putStrLn " devel Run project with the devel server"
|
|
||||||
putStrLn " use --dev devel to build with cabal-dev"
|
|
||||||
putStrLn " version Print the version of Yesod"
|
|
||||||
|
|
||||||
|
|||||||
@ -88,6 +88,7 @@ library
|
|||||||
, shakespeare-css >= 1.0 && < 1.1
|
, shakespeare-css >= 1.0 && < 1.1
|
||||||
, warp >= 1.2 && < 1.3
|
, warp >= 1.2 && < 1.3
|
||||||
, blaze-html >= 0.4.1.3 && < 0.5
|
, blaze-html >= 0.4.1.3 && < 0.5
|
||||||
|
, options >= 0.1 && < 0.2
|
||||||
exposed-modules: Yesod
|
exposed-modules: Yesod
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user