Allow looking on the text page for the latest version

This commit is contained in:
2023-10-20 15:53:48 +02:00
parent 4105ffa91f
commit 3a6d17952b
4 changed files with 31 additions and 28 deletions

View File

@ -7,6 +7,7 @@ module SlackBuilder.CommandLine
) where
import Data.Text (Text)
import qualified Data.Text as Text
import Options.Applicative
( Parser
, ParserInfo(..)
@ -29,7 +30,6 @@ data SlackBuilderCommand
| CloneCommand Text Text Text
| DownloadAndDeployCommand Text Text
| Up2DateCommand
deriving (Eq, Show)
data PackagistArguments = PackagistArguments
{ vendor :: Text
@ -42,11 +42,14 @@ data GhArguments = GhArguments
, transform :: Maybe Text
} deriving (Eq, Show)
newtype TextArguments = TextArguments Text
deriving (Eq, Show)
data TextArguments = TextArguments
{ versionPicker :: Text -> Text
, textURL :: Text
}
textArguments :: Parser TextArguments
textArguments = TextArguments <$> argument str (metavar "URL")
textArguments = TextArguments Text.strip
<$> argument str (metavar "URL")
slackBuilderParser :: ParserInfo SlackBuilderCommand
slackBuilderParser = info slackBuilderCommand fullDesc

View File

@ -107,11 +107,11 @@ latestPackagist PackagistArguments{..} = do
>>= fmap (version . fst) . Vector.uncons
latestText :: TextArguments -> SlackBuilderT (Maybe Text)
latestText (TextArguments textArguments) = do
uri <- liftIO $ useHttpsURI <$> mkURI textArguments
latestText TextArguments{..} = do
uri <- liftIO $ useHttpsURI <$> mkURI textURL
packagistResponse <- traverse (runReq defaultHttpConfig . go . fst) uri
pure $ Text.strip . Text.Encoding.decodeASCII . responseBody
pure $ versionPicker . Text.Encoding.decodeUtf8 . responseBody
<$> packagistResponse
where
go uri = req GET uri NoReqBody bsResponse mempty