Merge pull request #751 from MaxGabriel/validateName
Validate cabal package name not having numeric-only words
This commit is contained in:
commit
d9faced6b1
@ -15,6 +15,9 @@ 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.Maybe (isJust)
|
||||||
|
import Distribution.Text (simpleParse)
|
||||||
|
import Distribution.Package (PackageName)
|
||||||
|
|
||||||
prompt :: (String -> Maybe a) -> IO a
|
prompt :: (String -> Maybe a) -> IO a
|
||||||
prompt f = do
|
prompt f = do
|
||||||
@ -59,21 +62,15 @@ backendBS Mysql = $(embedFile "hsfiles/mysql.hsfiles")
|
|||||||
backendBS MongoDB = $(embedFile "hsfiles/mongo.hsfiles")
|
backendBS MongoDB = $(embedFile "hsfiles/mongo.hsfiles")
|
||||||
backendBS Simple = $(embedFile "hsfiles/simple.hsfiles")
|
backendBS Simple = $(embedFile "hsfiles/simple.hsfiles")
|
||||||
|
|
||||||
-- | Is the character valid for a project name?
|
validPackageName :: String -> Bool
|
||||||
validPN :: Char -> Bool
|
validPackageName s = isJust (simpleParse s :: Maybe PackageName)
|
||||||
validPN c
|
|
||||||
| 'A' <= c && c <= 'Z' = True
|
|
||||||
| 'a' <= c && c <= 'z' = True
|
|
||||||
| '0' <= c && c <= '9' = True
|
|
||||||
validPN '-' = True
|
|
||||||
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 validPackageName s && s /= "test"
|
||||||
then Just s
|
then Just s
|
||||||
else Nothing
|
else Nothing
|
||||||
let dir = project
|
let dir = project
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user