module Poseidon.CLI.Chronicle where import Poseidon.Chronicle (makeChronicle, readChronicle, updateChronicle, writeChronicle) import Poseidon.Package (PackageReadOptions (..), defaultPackageReadOptions, readPoseidonPackageCollection) import Poseidon.Utils (PoseidonIO) data ChronicleOptions = ChronicleOptions { ChronicleOptions -> [FilePath] _chronicleBaseDirs :: [FilePath] , ChronicleOptions -> ChronOperation _chronicleOperation :: ChronOperation } data ChronOperation = CreateChron FilePath | UpdateChron FilePath pacReadOpts :: PackageReadOptions pacReadOpts :: PackageReadOptions pacReadOpts = PackageReadOptions defaultPackageReadOptions { _readOptIgnoreChecksums :: Bool _readOptIgnoreChecksums = Bool True , _readOptIgnoreGeno :: Bool _readOptIgnoreGeno = Bool True , _readOptGenoCheck :: Bool _readOptGenoCheck = Bool False , _readOptIgnorePosVersion :: Bool _readOptIgnorePosVersion = Bool True } runChronicle :: ChronicleOptions -> PoseidonIO () runChronicle :: ChronicleOptions -> PoseidonIO () runChronicle (ChronicleOptions [FilePath] baseDirs ChronOperation operation) = do [PoseidonPackage] allPackages <- PackageReadOptions -> [FilePath] -> PoseidonIO [PoseidonPackage] readPoseidonPackageCollection PackageReadOptions pacReadOpts [FilePath] baseDirs case ChronOperation operation of CreateChron FilePath outPath -> do PoseidonPackageChronicle newChronicle <- FilePath -> [PoseidonPackage] -> PoseidonIO PoseidonPackageChronicle makeChronicle FilePath outPath [PoseidonPackage] allPackages FilePath -> PoseidonPackageChronicle -> PoseidonIO () writeChronicle FilePath outPath PoseidonPackageChronicle newChronicle UpdateChron FilePath inPath -> do PoseidonPackageChronicle newChronicle <- FilePath -> [PoseidonPackage] -> PoseidonIO PoseidonPackageChronicle makeChronicle FilePath inPath [PoseidonPackage] allPackages PoseidonPackageChronicle oldChronicle <- FilePath -> PoseidonIO PoseidonPackageChronicle readChronicle FilePath inPath let updatedChronicle :: PoseidonPackageChronicle updatedChronicle = PoseidonPackageChronicle -> PoseidonPackageChronicle -> PoseidonPackageChronicle updateChronicle PoseidonPackageChronicle oldChronicle PoseidonPackageChronicle newChronicle FilePath -> PoseidonPackageChronicle -> PoseidonIO () writeChronicle FilePath inPath PoseidonPackageChronicle updatedChronicle