Replace clone command with the check command
All checks were successful
Build / audit (push) Successful in 15m55s
Build / test (push) Successful in 16m57s

This commit is contained in:
Eugen Wissner 2023-12-09 21:33:34 +01:00
parent ef0a5b5958
commit e9504fb8e5
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
3 changed files with 32 additions and 18 deletions

View File

@ -96,3 +96,5 @@ test-suite slackbuilder-test
slackbuilder
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
build-tool-depends:
hspec-discover:hspec-discover

View File

@ -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

View File

@ -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