From 41077ea2bd907a58dc01c67df2ac71d8ee3c0894 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Wed, 10 Nov 2021 10:47:37 -0500 Subject: [PATCH] fix: flag when new project name is a reserved word. fixes #354. --- waspc/cli/Wasp/Cli/Command/CreateNewProject.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/waspc/cli/Wasp/Cli/Command/CreateNewProject.hs b/waspc/cli/Wasp/Cli/Command/CreateNewProject.hs index 9cde72da8..bd1901f22 100644 --- a/waspc/cli/Wasp/Cli/Command/CreateNewProject.hs +++ b/waspc/cli/Wasp/Cli/Command/CreateNewProject.hs @@ -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