-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #31
- Loading branch information
Showing
13 changed files
with
322 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dr-cabal-debug.json linguist-generated=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{- | | ||
Module : DrCabal.Json | ||
Copyright : (c) 2022 Dmitrii Kovanikov | ||
SPDX-License-Identifier : MPL-2.0 | ||
Maintainer : Dmitrii Kovanikov <kovanikov@gmail.com> | ||
Stability : Experimental | ||
Portability : Portable | ||
This module contains functions to process JSON entries recognised by @dr-cabal@. | ||
-} | ||
|
||
module DrCabal.Json | ||
( readEntries | ||
, writeEntries | ||
) where | ||
|
||
import Data.Aeson (eitherDecodeFileStrict') | ||
import Data.Aeson.Encode.Pretty (encodePretty) | ||
|
||
import DrCabal.Model (Entry) | ||
|
||
import qualified Colourista | ||
|
||
|
||
{- | Read a list of entries from a JSON file. | ||
Exits process with an error message on decoding failure. | ||
-} | ||
readEntries :: FilePath -> IO [Entry] | ||
readEntries file = eitherDecodeFileStrict' file >>= \case | ||
Right entries -> pure entries | ||
Left err -> do | ||
Colourista.errorMessage $ "Error parsing file: " <> toText file | ||
Colourista.redMessage $ " " <> toText err | ||
exitFailure | ||
|
||
-- | Write entries as a pretty JSON to the output file. | ||
writeEntries :: FilePath -> [Entry] -> IO () | ||
writeEntries outputPath = writeFileLBS outputPath . encodePretty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.