-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make some of CLI options for dhall-json more consistent #1475
Make some of CLI options for dhall-json more consistent #1475
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the renaming of the --preserveNull
and --noMaps
options, I think the breaking change is ok: --preserveNull
is brand new, and I suspect that --noMaps
is not very popular. Thoughts @Gabriel439?
dhall-json/src/Dhall/JSON.hs
Outdated
@@ -624,12 +624,12 @@ parseOmission :: Parser (Value -> Value) | |||
parseOmission = | |||
Options.Applicative.flag' | |||
omitNull | |||
( Options.Applicative.long "omitNull" | |||
( Options.Applicative.long "omit-null" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether it's worth breaking compatibility here. --omitNull
is the default setting, and I was assuming that we could get rid of it soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--omitNull
is the default setting
I have a question about it. This parser looks like one that always return omitNull
because of flag
(that always succeed) as a first Alternative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean this bit?
dhall-haskell/dhall-json/src/Dhall/JSON.hs
Lines 639 to 642 in 90315e9
parseNullPreservation = | |
Options.Applicative.flag | |
omitNull | |
id |
omitNull
is the default value here, so if we pass --preserveNull
, the result is id
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parser returns a function in any case. It can't fail. So
parseNullPreservation <|> smth
will never try to use smth
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that
parsePreservationAndOmission = parseNullPreservation <|> parseOmission <|> pure id
will never use parseOmissions
because of always successful parseNullPreservation
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yes, you're completely right! Good catch! :)
Can you fix this so --omitNull
and --omitEmpty
still have an effect when passed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I can see, for now omit-null
is complete useless: the omitNull
is a default value for preserve-null
flag. So this two flags are opposites.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If default behavior is omitting of nulls, I propose to remove --omit-null
as redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just removed --omit-nulls
.
<> Options.Applicative.help "Omit record fields that are null" | ||
) | ||
<|> Options.Applicative.flag' | ||
omitEmpty | ||
( Options.Applicative.long "omitEmpty" | ||
( Options.Applicative.long "omit-empty" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omit-mpty
also "nullifies" not only empty arrays but also empty objects. omissible-lists
translates only null ~> []
but not null ~> {}
. So omit-empty
and omissible-lists
are not complete opposites.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking! Seems like a bit of an unfortunate oversight! Let's maybe keep the --omit-empty
name for now then, and discuss this further on the issue.
@sjakobi: Yeah, I'm pretty sure nobody will complain if we rename those |
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a bug
<> Options.Applicative.help "Omit record fields that are null" | ||
) | ||
<|> Options.Applicative.flag' | ||
omitEmpty | ||
( Options.Applicative.long "omitEmpty" | ||
( Options.Applicative.long "omit-empty" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking! Seems like a bit of an unfortunate oversight! Let's maybe keep the --omit-empty
name for now then, and discuss this further on the issue.
dhall-json/CHANGELOG.md
Outdated
@@ -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` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you fix this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
dhall-json/CHANGELOG.md
Outdated
@@ -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` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* rename `--omit-empty` to `--omit-empty` | |
* rename `--omitEmpty` to `--omit-empty` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* rename `--omitNull` to `--omit-null` | ||
* rename `--omit-empty` to `--omit-empty` | ||
* rename `--preserveNull` to `--preserve-null` | ||
* rename `--noMaps` to `--no-maps` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes below have already been released. Can you separate the new entries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! :)
Closes #1430