From 2a8735c2022ff0d5150f68895c1eae9eafccb1e3 Mon Sep 17 00:00:00 2001 From: Aleksei Pirogov Date: Tue, 29 Oct 2019 22:05:13 +0300 Subject: [PATCH] Make some of CLI options for dhall-json more consistent (#1475) * Make some of CLI options for dhall-json more consistent * fix option parser and array nullification * update changelog --- dhall-json/CHANGELOG.md | 5 +++++ dhall-json/src/Dhall/JSON.hs | 17 +++++------------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/dhall-json/CHANGELOG.md b/dhall-json/CHANGELOG.md index 7548d878a..f90ad817f 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 `--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 diff --git a/dhall-json/src/Dhall/JSON.hs b/dhall-json/src/Dhall/JSON.hs index 2fc3da55e..8df793c52 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 "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) @@ -640,13 +633,13 @@ 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 @@ -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" )