Skip to content

Make --[no-]show-... options work with JSON output#308

Merged
2 commits merged intodevelopfrom
unknown repository
Feb 27, 2023
Merged

Make --[no-]show-... options work with JSON output#308
2 commits merged intodevelopfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Feb 20, 2023

Purpose

The CLI has several options to specify which field to display. Such options are not available when using JSON output --json or --json-stream. This PR make such options work with JSON output.

Context

#247 (comment)

Changes

  • Make --[no-]show-... options work with JSON output
  • Display translated message tag when passing --json and --json-translate

How to test this PR

Try several combinations using the --[no-]show-... and/or --[no-]time options and check that the fields are properly displayed or not. Also check that the combination --json --json-translate properly return the translated message.

$ zonemaster-cli --no-show-module --show-testcase --test connectivity --level INFO --json --json-translate afnic.fr | jq
[
  {
    "args": {
      "version": "v4.6.1"
    },
    "level": "INFO",
    "message": "Using version v4.6.1 of the Zonemaster engine.",
    "tag": "GLOBAL_VERSION"
  },
  {
    "args": {
      "asn_list": "2485,2486"
    },
    "level": "INFO",
    "message": "At least two IPv4 addresses of the authoritative nameservers are announce by different AS sets. A merged list of all AS: (2485,2486).",
    "tag": "IPV4_DIFFERENT_ASN"
  },
  {
    "args": {
      "asn_list": "2485,2486"
    },
    "level": "INFO",
    "message": "At least two IPv6 addresses of the authoritative nameservers are announce by different AS sets. A merged list of all AS: (2485,2486).",
    "tag": "IPV6_DIFFERENT_ASN"
  }
]

Passing --no-{time,show-level,show-module,show-testcase} should work
with --json or --json-stream.
@ghost ghost added the V-Major Versioning: The change gives an update of major in version. label Feb 20, 2023
@ghost ghost added this to the v2023.1 milestone Feb 20, 2023
@ghost ghost requested review from matsduf and vlevigneron February 20, 2023 10:06
@matsduf
Copy link
Contributor

matsduf commented Feb 21, 2023

Also see #247 (comment)

This is fine, but the documentation must be updated:

        --[no-]json-translate  Flag indicating if streaming JSON output
                               should include the translated message of the
                               tag or not.

What does --raw mean in combination with --json?

When --raw is given without --json then you get the tag and the arguments for that tag. Can you get the arguments here?

@ghost
Copy link
Author

ghost commented Feb 21, 2023

What does --raw mean in combination with --json?

--raw only applies to the message tag. --json --raw would mean "output the message tag without translating it into any human language".

When --raw is given without --json then you get the tag and the arguments for that tag. Can you get the arguments here?

I'm not sure I understand your question. Could you explain?

@ghost ghost requested review from hannaeko, marc-vanderwal and tgreenx February 22, 2023 09:35
Copy link
Contributor

@tgreenx tgreenx left a comment

Choose a reason for hiding this comment

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

Also see #247 (comment)

This is fine, but the documentation must be updated:

        --[no-]json-translate  Flag indicating if streaming JSON output
                               should include the translated message of the
                               tag or not.

What does --raw mean in combination with --json?

When --raw is given without --json then you get the tag and the arguments for that tag. Can you get the arguments here?

As mentioned in the cited comment, --[no-]json-translate appears entirely redundant to --[no-]raw. Up until it gets removed, I agree that the documentation could use some detail when both are used. Right now, --[no-]raw has no effect when combined with --[no-]json. Also, --[no-]json-translate takes precedence over --[no-]raw.

Other than that LGTM, tested and works as described.

@ghost
Copy link
Author

ghost commented Feb 22, 2023

I've updated the documentation for --json-translate.

@ghost ghost requested a review from tgreenx February 22, 2023 17:33
@matsduf
Copy link
Contributor

matsduf commented Feb 23, 2023

When --raw is given without --json then you get the tag and the arguments for that tag. Can you get the arguments here?

I'm not sure I understand your question. Could you explain?

Forget my comment. Now it looks OK.

@matsduf
Copy link
Contributor

matsduf commented Feb 23, 2023

This looks fine, but could --raw get more complete documentation, e.g.

	--[no-]raw     Flag indicating if output should be translated
	                       to human language or dumped raw. This flag is
                               ignored if --json or --json-stream has been given.

@ghost
Copy link
Author

ghost commented Feb 24, 2023

This looks fine, but could --raw get more complete documentation, e.g.

I'm not against it. However I'd like to share why I'd like not to add this to this PR:

  • I want this PR to focus on the JSON implementation. Therefore, I think, this small change is outside of scope.
  • I want this PR to avoid updating the documentation too much since I find it good. I use the documentation as a goal when updating the implementation.
  • I'm planning in a follow-up PR to deprecate --[no-]json-translate and replace it with --[no-]raw.

@matsduf
Copy link
Contributor

matsduf commented Feb 26, 2023

  • I'm planning in a follow-up PR to deprecate --[no-]json-translate and replace it with --[no-]raw.

So you mean that --json-translate will be replaced by --no-raw and --no-json-translate by --raw?

If the end result is that it will be clear in the documentation what options that can be combined and not that I am fine with it.

@ghost
Copy link
Author

ghost commented Feb 27, 2023

So you mean that --json-translate will be replaced by --no-raw and --no-json-translate by --raw?

Yes. This is exactly what I intend to do.

Copy link
Contributor

@matsduf matsduf left a comment

Choose a reason for hiding this comment

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

Requires additional PRs, but this part is fine.

@ghost ghost merged commit 9798fea into zonemaster:develop Feb 27, 2023
@tgreenx
Copy link
Contributor

tgreenx commented May 31, 2023

v2023.1 Release testing

Basic testing:

  • Options --[no-]show-... work with JSON output. --> OK
  • Display translated message tag when passing --json and --json-translate. --> OK

Bugs:

Observations:

  • --json --no-raw (or just --json) includes the content of --raw (message tag and args) --> Acceptable but undocumented behavior.

@tgreenx tgreenx added the S-ReleaseTested Status: The PR has been successfully tested in release testing label May 31, 2023
@ghost ghost mentioned this pull request May 31, 2023
@ghost ghost deleted the json-show-options branch June 22, 2023 13:05
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-ReleaseTested Status: The PR has been successfully tested in release testing V-Major Versioning: The change gives an update of major in version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants