Skip to content
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

Merged
merged 4 commits into from
Oct 29, 2019
Merged

Make some of CLI options for dhall-json more consistent #1475

merged 4 commits into from
Oct 29, 2019

Conversation

astynax
Copy link
Contributor

@astynax astynax commented Oct 25, 2019

Closes #1430

Copy link
Collaborator

@sjakobi sjakobi left a 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?

@@ -624,12 +624,12 @@ parseOmission :: Parser (Value -> Value)
parseOmission =
Options.Applicative.flag'
omitNull
( Options.Applicative.long "omitNull"
( Options.Applicative.long "omit-null"
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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?

parseNullPreservation =
Options.Applicative.flag
omitNull
id

omitNull is the default value here, so if we pass --preserveNull, the result is id.

http://hackage.haskell.org/package/optparse-applicative-0.15.1.0/docs/Options-Applicative-Builder.html#v:flag

Copy link
Contributor Author

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.

Copy link
Contributor Author

@astynax astynax Oct 25, 2019

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok!

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the move from --omitEmpty to --omissible-lists discussed in #1414 and originally proposed in #1410?

Would you mind checking that --omitEmpty and --omissible-lists are indeed opposites?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

@Gabriella439
Copy link
Collaborator

@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)
Copy link
Contributor Author

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"
Copy link
Collaborator

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.

@@ -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`
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -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`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* rename `--omit-empty` to `--omit-empty`
* rename `--omitEmpty` to `--omit-empty`

Copy link
Contributor Author

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`
Copy link
Collaborator

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?

Copy link
Collaborator

@sjakobi sjakobi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! :)

@mergify mergify bot merged commit 2a8735c into dhall-lang:master Oct 29, 2019
@astynax astynax deleted the dhall-json-cli-options-renaming branch October 30, 2019 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consistent CLI options in dhall-json
3 participants