Replace clone command with the check command
This commit is contained in:
parent
ef0a5b5958
commit
e9504fb8e5
@ -96,3 +96,5 @@ test-suite slackbuilder-test
|
|||||||
slackbuilder
|
slackbuilder
|
||||||
|
|
||||||
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
|
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall
|
||||||
|
build-tool-depends:
|
||||||
|
hspec-discover:hspec-discover
|
||||||
|
33
src/Main.hs
33
src/Main.hs
@ -256,12 +256,21 @@ up2Date = for_ autoUpdatable go
|
|||||||
go package = getAndLogLatest package
|
go package = getAndLogLatest package
|
||||||
>>= mapM_ (updatePackageIfRequired package)
|
>>= mapM_ (updatePackageIfRequired package)
|
||||||
>> liftIO (putStrLn "")
|
>> liftIO (putStrLn "")
|
||||||
|
|
||||||
|
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 }
|
getAndLogLatest Package{ latest = Package.Updater{ detectLatest }, name }
|
||||||
= liftIO (putStrLn $ Text.unpack name <> ": Retreiving the latest version.")
|
= liftIO (putStrLn $ Text.unpack name <> ": Retreiving the latest version.")
|
||||||
>> detectLatest
|
>> detectLatest
|
||||||
|
|
||||||
updatePackageIfRequired :: Package -> Text -> SlackBuilderT ()
|
checkUpdateAvailability :: Package -> Text -> SlackBuilderT (Maybe PackageInfo)
|
||||||
updatePackageIfRequired package@Package{..} version = do
|
checkUpdateAvailability Package{..} version = do
|
||||||
let packagePath = Text.unpack category </> Text.unpack name </> (Text.unpack name <.> "info")
|
let packagePath = Text.unpack category </> Text.unpack name </> (Text.unpack name <.> "info")
|
||||||
repository' <- SlackBuilderT $ asks repository
|
repository' <- SlackBuilderT $ asks repository
|
||||||
infoContents <- liftIO $ ByteString.readFile $ repository' </> packagePath
|
infoContents <- liftIO $ ByteString.readFile $ repository' </> packagePath
|
||||||
@ -274,7 +283,8 @@ updatePackageIfRequired package@Package{..} version = do
|
|||||||
Text.IO.putStrLn
|
Text.IO.putStrLn
|
||||||
$ name <> " is up to date (Version " <> version <> ")."
|
$ name <> " is up to date (Version " <> version <> ")."
|
||||||
setSGR [Reset]
|
setSGR [Reset]
|
||||||
| otherwise -> do
|
pure Nothing
|
||||||
|
| otherwise ->
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
setSGR [SetColor Foreground Dull Yellow]
|
setSGR [SetColor Foreground Dull Yellow]
|
||||||
Text.IO.putStrLn
|
Text.IO.putStrLn
|
||||||
@ -282,8 +292,14 @@ updatePackageIfRequired package@Package{..} version = do
|
|||||||
<> name <> " " <> getField @"version" parsedInfoFile
|
<> name <> " " <> getField @"version" parsedInfoFile
|
||||||
<> " is available (" <> version <> ")."
|
<> " is available (" <> version <> ")."
|
||||||
setSGR [Reset]
|
setSGR [Reset]
|
||||||
updatePackage package parsedInfoFile version
|
pure $ Just parsedInfoFile
|
||||||
Left errorBundle -> liftIO $ putStr $ errorBundlePretty errorBundle
|
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 -> SlackBuilderT (Package.Download, Text)
|
||||||
updateDownload Package{..} Package.Updater{..} = do
|
updateDownload Package{..} Package.Updater{..} = do
|
||||||
@ -369,8 +385,8 @@ renderAndDownload Package{..} version = do
|
|||||||
|
|
||||||
getVersion packagePath version
|
getVersion packagePath version
|
||||||
|
|
||||||
updatePackage :: Package -> PackageInfo -> Text -> SlackBuilderT ()
|
updatePackage :: Package -> Text -> PackageInfo -> SlackBuilderT ()
|
||||||
updatePackage package@Package{..} info version = do
|
updatePackage package@Package{..} version info = do
|
||||||
let packagePath = category <> "/" <> name
|
let packagePath = category <> "/" <> name
|
||||||
|
|
||||||
repository' <- SlackBuilderT $ asks repository
|
repository' <- SlackBuilderT $ asks repository
|
||||||
@ -416,6 +432,5 @@ main = do
|
|||||||
categories <- liftIO $ findCategory repository'
|
categories <- liftIO $ findCategory repository'
|
||||||
liftIO $ print $ splitFileName . makeRelative repository' <$> categories
|
liftIO $ print $ splitFileName . makeRelative repository' <$> categories
|
||||||
pure Nothing
|
pure Nothing
|
||||||
CloneCommand repo tarball tagPrefix -> fmap (Text.pack . show)
|
CheckCommand -> check >> pure Nothing
|
||||||
<$> clone repo tarball tagPrefix
|
|
||||||
Up2DateCommand -> up2Date >> pure Nothing
|
Up2DateCommand -> up2Date >> pure Nothing
|
||||||
|
@ -21,7 +21,7 @@ import Options.Applicative
|
|||||||
|
|
||||||
data SlackBuilderCommand
|
data SlackBuilderCommand
|
||||||
= CategoryCommand Text
|
= CategoryCommand Text
|
||||||
| CloneCommand Text Text Text
|
| CheckCommand
|
||||||
| Up2DateCommand
|
| Up2DateCommand
|
||||||
|
|
||||||
data PackagistArguments = PackagistArguments
|
data PackagistArguments = PackagistArguments
|
||||||
@ -46,13 +46,10 @@ slackBuilderParser = info slackBuilderCommand fullDesc
|
|||||||
slackBuilderCommand :: Parser SlackBuilderCommand
|
slackBuilderCommand :: Parser SlackBuilderCommand
|
||||||
slackBuilderCommand = subparser
|
slackBuilderCommand = subparser
|
||||||
$ command "category" (info categoryCommand mempty)
|
$ command "category" (info categoryCommand mempty)
|
||||||
<> command "clone" (info cloneCommand mempty)
|
<> command "check" (info checkCommand mempty)
|
||||||
<> command "up2date" (info up2DateCommand mempty)
|
<> command "up2date" (info up2DateCommand mempty)
|
||||||
where
|
where
|
||||||
categoryCommand = CategoryCommand
|
categoryCommand = CategoryCommand
|
||||||
<$> argument str (metavar "PKGNAM")
|
<$> argument str (metavar "PKGNAM")
|
||||||
cloneCommand = CloneCommand
|
checkCommand = pure CheckCommand
|
||||||
<$> argument str (metavar "REPO")
|
|
||||||
<*> argument str (metavar "TARBALL")
|
|
||||||
<*> argument str (metavar "TAG_PREFIX")
|
|
||||||
up2DateCommand = pure Up2DateCommand
|
up2DateCommand = pure Up2DateCommand
|
||||||
|
Loading…
Reference in New Issue
Block a user