Merge pull request #808 from dunric/master

Add some minimal interaction to add-handler command
This commit is contained in:
Michael Snoyman 2014-08-18 09:16:46 +03:00
commit 827ddf8be5

View File

@ -22,20 +22,28 @@ addHandler = do
[] -> error "No cabal file found" [] -> error "No cabal file found"
_ -> error "Too many cabal files found" _ -> error "Too many cabal files found"
putStr "Name of route (without trailing R): " let routeInput = do
hFlush stdout putStr "Name of route (without trailing R): "
name <- getLine hFlush stdout
case name of name <- getLine
[] -> error "Please provide a name" case name of
c:_ [] -> error "No name entered. Quitting ..."
| isLower c -> error "Name must start with an upper case letter" c:_
| otherwise -> return () | isLower c -> do
putStrLn "Name must start with an upper case letter"
-- Check that the handler file doesn't already exist routeInput
let handlerFile = concat ["Handler/", name, ".hs"] | otherwise -> do
exists <- doesFileExist handlerFile -- Check that the handler file doesn't already exist
when exists $ error $ "File already exists: " ++ show handlerFile let handlerFile = concat ["Handler/", name, ".hs"]
exists <- doesFileExist handlerFile
if exists
then do
putStrLn $ "File already exists: " ++ show handlerFile
putStrLn "Try another name or leave blank to exit"
routeInput
else return (name, handlerFile)
(name, handlerFile) <- routeInput
putStr "Enter route pattern (ex: /entry/#EntryId): " putStr "Enter route pattern (ex: /entry/#EntryId): "
hFlush stdout hFlush stdout
pattern <- getLine pattern <- getLine