- handler :: IOException -> IO (Maybe Text)
- handler = const $ pure Nothing
-
-getEntryTemplate :: Text -> IO (Maybe Template)
-getEntryTemplate t = (pure $ fmap template) <*> (safeReadFile =<< ((++ "/entry-" ++ (unpack t) ++ ".txt")) <$> getGlobalProjectDir)
-
-resolveProjectConfig :: IO (Either Text ProjectConfig)
-resolveProjectConfig = do
- l <- getLocalProjectConfig
- g <- getGlobalProjectConfig
-
- 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")
-
-initGlobalIfNeeded :: IO () -> IO ()
-initGlobalIfNeeded next = getGlobalProjectConfigPath >>= doesFileExist >>= bool globalInit (return ()) >> next
-
-globalInit :: IO ()
-globalInit = do
- home <- getHomeDirectory
- putStrLn "\nWelcome to xyz! Looks like this is your first time here. Let's configure a few things...\n"
- editor <- editorPrompt
- vcs <- vcsPrompt
- let pushCmdAndRemote = case vcs of
- Just (True, x) -> [("pushCommand", "git add . && git commit -m \"$title\""), ("remote", x)]
- Nothing -> []
-
- getGlobalProjectConfigPath >>= flip writeFile (toStrict . encodeToLazyText $ GlobalConfig editor (lookup "pushCommand" pushCmdAndRemote) (lookup "remote" pushCmdAndRemote))
- putStrLn "\nThanks! Now let's continue with initialising your project...\n"
-
-init :: IO ()
-init = do
- home <- getHomeDirectory
- themes <- allFilesIn $ home ++ "/.xyz/themes"
- projectSpec <- (\[x,y,z] -> (x, y, z, Nothing, Nothing, Nothing)) <$> fmap snd <$> initPrompt (map pack themes)
- let localConfig = uncurryN LocalConfig projectSpec
- writeFile "xyz.json" (toStrict . encodeToLazyText $ localConfig)
- config <- resolveProjectConfig
-
- case config of
- Right projectConfig -> do
- createDirectory "entries"
-
- case (commitCommand (projectConfig :: ProjectConfig), gitRemote (projectConfig :: ProjectConfig)) of
+ globalInit = do
+ lift $ putStrLn "\nWelcome to xyz! Looks like this is your first time here. Let's configure a few things...\n"
+ editor <- lift editorPrompt
+ vcs <- lift vcsPrompt
+ let pushCmdAndRemote = case vcs of
+ Just (True, x) -> [("pushCommand", "git add . && git commit -m \"$title\""), ("remote", x)]
+ Nothing -> []
+
+ lift $ getGlobalProjectConfigPath >>= flip writeFile (toStrict . encodeToLazyText $ GlobalConfig editor (lookup "pushCommand" pushCmdAndRemote) (lookup "remote" pushCmdAndRemote))
+ lift $ putStrLn "\nThanks! Now let's continue with initialising your project...\n"
+
+ localInit = do
+ home <- lift $ getHomeDirectory
+ themes <- lift $ allFilesIn $ home ++ "/.xyz/themes"
+ projectSpec <- lift $ (\[x,y,z] -> (x, y, z, Nothing, Nothing, Nothing)) <$> fmap snd <$> initPrompt (map pack themes)
+ let localConfig = uncurryN LocalConfig projectSpec
+ lift $ writeFile "xyz.json" (toStrict . encodeToLazyText $ localConfig)
+ config <- resolveProjectConfig
+ lift $ createDirectory "entries"
+
+ case (commitCommand (config :: ProjectConfig), gitRemote (config :: ProjectConfig)) of