Add the `--preserveNull` flag and omit null fields by default on `dhall-to-yaml` (#1365)
* Add the `--preserveNull` flag and omit null fields by default on `dhall-to-yaml` fixes #1354 * Restore the `--omitNull` flag and apply `--preserveNull` to `dhall-to-json` * Adjust examples that return null fields * Mention the default behaviour regarding nulls * Null -> null
This commit is contained in:
parent
7634ee740b
commit
045ed99ae5
|
@ -41,7 +41,7 @@ parseOptions =
|
||||||
( Options
|
( Options
|
||||||
<$> parseExplain
|
<$> parseExplain
|
||||||
<*> parsePretty
|
<*> parsePretty
|
||||||
<*> Dhall.JSON.parseOmission
|
<*> Dhall.JSON.parsePreservationAndOmission
|
||||||
<*> Dhall.JSON.parseConversion
|
<*> Dhall.JSON.parseConversion
|
||||||
<*> parseApproximateSpecialDoubles
|
<*> parseApproximateSpecialDoubles
|
||||||
<*> optional parseFile
|
<*> optional parseFile
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Main where
|
||||||
import Control.Applicative (optional, (<|>))
|
import Control.Applicative (optional, (<|>))
|
||||||
import Control.Exception (SomeException)
|
import Control.Exception (SomeException)
|
||||||
import Data.Monoid ((<>))
|
import Data.Monoid ((<>))
|
||||||
import Dhall.JSON (parseOmission, parseConversion)
|
import Dhall.JSON (parsePreservationAndOmission, parseConversion)
|
||||||
import Dhall.Yaml (Options(..), dhallToYaml, parseDocuments, parseQuoted)
|
import Dhall.Yaml (Options(..), dhallToYaml, parseDocuments, parseQuoted)
|
||||||
import Options.Applicative (Parser, ParserInfo)
|
import Options.Applicative (Parser, ParserInfo)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ parseOptions =
|
||||||
Just
|
Just
|
||||||
<$> ( Options
|
<$> ( Options
|
||||||
<$> parseExplain
|
<$> parseExplain
|
||||||
<*> Dhall.JSON.parseOmission
|
<*> Dhall.JSON.parsePreservationAndOmission
|
||||||
<*> parseDocuments
|
<*> parseDocuments
|
||||||
<*> parseQuoted
|
<*> parseQuoted
|
||||||
<*> Dhall.JSON.parseConversion
|
<*> Dhall.JSON.parseConversion
|
||||||
|
|
|
@ -175,7 +175,10 @@
|
||||||
> }
|
> }
|
||||||
> ]
|
> ]
|
||||||
|
|
||||||
> $ dhall-to-json <<< './example.dhall'
|
By default, the fields that are evaluated to @null@ will be removed,
|
||||||
|
but here we're preserving them with the @--preserveNull@ flag.
|
||||||
|
|
||||||
|
> $ dhall-to-json --preserveNull <<< './example.dhall'
|
||||||
> {
|
> {
|
||||||
> "bar": [
|
> "bar": [
|
||||||
> 1,
|
> 1,
|
||||||
|
@ -197,6 +200,7 @@ module Dhall.JSON (
|
||||||
, omitNull
|
, omitNull
|
||||||
, omitEmpty
|
, omitEmpty
|
||||||
, parseOmission
|
, parseOmission
|
||||||
|
, parsePreservationAndOmission
|
||||||
, Conversion(..)
|
, Conversion(..)
|
||||||
, convertToHomogeneousMaps
|
, convertToHomogeneousMaps
|
||||||
, parseConversion
|
, parseConversion
|
||||||
|
@ -630,6 +634,20 @@ parseOmission =
|
||||||
)
|
)
|
||||||
<|> pure id
|
<|> 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.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
|
||||||
|
|
||||||
{-| Specify whether or not to convert association lists of type
|
{-| Specify whether or not to convert association lists of type
|
||||||
@List { mapKey: Text, mapValue : v }@ to records
|
@List { mapKey: Text, mapValue : v }@ to records
|
||||||
-}
|
-}
|
||||||
|
|
Loading…
Reference in New Issue