module Nbparts.Types.Manifest
( currentNbpartsVersion,
Manifest (..),
Format (..),
defManifest,
formatExtension,
)
where
import Data.Aeson (Options (constructorTagModifier))
import Data.Aeson qualified as Aeson
import Data.Text qualified as Text
import Data.Version (Version)
import GHC.Generics (Generic)
import Paths_nbparts qualified
currentNbpartsVersion :: Version
currentNbpartsVersion :: Version
currentNbpartsVersion = Version
Paths_nbparts.version
data Manifest = Manifest
{ Manifest -> Version
nbpartsVersion :: Version,
Manifest -> Format
sourcesFormat :: Format,
Manifest -> Format
metadataFormat :: Format,
Manifest -> Format
outputsFormat :: Format
}
deriving ((forall x. Manifest -> Rep Manifest x)
-> (forall x. Rep Manifest x -> Manifest) -> Generic Manifest
forall x. Rep Manifest x -> Manifest
forall x. Manifest -> Rep Manifest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Manifest -> Rep Manifest x
from :: forall x. Manifest -> Rep Manifest x
$cto :: forall x. Rep Manifest x -> Manifest
to :: forall x. Rep Manifest x -> Manifest
Generic, Int -> Manifest -> ShowS
[Manifest] -> ShowS
Manifest -> String
(Int -> Manifest -> ShowS)
-> (Manifest -> String) -> ([Manifest] -> ShowS) -> Show Manifest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Manifest -> ShowS
showsPrec :: Int -> Manifest -> ShowS
$cshow :: Manifest -> String
show :: Manifest -> String
$cshowList :: [Manifest] -> ShowS
showList :: [Manifest] -> ShowS
Show, Manifest -> Manifest -> Bool
(Manifest -> Manifest -> Bool)
-> (Manifest -> Manifest -> Bool) -> Eq Manifest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Manifest -> Manifest -> Bool
== :: Manifest -> Manifest -> Bool
$c/= :: Manifest -> Manifest -> Bool
/= :: Manifest -> Manifest -> Bool
Eq, Eq Manifest
Eq Manifest =>
(Manifest -> Manifest -> Ordering)
-> (Manifest -> Manifest -> Bool)
-> (Manifest -> Manifest -> Bool)
-> (Manifest -> Manifest -> Bool)
-> (Manifest -> Manifest -> Bool)
-> (Manifest -> Manifest -> Manifest)
-> (Manifest -> Manifest -> Manifest)
-> Ord Manifest
Manifest -> Manifest -> Bool
Manifest -> Manifest -> Ordering
Manifest -> Manifest -> Manifest
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Manifest -> Manifest -> Ordering
compare :: Manifest -> Manifest -> Ordering
$c< :: Manifest -> Manifest -> Bool
< :: Manifest -> Manifest -> Bool
$c<= :: Manifest -> Manifest -> Bool
<= :: Manifest -> Manifest -> Bool
$c> :: Manifest -> Manifest -> Bool
> :: Manifest -> Manifest -> Bool
$c>= :: Manifest -> Manifest -> Bool
>= :: Manifest -> Manifest -> Bool
$cmax :: Manifest -> Manifest -> Manifest
max :: Manifest -> Manifest -> Manifest
$cmin :: Manifest -> Manifest -> Manifest
min :: Manifest -> Manifest -> Manifest
Ord)
defManifest :: Manifest
defManifest :: Manifest
defManifest =
Manifest
{ nbpartsVersion :: Version
nbpartsVersion = Version
currentNbpartsVersion,
sourcesFormat :: Format
sourcesFormat = Format
FormatYaml,
metadataFormat :: Format
metadataFormat = Format
FormatYaml,
outputsFormat :: Format
outputsFormat = Format
FormatYaml
}
data Format
= FormatYaml
| FormatJson
| FormatMarkdown
deriving ((forall x. Format -> Rep Format x)
-> (forall x. Rep Format x -> Format) -> Generic Format
forall x. Rep Format x -> Format
forall x. Format -> Rep Format x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Format -> Rep Format x
from :: forall x. Format -> Rep Format x
$cto :: forall x. Rep Format x -> Format
to :: forall x. Rep Format x -> Format
Generic, Int -> Format -> ShowS
[Format] -> ShowS
Format -> String
(Int -> Format -> ShowS)
-> (Format -> String) -> ([Format] -> ShowS) -> Show Format
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Format -> ShowS
showsPrec :: Int -> Format -> ShowS
$cshow :: Format -> String
show :: Format -> String
$cshowList :: [Format] -> ShowS
showList :: [Format] -> ShowS
Show, Format -> Format -> Bool
(Format -> Format -> Bool)
-> (Format -> Format -> Bool) -> Eq Format
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Format -> Format -> Bool
== :: Format -> Format -> Bool
$c/= :: Format -> Format -> Bool
/= :: Format -> Format -> Bool
Eq, Eq Format
Eq Format =>
(Format -> Format -> Ordering)
-> (Format -> Format -> Bool)
-> (Format -> Format -> Bool)
-> (Format -> Format -> Bool)
-> (Format -> Format -> Bool)
-> (Format -> Format -> Format)
-> (Format -> Format -> Format)
-> Ord Format
Format -> Format -> Bool
Format -> Format -> Ordering
Format -> Format -> Format
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Format -> Format -> Ordering
compare :: Format -> Format -> Ordering
$c< :: Format -> Format -> Bool
< :: Format -> Format -> Bool
$c<= :: Format -> Format -> Bool
<= :: Format -> Format -> Bool
$c> :: Format -> Format -> Bool
> :: Format -> Format -> Bool
$c>= :: Format -> Format -> Bool
>= :: Format -> Format -> Bool
$cmax :: Format -> Format -> Format
max :: Format -> Format -> Format
$cmin :: Format -> Format -> Format
min :: Format -> Format -> Format
Ord)
formatExtension :: Format -> String
formatExtension :: Format -> String
formatExtension Format
FormatYaml = String
"yaml"
formatExtension Format
FormatJson = String
"json"
formatExtension Format
FormatMarkdown = String
"md"
instance Aeson.ToJSON Manifest
instance Aeson.FromJSON Manifest
instance Aeson.ToJSON Format where
toJSON :: Format -> Value
toJSON = Options -> Format -> Value
forall a.
(Generic a, GToJSON' Value Zero (Rep a)) =>
Options -> a -> Value
Aeson.genericToJSON Options
jsonOptions
instance Aeson.FromJSON Format where
parseJSON :: Value -> Parser Format
parseJSON = String -> (Text -> Parser Format) -> Value -> Parser Format
forall a. String -> (Text -> Parser a) -> Value -> Parser a
Aeson.withText String
"Format" ((Text -> Parser Format) -> Value -> Parser Format)
-> (Text -> Parser Format) -> Value -> Parser Format
forall a b. (a -> b) -> a -> b
$ \case
Text
"yaml" -> Format -> Parser Format
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Format
FormatYaml
Text
"json" -> Format -> Parser Format
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Format
FormatJson
Text
"markdown" -> Format -> Parser Format
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Format
FormatMarkdown
Text
"FormatYaml" -> Format -> Parser Format
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Format
FormatYaml
Text
"FormatJson" -> Format -> Parser Format
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Format
FormatJson
Text
"FormatMarkdown" -> Format -> Parser Format
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Format
FormatMarkdown
Text
other -> String -> Parser Format
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Format) -> String -> Parser Format
forall a b. (a -> b) -> a -> b
$ String
"Unknown format: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
Text.unpack Text
other
jsonOptions :: Aeson.Options
jsonOptions :: Options
jsonOptions =
Options
Aeson.defaultOptions
{ constructorTagModifier = \case
String
"FormatYaml" -> String
"yaml"
String
"FormatJson" -> String
"json"
String
"FormatMarkdown" -> String
"markdown"
String
other -> String
other
}