From 6081204aa4df0be52f011673e2281f07b29da839 Mon Sep 17 00:00:00 2001 From: Aleksei Pirogov Date: Fri, 25 Oct 2019 10:54:40 +0300 Subject: [PATCH 1/3] Make some of CLI options for dhall-json more consistent --- dhall-json/CHANGELOG.md | 5 +++++ dhall-json/src/Dhall/JSON.hs | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/dhall-json/CHANGELOG.md b/dhall-json/CHANGELOG.md index 7548d878a..d75cde3cb 100644 --- a/dhall-json/CHANGELOG.md +++ b/dhall-json/CHANGELOG.md @@ -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 `--omitNull` to `--omit-null` + * rename `--omit-empty` to `--omit-empty` + * rename `--preserveNull` to `--preserve-null` + * rename `--noMaps` to `--no-maps` * [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 diff --git a/dhall-json/src/Dhall/JSON.hs b/dhall-json/src/Dhall/JSON.hs index 09d2f859e..1759f1be8 100644 --- a/dhall-json/src/Dhall/JSON.hs +++ b/dhall-json/src/Dhall/JSON.hs @@ -624,12 +624,12 @@ parseOmission :: Parser (Value -> Value) parseOmission = Options.Applicative.flag' omitNull - ( Options.Applicative.long "omitNull" + ( Options.Applicative.long "omit-null" <> 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 @@ -640,7 +640,7 @@ parseNullPreservation = Options.Applicative.flag omitNull id - ( Options.Applicative.long "preserveNull" + ( Options.Applicative.long "preserve-null" <> Options.Applicative.help "Preserve record fields that are null" ) @@ -1038,7 +1038,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" ) From 2cd457d5724e103a38a273c40f936a31ecffc9c9 Mon Sep 17 00:00:00 2001 From: Aleksei Pirogov Date: Mon, 28 Oct 2019 10:00:26 +0300 Subject: [PATCH 2/3] fix option parser and array nullification --- dhall-json/src/Dhall/JSON.hs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/dhall-json/src/Dhall/JSON.hs b/dhall-json/src/Dhall/JSON.hs index 1759f1be8..4e62de357 100644 --- a/dhall-json/src/Dhall/JSON.hs +++ b/dhall-json/src/Dhall/JSON.hs @@ -199,7 +199,6 @@ module Dhall.JSON ( dhallToJSON , omitNull , omitEmpty - , parseOmission , parsePreservationAndOmission , Conversion(..) , convertToHomogeneousMaps @@ -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) = @@ -623,16 +622,10 @@ omitEmpty Null = parseOmission :: Parser (Value -> Value) parseOmission = Options.Applicative.flag' - omitNull - ( Options.Applicative.long "omit-null" - <> Options.Applicative.help "Omit record fields that are null" - ) - <|> Options.Applicative.flag' 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) @@ -646,7 +639,7 @@ parseNullPreservation = -- | 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 From 541a451516c03f17ad8ab9d6cbe7ef159dd9f4e2 Mon Sep 17 00:00:00 2001 From: Aleksei Pirogov Date: Mon, 28 Oct 2019 22:29:35 +0300 Subject: [PATCH 3/3] update changelog --- dhall-json/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dhall-json/CHANGELOG.md b/dhall-json/CHANGELOG.md index d75cde3cb..f90ad817f 100644 --- a/dhall-json/CHANGELOG.md +++ b/dhall-json/CHANGELOG.md @@ -1,10 +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 `--omitNull` to `--omit-null` - * rename `--omit-empty` to `--omit-empty` + * 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