summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs39
-rw-r--r--src/SlackBuilder/CommandLine.hs9
2 files changed, 30 insertions, 18 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
diff --git a/src/SlackBuilder/CommandLine.hs b/src/SlackBuilder/CommandLine.hs
index 7cfe747..7da036a 100644
--- a/src/SlackBuilder/CommandLine.hs
+++ b/src/SlackBuilder/CommandLine.hs
@@ -21,7 +21,7 @@ import Options.Applicative
data SlackBuilderCommand
= CategoryCommand Text
- | CloneCommand Text Text Text
+ | CheckCommand
| Up2DateCommand
data PackagistArguments = PackagistArguments
@@ -46,13 +46,10 @@ slackBuilderParser = info slackBuilderCommand fullDesc
slackBuilderCommand :: Parser SlackBuilderCommand
slackBuilderCommand = subparser
$ command "category" (info categoryCommand mempty)
- <> command "clone" (info cloneCommand mempty)
+ <> command "check" (info checkCommand mempty)
<> command "up2date" (info up2DateCommand mempty)
where
categoryCommand = CategoryCommand
<$> argument str (metavar "PKGNAM")
- cloneCommand = CloneCommand
- <$> argument str (metavar "REPO")
- <*> argument str (metavar "TARBALL")
- <*> argument str (metavar "TAG_PREFIX")
+ checkCommand = pure CheckCommand
up2DateCommand = pure Up2DateCommand