-
Notifications
You must be signed in to change notification settings - Fork 451
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
Allow help flags to be specified for any Admin subcommand #5220
Conversation
Moves the Opts class from ServiceStatusCmd and into the `Admin` class.
Separates the check for the `help` opt value from the parseArgs command and creates a separate method for printing the usage statement from the Help class Adds method calls to the new printUsage method so logic is preserved Removes the AdminOpts class
Curious if you tried global parameter validation. It looks like you can create a validator class that is called when
|
030564c
to
f509453
Compare
f509453
to
cb00410
Compare
Use `else if` instead of default `else` case as it will create a client.shutdown rpc call to the manager.
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.
Tested locally and found one problem and made suggestion to fix it. Looks good otherwise.
server/base/src/main/java/org/apache/accumulo/server/util/Admin.java
Outdated
Show resolved
Hide resolved
…n.java Automatically find all subcommand help options instead of formal IF statement. Co-authored-by: Keith Turner <[email protected]>
just curious if my comment about global parameter validation was seen. I think that approach, if it works, would negate the need for every command to extend SubCommandOpts. |
Re-reading the doc, maybe it won't work? It says, "After parsing your parameters with JCommander...", so if extra unknown args like |
This seemed like a really neat way to handle the help param so I spent some time throwing it together. Specifically it attempts to parse the main param on line 819 before attempting the validators on line 822: https://github.com/cbeust/jcommander/blob/8ab73fd92c8ca25bd9358e8e6445ad9bff851747/src/main/java/com/beust/jcommander/JCommander.java#L819 |
@Parameter(names = {"-f", "--force"}, | ||
description = "force the given server to stop by removing its lock") | ||
boolean force = false; | ||
private static class SubCommandOpts { |
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 we need this class? Could the other commands extend Help
like ServerUtilOpts
does?
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 we need this class? Could the other commands extend
Help
likeServerUtilOpts
does?
They could, but the subcommands aren't using the jcommander object that is in the Help class so it seemed like a waste.
Alternatively, we could also remove this class and add the help params to each of the sub commands directly.
It's just a couple more lines of code.
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 wouldn't put any more work into it, just wondering if we could re-use the @Parameter
declaration.
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.
Looks good to me, just had a previous question about whether or not we could re-use the Help class.
If you are interested, I put up the changes for the validator exception: https://github.com/ddanielr/accumulo/pull/34/files#diff-4de8db0c0c757d544b8022eaeb6689358b6c94cda8dde6d57c2f366354fcb126 The
|
Oh, I see, you added the parameter and the validation. I think that looks a little cleaner, but I'll leave it up to you as whether or not to include that |
Fixes #4755.
Modified the code to complete parsing first, then attempt to check for help flags with a second method call.
For most of the locations in the code, this check happens at the same point in time as it did previously.
Specifically for the admin code, the position of the
--help
flag does not matter for command options as it always returns the usage of the parsed command.