summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 535b655..0b67b5d 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -256,12 +256,21 @@ up2Date = for_ autoUpdatable go
go package = getAndLogLatest package
>>= mapM_ (updatePackageIfRequired package)
>> liftIO (putStrLn "")
- getAndLogLatest Package{ latest = Package.Updater{ detectLatest }, name }
- = liftIO (putStrLn $ Text.unpack name <> ": Retreiving the latest version.")
- >> detectLatest
-updatePackageIfRequired :: Package -> Text -> SlackBuilderT ()
-updatePackageIfRequired package@Package{..} version = do
+check :: SlackBuilderT ()
+check = for_ autoUpdatable go
+ where
+ go package = getAndLogLatest package
+ >>= mapM_ (checkUpdateAvailability package)
+ >> liftIO (putStrLn "")
+
+getAndLogLatest :: Package -> SlackBuilderT (Maybe Text)
+getAndLogLatest Package{ latest = Package.Updater{ detectLatest }, name }
+ = liftIO (putStrLn $ Text.unpack name <> ": Retreiving the latest version.")
+ >> detectLatest
+
+checkUpdateAvailability :: Package -> Text -> SlackBuilderT (Maybe PackageInfo)
+checkUpdateAvailability Package{..} version = do
let packagePath = Text.unpack category </> Text.unpack name </> (Text.unpack name <.> "info")
repository' <- SlackBuilderT $ asks repository
infoContents <- liftIO $ ByteString.readFile $ repository' </> packagePath
@@ -274,7 +283,8 @@ updatePackageIfRequired package@Package{..} version = do
Text.IO.putStrLn
$ name <> " is up to date (Version " <> version <> ")."
setSGR [Reset]
- | otherwise -> do
+ pure Nothing
+ | otherwise ->
liftIO $ do
setSGR [SetColor Foreground Dull Yellow]
Text.IO.putStrLn
@@ -282,8 +292,14 @@ updatePackageIfRequired package@Package{..} version = do
<> name <> " " <> getField @"version" parsedInfoFile
<> " is available (" <> version <> ")."
setSGR [Reset]
- updatePackage package parsedInfoFile version
- Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle
+ pure $ Just parsedInfoFile
+ Left errorBundle -> liftIO (putStr $ errorBundlePretty errorBundle)
+ >> pure Nothing
+
+updatePackageIfRequired :: Package -> Text -> SlackBuilderT ()
+updatePackageIfRequired package version
+ = checkUpdateAvailability package version
+ >>= mapM_ (updatePackage package version)
updateDownload :: Package -> Package.Updater -> SlackBuilderT (Package.Download, Text)
updateDownload Package{..} Package.Updater{..} = do
@@ -369,8 +385,8 @@ renderAndDownload Package{..} version = do
getVersion packagePath version
-updatePackage :: Package -> PackageInfo -> Text -> SlackBuilderT ()
-updatePackage package@Package{..} info version = do
+updatePackage :: Package -> Text -> PackageInfo -> SlackBuilderT ()
+updatePackage package@Package{..} version info = do
let packagePath = category <> "/" <> name
repository' <- SlackBuilderT $ asks repository
@@ -416,6 +432,5 @@ main = do
categories <- liftIO $ findCategory repository'
liftIO $ print $ splitFileName . makeRelative repository' <$> categories
pure Nothing
- CloneCommand repo tarball tagPrefix -> fmap (Text.pack . show)
- <$> clone repo tarball tagPrefix
+ CheckCommand -> check >> pure Nothing
Up2DateCommand -> up2Date >> pure Nothing