aboutsummaryrefslogtreecommitdiffstats
path: root/common/src
diff options
context:
space:
mode:
Diffstat (limited to 'common/src')
-rw-r--r--common/src/Version.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/common/src/Version.hs b/common/src/Version.hs
index cb568e6..6970968 100644
--- a/common/src/Version.hs
+++ b/common/src/Version.hs
@@ -8,16 +8,24 @@ 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
+ toJSON = A.toJSON . versionToString
instance A.FromJSON Version where
parseJSON (A.String (versionFromText -> Just version)) = pure version
@@ -34,3 +42,6 @@ versionFromString _ = Nothing
versionFromText :: T.Text -> Maybe Version
versionFromText = versionFromString . T.unpack
+
+instance IsString Version where
+ fromString = fromMaybe (error "") . versionFromString