summaryrefslogtreecommitdiff
path: root/app/Main.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2023-08-06 14:25:19 +0200
committerEugen Wissner <belka@caraus.de>2023-08-06 14:25:19 +0200
commit69ba04a7314aa5750a5fedbb9533cf775486870f (patch)
tree2d9f88b4020b8e3136494074dceb5e48c9828591 /app/Main.hs
parent028f64d25a93e0430f22240024e255eec12bfb09 (diff)
downloadslackbuilder-69ba04a7314aa5750a5fedbb9533cf775486870f.tar.gz
Move text URL check to the Haskell binary
Diffstat (limited to 'app/Main.hs')
-rw-r--r--app/Main.hs45
1 files changed, 9 insertions, 36 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 75a4396..ac1aae2 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -2,45 +2,18 @@ module Main
( main
) where
-import Data.Aeson.TH (defaultOptions, deriveJSON)
-import Data.HashMap.Strict (HashMap)
-import qualified Data.HashMap.Strict as HashMap
-import Data.Text (Text)
import qualified Data.Text.IO as Text.IO
-import Data.Vector (Vector)
-import qualified Data.Vector as Vector
-import Network.HTTP.Req
- ( runReq
- , defaultHttpConfig
- , req
- , GET(..)
- , https
- , jsonResponse
- , NoReqBody(..)
- , (/:)
- , responseBody
- )
import Data.Maybe (fromMaybe)
-
-newtype PackagistPackage = PackagistPackage
- { version :: Text
- } deriving (Eq, Show)
-
-$(deriveJSON defaultOptions ''PackagistPackage)
-
-newtype PackagistResponse = PackagistResponse
- { packages :: HashMap Text (Vector PackagistPackage)
- } deriving (Eq, Show)
-
-$(deriveJSON defaultOptions ''PackagistResponse)
+import Options.Applicative (execParser)
+import SlackBuilder.CommandLine
+import SlackBuilder.Updater
main :: IO ()
main = do
- packagistResponse <- runReq defaultHttpConfig $
- let uri = https "repo.packagist.org" /: "p2" /: "composer" /: "composer.json"
- in req GET uri NoReqBody jsonResponse mempty
- let packagistPackages = packages $ responseBody packagistResponse
+ programCommand <- execParser slackBuilderParser
+ latestVersion <- case programCommand of
+ PackagistCommand packagistArguments ->
+ latestPackagist packagistArguments
+ TextCommand textArguments -> latestText textArguments
- Text.IO.putStrLn $ fromMaybe ""
- $ HashMap.lookup "composer/composer" packagistPackages
- >>= fmap (version . fst) . Vector.uncons
+ Text.IO.putStrLn $ fromMaybe "" latestVersion