49 lines
1.8 KiB
Haskell
49 lines
1.8 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.Trans
|
|
import SlackBuilder.Updater
|
|
import qualified Toml
|
|
import qualified Data.Text as Text
|
|
import Control.Monad.Trans.Reader (ReaderT(..))
|
|
import SlackBuilder.Download
|
|
|
|
main :: IO ()
|
|
main = do
|
|
programCommand <- execParser slackBuilderParser
|
|
settings <- Toml.decodeFile settingsCodec "config/config.toml"
|
|
latestVersion <- flip runReaderT settings
|
|
$ runSlackBuilderT
|
|
$ executeCommand programCommand
|
|
|
|
Text.IO.putStrLn $ fromMaybe "" latestVersion
|
|
where
|
|
executeCommand = \case
|
|
PackagistCommand packagistArguments ->
|
|
latestPackagist packagistArguments
|
|
TextCommand textArguments -> latestText textArguments
|
|
GhCommand ghArguments@GhArguments{ transform }
|
|
-> latestGitHub ghArguments $ chooseTransformFunction transform
|
|
SlackBuildCommand packagePath version ->
|
|
updateSlackBuildVersion packagePath version >> pure Nothing
|
|
CommitCommand packagePath version ->
|
|
commit packagePath version >> pure Nothing
|
|
ExistsCommand urlPath -> pure . Text.pack . show
|
|
<$> remoteFileExists urlPath
|
|
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
|