Skip to content

Commit

Permalink
Make some of CLI options for dhall-json more consistent (#1475)
Browse files Browse the repository at this point in the history
* Make some of CLI options for dhall-json more consistent

* fix option parser and array nullification

* update changelog
  • Loading branch information
astynax authored and mergify[bot] committed Oct 29, 2019
1 parent 1349a50 commit 2a8735c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
5 changes: 5 additions & 0 deletions dhall-json/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Next version

* [BREAKING CHANGE: Rename some options of `dhall-to-{json,yaml}` to more consistent ones](https://github.com/dhall-lang/dhall-haskell/issues/1430):
* rename `--omitEmpty` to `--omit-empty`
* rename `--preserveNull` to `--preserve-null`
* rename `--noMaps` to `--no-maps`
* drop `--omitNull` as redundant because of `--preserve-null` (see below)
* [BREAKING CHANGE: Enable `--pretty` by default for `dhall-to-json`](https://github.com/dhall-lang/dhall-haskell/issues/716)
* [BREAKING CHANGE: Enable `--omitNull` by default for `dhall-to-{json,yaml}`](https://github.com/dhall-lang/dhall-haskell/pull/1365)
* To recover the old behavior use the `--preserveNull` flag
Expand Down
17 changes: 5 additions & 12 deletions dhall-json/src/Dhall/JSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ module Dhall.JSON (
dhallToJSON
, omitNull
, omitEmpty
, parseOmission
, parsePreservationAndOmission
, Conversion(..)
, convertToHomogeneousMaps
Expand Down Expand Up @@ -609,7 +608,7 @@ omitEmpty (Object object) =
omitEmpty (Array array) =
if null elems then Null else Array elems
where
elems = (fmap omitEmpty array)
elems = Vector.filter (/= Null) (fmap omitEmpty array)
omitEmpty (String string) =
String string
omitEmpty (Number number) =
Expand All @@ -623,30 +622,24 @@ omitEmpty Null =
parseOmission :: Parser (Value -> Value)
parseOmission =
Options.Applicative.flag'
omitNull
( Options.Applicative.long "omitNull"
<> Options.Applicative.help "Omit record fields that are null"
)
<|> Options.Applicative.flag'
omitEmpty
( Options.Applicative.long "omitEmpty"
( Options.Applicative.long "omit-empty"
<> Options.Applicative.help "Omit record fields that are null or empty records"
)
<|> pure id

-- | Parser for command-line options related to preserving null fields.
parseNullPreservation :: Parser (Value -> Value)
parseNullPreservation =
Options.Applicative.flag
omitNull
id
( Options.Applicative.long "preserveNull"
( Options.Applicative.long "preserve-null"
<> Options.Applicative.help "Preserve record fields that are null"
)

-- | Combines parsers for command-line options related to preserving & omitting null fields.
parsePreservationAndOmission :: Parser (Value -> Value)
parsePreservationAndOmission = parseNullPreservation <|> parseOmission <|> pure id
parsePreservationAndOmission = parseOmission <|> parseNullPreservation

{-| Specify whether or not to convert association lists of type
@List { mapKey: Text, mapValue : v }@ to records
Expand Down Expand Up @@ -1044,7 +1037,7 @@ parseConversion =
noConversion =
Options.Applicative.flag'
NoConversion
( Options.Applicative.long "noMaps"
( Options.Applicative.long "no-maps"
<> Options.Applicative.help "Disable conversion of association lists to homogeneous maps"
)

Expand Down

0 comments on commit 2a8735c

Please sign in to comment.