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