diff options
Diffstat (limited to 'app/SlackBuilder/Package.hs')
| -rw-r--r-- | app/SlackBuilder/Package.hs | 14 |
1 files changed, 12 insertions, 2 deletions
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 |
