yesod init accepts app name
This commit is contained in:
parent
4fcabc073c
commit
067a21c60f
@ -66,16 +66,14 @@ backendBS Simple = $(embedFile "hsfiles/simple.hsfiles")
|
|||||||
backendBS Minimal = $(embedFile "hsfiles/minimal.hsfiles")
|
backendBS Minimal = $(embedFile "hsfiles/minimal.hsfiles")
|
||||||
|
|
||||||
validPackageName :: String -> Bool
|
validPackageName :: String -> Bool
|
||||||
validPackageName s = isJust (simpleParse s :: Maybe PackageName)
|
validPackageName s = isJust (simpleParse s :: Maybe PackageName) && s /= "test"
|
||||||
|
|
||||||
scaffold :: Bool -- ^ bare directory instead of a new subdirectory?
|
scaffold :: Bool -- ^ bare directory instead of a new subdirectory?
|
||||||
|
-> Maybe String -- ^ application name
|
||||||
-> IO ()
|
-> IO ()
|
||||||
scaffold isBare = do
|
scaffold isBare appName = do
|
||||||
puts $ renderTextUrl undefined $(textFile "input/welcome.cg")
|
puts $ renderTextUrl undefined $(textFile "input/welcome.cg")
|
||||||
project <- prompt $ \s ->
|
project <- projectName appName
|
||||||
if validPackageName s && s /= "test"
|
|
||||||
then Just s
|
|
||||||
else Nothing
|
|
||||||
|
|
||||||
puts $ renderTextUrl undefined $(textFile "input/database.cg")
|
puts $ renderTextUrl undefined $(textFile "input/database.cg")
|
||||||
|
|
||||||
@ -106,3 +104,19 @@ scaffold isBare = do
|
|||||||
else LT.replace "PROJECTNAME" (LT.pack project)
|
else LT.replace "PROJECTNAME" (LT.pack project)
|
||||||
|
|
||||||
TLIO.putStr $ projectnameReplacer $ renderTextUrl undefined $(textFile "input/done.cg")
|
TLIO.putStr $ projectnameReplacer $ renderTextUrl undefined $(textFile "input/done.cg")
|
||||||
|
|
||||||
|
projectName :: Maybe String -- ^ application name
|
||||||
|
-> IO String
|
||||||
|
projectName appName = case appName of
|
||||||
|
Nothing -> askForProjectName
|
||||||
|
Just name ->
|
||||||
|
if validPackageName name
|
||||||
|
then return name
|
||||||
|
else do
|
||||||
|
putStr "Given application name is not valid, please choose another one"
|
||||||
|
hFlush stdout
|
||||||
|
askForProjectName
|
||||||
|
where
|
||||||
|
askForProjectName = do
|
||||||
|
puts $ renderTextUrl undefined $(textFile "input/project_name.cg")
|
||||||
|
prompt $ \s -> if validPackageName s then Just s else Nothing
|
||||||
|
|||||||
4
yesod-bin/input/project_name.cg
Normal file
4
yesod-bin/input/project_name.cg
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
What do you want to call your project? We'll use this for the cabal name.
|
||||||
|
|
||||||
|
Project name:
|
||||||
@ -1,6 +1,3 @@
|
|||||||
Welcome to the Yesod scaffolder.
|
Welcome to the Yesod scaffolder.
|
||||||
I'm going to be creating a skeleton Yesod project for you.
|
I'm going to be creating a skeleton Yesod project for you.
|
||||||
|
|
||||||
What do you want to call your project? We'll use this for the cabal name.
|
|
||||||
|
|
||||||
Project name:
|
|
||||||
|
|||||||
@ -41,7 +41,7 @@ data Options = Options
|
|||||||
}
|
}
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
data Command = Init { _initBare :: Bool }
|
data Command = Init { _initBare :: Bool, _initName :: Maybe String }
|
||||||
| HsFiles
|
| HsFiles
|
||||||
| Configure
|
| Configure
|
||||||
| Build { buildExtraArgs :: [String] }
|
| Build { buildExtraArgs :: [String] }
|
||||||
@ -99,7 +99,7 @@ main = do
|
|||||||
] optParser'
|
] optParser'
|
||||||
let cabal = rawSystem' (cabalCommand o)
|
let cabal = rawSystem' (cabalCommand o)
|
||||||
case optCommand o of
|
case optCommand o of
|
||||||
Init bare -> scaffold bare
|
Init bare name -> scaffold bare name
|
||||||
HsFiles -> mkHsFile
|
HsFiles -> mkHsFile
|
||||||
Configure -> cabal ["configure"]
|
Configure -> cabal ["configure"]
|
||||||
Build es -> touch' >> cabal ("build":es)
|
Build es -> touch' >> cabal ("build":es)
|
||||||
@ -136,8 +136,7 @@ optParser :: Parser Options
|
|||||||
optParser = Options
|
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 initOptions
|
||||||
(info (Init <$> (switch (long "bare" <> help "Create files in current folder")))
|
|
||||||
(progDesc "Scaffold a new site"))
|
(progDesc "Scaffold a new site"))
|
||||||
<> command "hsfiles" (info (pure HsFiles)
|
<> command "hsfiles" (info (pure HsFiles)
|
||||||
(progDesc "Create a hsfiles file for the current folder"))
|
(progDesc "Create a hsfiles file for the current folder"))
|
||||||
@ -160,6 +159,12 @@ optParser = Options
|
|||||||
(progDesc "Print the version of Yesod"))
|
(progDesc "Print the version of Yesod"))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
initOptions :: Parser Command
|
||||||
|
initOptions = Init
|
||||||
|
<$> switch (long "bare" <> help "Create files in current folder")
|
||||||
|
<*> optStr (long "name" <> short 'n' <> metavar "APP_NAME"
|
||||||
|
<> help "Set the application name")
|
||||||
|
|
||||||
keterOptions :: Parser Command
|
keterOptions :: Parser Command
|
||||||
keterOptions = Keter
|
keterOptions = Keter
|
||||||
<$> switch ( long "nobuild" <> short 'n' <> help "Skip rebuilding" )
|
<$> switch ( long "nobuild" <> short 'n' <> help "Skip rebuilding" )
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user