getLocalProjectConfig :: IO (Maybe LocalConfig)
getLocalProjectConfig = doesFileExist "xyz.json" >>= bool (return Nothing) (BL.readFile "xyz.json" >>= return . decode)
-resolveProjectConfig :: IO (Maybe ProjectConfig)
+resolveProjectConfig :: IO (Either Text ProjectConfig)
resolveProjectConfig = do
l <- getLocalProjectConfig
g <- getGlobalProjectConfig
- case (l, g) of
- (Just l, Just g) -> return . Just $ getProjectConfig g l
- (Just _, Nothing) -> fail "Busted global config"
- (Nothing, Just _) -> fail "Busted local config"
- _ -> fail "All configs are busted"
+ return $ case (l, g) of
+ (Just l, Just g) -> Right $ getProjectConfig g l
+ (Just _, Nothing) -> Left "Busted global config"
+ (Nothing, Just _) -> Left "Busted local config"
+ _ -> Left "All configs are busted"
continueIfInvalidProject :: IO () -> IO ()
continueIfInvalidProject next = doesFileExist "xyz.json" >>= bool next (putStrLn "Project already initialised")
config <- resolveProjectConfig
case config of
- Just projectConfig -> do
+ Right projectConfig -> do
createDirectory "entries"
case (commitCommand (projectConfig :: ProjectConfig), gitRemote (projectConfig :: ProjectConfig)) of
(_, _) -> return()
putStrLn "\nInitialised empty project"
- Nothing -> do
- putStrLn "\nSomething went real wrong"
+ Left error -> do
+ putStrLn $ "\n" +++ error
build :: ProjectConfig -> IO ()
build config = allFilesIn "entries" >>= (writeOutProject config) >> putStrLn "Build successful"
]
]
-gogogo :: (ProjectConfig -> IO ()) -> Maybe ProjectConfig -> IO ()
+gogogo :: (ProjectConfig -> IO ()) -> Either Text ProjectConfig -> IO ()
gogogo next projectConfig = case projectConfig of
- Just config -> next config
- _ -> fail "This does not appear to be a vailid project directory" -- Never executes, the cases in resolveProjectConfig will fail first.
+ Right config -> next config
+ Left error -> putStrLn $ "This does not appear to be a vailid project directory: " +++ error -- Never executes, the cases in resolveProjectConfig will fail first.
parse ["init"] = initGlobalIfNeeded (continueIfInvalidProject init) >> exitSuccess
parse ["build"] = resolveProjectConfig >>= (gogogo build) >> exitSuccess