fix: flag when new project name is a reserved word.

fixes #354.
This commit is contained in:
Phil de Joux 2021-11-10 10:47:37 -05:00 committed by Martin Šošić
parent b6f024cb27
commit 41077ea2bd

View File

@ -1,3 +1,5 @@
{-# LANGUAGE ViewPatterns #-}
module Wasp.Cli.Command.CreateNewProject
( createNewProject,
)
@ -6,6 +8,7 @@ where
import Control.Monad.Except (throwError)
import Control.Monad.IO.Class (liftIO)
import Data.Char (isLetter)
import Data.List (intercalate)
import StrongPath (Abs, Dir, File', Path', Rel, reldir, relfile, (</>))
import qualified StrongPath as SP
import System.Directory (createDirectory, getCurrentDirectory)
@ -17,20 +20,17 @@ import Wasp.Cli.Command (Command, CommandError (..))
import qualified Wasp.Cli.Command.Common as Command.Common
import qualified Wasp.Cli.Common as Common
import qualified Wasp.Data
import Wasp.Lexer (reservedNames)
import qualified Wasp.Util.Terminal as Term
newtype ProjectName = ProjectName {_projectName :: String}
createNewProject :: String -> Command ()
createNewProject projectNameStr = do
case parseProjectName projectNameStr of
Left err -> throwError $ CommandError err
Right projectName -> createNewProject' projectName
where
parseProjectName name =
if all isLetter name
then Right $ ProjectName name
else Left "Please use only letters for project name."
createNewProject (all isLetter -> False) =
throwError $ CommandError "Please use only letters for a new project's name."
createNewProject ((`elem` reservedNames) -> True) =
throwError . CommandError $ "Please pick a project name not one of these reserved words:\n\t" ++ intercalate "\n\t" reservedNames
createNewProject name = createNewProject' (ProjectName name)
createNewProject' :: ProjectName -> Command ()
createNewProject' (ProjectName projectName) = do