diff options
author | 2025-02-20 12:29:35 +0100 | |
---|---|---|
committer | 2025-02-20 18:36:23 +0100 | |
commit | caf72faccc04e647c27e1b5eef85c515949d8210 (patch) | |
tree | ec32dda7b87c12712307d2d101368fed5888d4b9 /common/src | |
parent | 3c64b52017e7c16da0d017c033c77eee5d7a4340 (diff) |
consolidate `backend, cli, common` -> `acms`
Diffstat (limited to 'common/src')
-rw-r--r-- | common/src/Collection.hs | 30 | ||||
-rw-r--r-- | common/src/Version.hs | 47 |
2 files changed, 0 insertions, 77 deletions
diff --git a/common/src/Collection.hs b/common/src/Collection.hs deleted file mode 100644 index 418278d..0000000 --- a/common/src/Collection.hs +++ /dev/null @@ -1,30 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE ViewPatterns #-} - -module Collection where - -import Miso.String (MisoString, toMisoString) -import Text.ParserCombinators.ReadP qualified as R -import Text.ParserCombinators.ReadPrec qualified as R -import Text.Read (Read (..)) - -newtype Collection = Collection {name :: MisoString} - deriving (Read, Eq, Show) - -data CollectionItem = CollectionItem - { collection :: Collection, - itemFileName :: FilePath - } - deriving (Eq) - -instance Read CollectionItem where - readPrec = R.lift $ do - (Collection . toMisoString -> collection) <- R.munch (/= '/') - _ <- R.string "/" - itemFileName <- R.munch (const True) - pure CollectionItem {..} - -instance Show CollectionItem where - show (CollectionItem {collection = Collection cn, itemFileName}) = - show (cn <> "/" <> toMisoString itemFileName) diff --git a/common/src/Version.hs b/common/src/Version.hs deleted file mode 100644 index 6970968..0000000 --- a/common/src/Version.hs +++ /dev/null @@ -1,47 +0,0 @@ -module Version - ( Version (..), - versionToString, - versionFromText, - versionFromString, - ) -where - -import Data.Aeson qualified as A -import Data.Aeson.Types qualified as A -import Data.Function (on) -import Data.List -import Data.List.Split -import Data.Maybe (fromMaybe) -import Data.String (IsString (..)) -import Data.Text qualified as T - -data Version = Version Int Int Int - deriving (Show, Eq) - -instance Ord Version where - compare = compare `on` toTriple - -toTriple :: Version -> (Int, Int, Int) -toTriple (Version major minor patch) = (major, minor, patch) - -instance A.ToJSON Version where - toJSON = A.toJSON . versionToString - -instance A.FromJSON Version where - parseJSON (A.String (versionFromText -> Just version)) = pure version - parseJSON v = A.typeMismatch "version" v - -versionToString :: Version -> String -versionToString (Version major minor patch) = - intercalate "." (map show [major, minor, patch]) - -versionFromString :: String -> Maybe Version -versionFromString (map read . splitOn "." -> [major, minor, patch]) = - Just (Version major minor patch) -versionFromString _ = Nothing - -versionFromText :: T.Text -> Maybe Version -versionFromText = versionFromString . T.unpack - -instance IsString Version where - fromString = fromMaybe (error "") . versionFromString |