In yesod init, ensure words have atleast one character; fixes #550

This commit is contained in:
Maximilian Tagher 2014-06-06 12:51:00 -07:00
parent d42ba4d024
commit 62877cbba0

View File

@ -15,6 +15,8 @@ import Text.ProjectTemplate (unpackTemplate, receiveFS)
import System.IO import System.IO
import Text.Shakespeare.Text (renderTextUrl, textFile) import Text.Shakespeare.Text (renderTextUrl, textFile)
import Network.HTTP.Conduit (withManager, http, parseUrl, responseBody) import Network.HTTP.Conduit (withManager, http, parseUrl, responseBody)
import Data.List.Split (splitOn)
import Data.Char (isDigit)
prompt :: (String -> Maybe a) -> IO a prompt :: (String -> Maybe a) -> IO a
prompt f = do prompt f = do
@ -68,12 +70,14 @@ validPN c
validPN '-' = True validPN '-' = True
validPN _ = False validPN _ = False
scaffold :: Bool -- ^ bare directory instead of a new subdirectory? scaffold :: Bool -- ^ bare directory instead of a new subdirectory?
-> IO () -> IO ()
scaffold isBare = do scaffold isBare = do
puts $ renderTextUrl undefined $(textFile "input/welcome.cg") puts $ renderTextUrl undefined $(textFile "input/welcome.cg")
project <- prompt $ \s -> project <- prompt $ \s ->
if all validPN s && not (null s) && s /= "test" if all validPN s && not (null s) && s /= "test" && (not $ any (all isDigit) (splitOn "-" s))
then Just s then Just s
else Nothing else Nothing
let dir = project let dir = project