slackbuilder/app/Main.hs

37 lines
1.3 KiB
Haskell

module Main
( main
) where
import qualified Data.Text.IO as Text.IO
import Data.Maybe (fromMaybe)
import Options.Applicative (execParser)
import SlackBuilder.CommandLine
import SlackBuilder.Config
import SlackBuilder.Updater
import qualified Toml
import qualified Data.Text as Text
main :: IO ()
main = do
programCommand <- execParser slackBuilderParser
settings <- Toml.decodeFile settingsCodec "config/config.toml"
latestVersion <- case programCommand of
PackagistCommand packagistArguments ->
latestPackagist packagistArguments
TextCommand textArguments -> latestText textArguments
GhCommand ghArguments@GhArguments{ transform } ->
latestGitHub settings ghArguments $ chooseTransformFunction transform
Text.IO.putStrLn $ fromMaybe "" latestVersion
where
chooseTransformFunction (Just "php") = phpTransform
chooseTransformFunction (Just "rdiff-backup") = Text.stripPrefix "v"
chooseTransformFunction _ = stripPrefix "v"
stripPrefix prefix string = Just
$ fromMaybe string
$ Text.stripPrefix prefix string
phpTransform version
| (majorPrefix, patchVersion) <- Text.breakOnEnd "." version
, majorPrefix == "php-8.2." = Just $ Text.drop (Text.length "php-") version
| otherwise = Nothing