From 77c9a2ab54b697f37e21b76c1fd82fc42dc4792e Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 3 Sep 2023 10:26:43 +0200 Subject: Add a test module --- app/SlackBuilder/CommandLine.hs | 3 +++ app/SlackBuilder/Download.hs | 1 + app/SlackBuilder/Package.hs | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'app/SlackBuilder') diff --git a/app/SlackBuilder/CommandLine.hs b/app/SlackBuilder/CommandLine.hs index 23bf840..48881e2 100644 --- a/app/SlackBuilder/CommandLine.hs +++ b/app/SlackBuilder/CommandLine.hs @@ -30,6 +30,7 @@ data SlackBuilderCommand | DownloadCommand Text String | CloneCommand Text Text Text | DownloadAndDeployCommand Text Text + | Up2DateCommand deriving (Eq, Show) data PackagistArguments = PackagistArguments @@ -75,6 +76,7 @@ slackBuilderCommand = subparser <> command "download" (info downloadCommand mempty) <> command "clone" (info cloneCommand mempty) <> command "deploy" (info deployCommand mempty) + <> command "up2date" (info up2DateCommand mempty) where slackBuildCommand = SlackBuildCommand <$> argument str (metavar "PATH") @@ -98,3 +100,4 @@ slackBuilderCommand = subparser deployCommand = DownloadAndDeployCommand <$> argument str (metavar "URI") <*> argument str (metavar "TARBALL") + up2DateCommand = pure Up2DateCommand diff --git a/app/SlackBuilder/Download.hs b/app/SlackBuilder/Download.hs index 2201c25..5d4cb8d 100644 --- a/app/SlackBuilder/Download.hs +++ b/app/SlackBuilder/Download.hs @@ -7,6 +7,7 @@ module SlackBuilder.Download , hostedSources , remoteFileExists , updateSlackBuildVersion + , uploadCommand ) where import Data.ByteString (ByteString) diff --git a/app/SlackBuilder/Package.hs b/app/SlackBuilder/Package.hs index cc07cc5..cc3ea42 100644 --- a/app/SlackBuilder/Package.hs +++ b/app/SlackBuilder/Package.hs @@ -1,13 +1,15 @@ module SlackBuilder.Package ( DownloadPlaceholder(..) , Download(..) + , DownloadTemplate(..) , PackageInfo(..) , Maintainer(..) , Updater(..) , infoTemplate + , renderDownloadWithVersion ) where -import Data.List.NonEmpty (NonEmpty) +import Data.List.NonEmpty (NonEmpty(..)) import Data.Text (Text) import qualified Data.Text as Text import Text.URI (URI(..)) @@ -17,6 +19,7 @@ import GHC.Records (HasField(..)) import System.FilePath (takeBaseName) import Data.List (partition) import SlackBuilder.Trans +import Control.Monad.Catch (MonadThrow) -- | Download URI with the MD5 checksum of the target. data Download = Download @@ -60,8 +63,15 @@ instance Show DownloadTemplate where show (DownloadTemplate components) = concatMap show components +renderDownloadWithVersion :: MonadThrow m => DownloadTemplate -> Text -> m URI +renderDownloadWithVersion (DownloadTemplate components) version = + URI.mkURI $ foldr f "" components + where + f (StaticPlaceholder staticPlaceholder) accumulator = accumulator <> staticPlaceholder + f VersionPlaceholder accumulator = accumulator <> version + -- | Function used to get the latest version of a source. -newtype Updater = Updater (SlackBuilderT (Maybe Text)) +data Updater = Updater (SlackBuilderT (Maybe Text)) DownloadTemplate packageName :: PackageInfo -> Text packageName PackageInfo{ path } = Text.pack $ takeBaseName path -- cgit v1.2.3