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

[#6097] improve(CLI): Add --quiet option to the Gravition CLI #6198

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Abyss-lord
Copy link
Contributor

What changes were proposed in this pull request?

Add a --quiet option to the Gravition CLI to suppress all output except for errors. The following command implements the logic for processing the --quiet argument.

  1. AddXXX
  2. CreateXXX
  3. XXXEnable
  4. XXXDisable
  5. DeleteXXX
  6. GrantXXX
  7. RemoveXXX
  8. RevokeXXX
  9. SetXXXProperty

All tests have been updated. Currently, #6139, #6147, and #6152 have not been merged yet. I will update the XXXCommandHandler after they are merged.

Why are the changes needed?

Fix: #6097

Does this PR introduce any user-facing change?

No

How was this patch tested?

local test + UT

gcli metalake update -m demo_metalake --disable -i
#demo_metalake has been disabled.

gcli metalake update -m demo_metalake --disable -i --quiet

gcli metalake update -m demo_metalake --enable -i
# demo_metalake has been enabled.

gcli metalake update -m demo_metalake --enable -i --quiet

Add --quiet option to the Gravition CLI to suppress all output except for errors.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

fix test issues.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor Tag, Metalake and Fileset code.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor Column handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor OwnerShip handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor User handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor Role handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor Group handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor Schema handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor Topic handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor and format handlers and test cases.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor CommandHandler and TestableCommandLine.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor TestableCommandLine

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor all commands.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

Refactor Command class .

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

Add --quiet option to the Gravition CLI to suppress all output except for errors.
@Abyss-lord
Copy link
Contributor Author

@justinmclean @tengqm , could you please review this PR when you have time? I’d really appreciate your feedback.

@justinmclean
Copy link
Member

In general, this looks good, and only a couple of minor comments, but I'm not sure why you added eq calls to many tests when it's not required.

@Abyss-lord
Copy link
Contributor Author

Hi @justinmclean , I’ve finished updating the code. Please take a look at the PR again when you have time.

@justinmclean
Copy link
Member

Looks good, just one comment to address that was unresolved.

@Abyss-lord
Copy link
Contributor Author

Abyss-lord commented Jan 13, 2025

Looks good, just one comment to address that was unresolved.

@justinmclean fix, plz review again.

@tengqm
Copy link
Contributor

tengqm commented Jan 13, 2025

/lgtm

justinmclean and others added 5 commits January 14, 2025 11:39
Add --quiet option to the Gravition CLI to suppress all output except for errors.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

fix test issues.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor Tag, Metalake and Fileset code.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor Column handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor OwnerShip handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor User handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor Role handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor Group handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor Schema handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor Topic handler and test.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor and format handlers and test cases.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor CommandHandler and TestableCommandLine.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor TestableCommandLine

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

refactor all commands.

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

Refactor Command class .

[apache#6097] improve(CLI): Add --quiet option to the Gravition CLI

Add --quiet option to the Gravition CLI to suppress all output except for errors.
@Abyss-lord
Copy link
Contributor Author

Abyss-lord commented Jan 14, 2025

@justinmclean @jerryshao I’ve finished updating the code. Please take a look at the PR again when you have time.

# Conflicts:
#	clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
justinmclean
justinmclean previously approved these changes Jan 14, 2025
Copy link
Member

@justinmclean justinmclean left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for your work here.

@jerryshao
Copy link
Contributor

jerryshao commented Jan 14, 2025

What is the usage of this variable, can we elaborate the usage scenario for this? Also the change seems too fragmented, we need to change the code everywhere, A better way is to define an output class and can be controlled in there, rather than adding system output everywhere.

Besides, if we don't want output, we can simply use /foo/bar 2&1 > /dev/null, which is a typical usage pattern in *nix, I'm curious what is the benefit of adding this.

@shaofengshi
Copy link
Contributor

What is the usage of this variable, can we elaborate the usage scenario for this? Also the change seems too fragmented, we need to change the code everywhere, A better way is to define an output class and can be controlled in there, rather than adding system output everywhere.

Besides, if we don't want output, we can simply use /foo/bar 2&1 > /dev/null, which is a typical usage pattern in *nix, I'm curious what is the benefit of adding this.

+1; the current implementation is not good.

@justinmclean
Copy link
Member

It was added at the request of @tengqm with the advice of https://clig.dev.

For example: "For instances where you do want no output (for example, when used in shell scripts), to avoid clumsy redirection of stderr to /dev/null, you can provide a -q option to suppress all non-essential output."

@tengqm
Copy link
Contributor

tengqm commented Jan 14, 2025

It was added at the request of @tengqm with the advice of https://clig.dev.

For example: "For instances where you do want no output (for example, when used in shell scripts), to avoid clumsy redirection of stderr to /dev/null, you can provide a -q option to suppress all non-essential output."

Right. This change seems like a compromise between stricter traditional command outputs and something advised elsewhere. In some reviews to CLI command outputs (cannot recall exactly which one though), I raised my concern about the necessity of printing success messages, such as "something has been successfully removed/updated". I was more inclined to explicit, ationable error messages when things go bad, or silent success with no output if an acction succeeded. We are not creating a chatbot with the CLI tool after all. Verbose outputs may also complicate the scriptability of the CLI command. There were other arguments that this verbose messages are actually desirable, and they can be suppressed using a -q argument. I tend to agree with this approach. That is the background.

Back to the implementation, I am a little bit sick of the actual implementation at this moment. Without an appropriate schema to group or to abstract the command line arguments, this kind of changes won't be uncommon in the foreseeable future. For example, for all list operations, we may want a --sort option, or even a --sort-order option; for another example, we may want filtering, paging options.

A cleaner solution, on top of my head, is to have something like this:

  • a GenericOptions for flags like url, metalake, authenticate, ignore-version, verbose etc.
  • a ListOptions for flags like sort, output-format, filter, ...
  • a DeleteOptions for flags like force, cascaded, forever, etc.

We are not there yet. But if we are on the same page, knowing where we are heading, this change should be fine.

@justinmclean
Copy link
Member

I think one small improvement would be to add this to the base class:

  protected void optionalOutput(String message) {
    if (!quiet) {
      System.out.println(message);
    }
  }

and call optionalOutput in commands to remove the multiple if (quiet) return; lines. This gives more flexibility in the future regarding the control of the output.

Another solution to avoid passing quiet around (and changing so many files) would involve creating a global config singleton, but that has its own issues and I think is to be best avoided. We could also pass around a command context (same no of files changed, but less changes would be required for future similar changes) or as suggested above grouping different options into classes. I would suggest doing that as a separate PR for this, as the saying goes "Make it work, then make it good."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Improvement] Add --quiet option to the Gravition CLI
5 participants