-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-8131: Moved --version argument implementation from kafka-run-class.sh to CommandLineUtils to include documentation in command line help #6481
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
Changes from all commits
0cdf93b
aba9ef8
1ff4e2e
92db08c
7ec6c23
049be2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| import java.util.Properties | ||
|
|
||
| import joptsimple.{OptionParser, OptionSet, OptionSpec} | ||
| import org.apache.kafka.common.utils.AppInfoParser | ||
|
|
||
| import scala.collection.Set | ||
|
|
||
|
|
@@ -36,16 +37,27 @@ object CommandLineUtils extends Logging { | |
| return commandOpts.args.length == 0 || commandOpts.options.has(commandOpts.helpOpt) | ||
| } | ||
|
|
||
| def isPrintVersionNeeded(commandOpts: CommandDefaultOptions): Boolean = { | ||
| commandOpts.options.has(commandOpts.versionOpt) | ||
| } | ||
|
|
||
| /** | ||
| * Check and print help message if there is no options or `--help` option | ||
| * from command line | ||
| * from command line, if `--version` is specified on the command line | ||
| * print version information and exit. | ||
| * NOTE: The function name is not strictly speaking correct anymore | ||
| * as it also checks whether the version needs to be printed, but | ||
| * refactoring this would have meant changing all command line tools | ||
| * and unnecessarily increased the blast radius of this change. | ||
| * | ||
| * @param commandOpts Acceptable options for a command | ||
| * @param message Message to display on successful check | ||
| */ | ||
| def printHelpAndExitIfNeeded(commandOpts: CommandDefaultOptions, message: String) = { | ||
| if (isPrintHelpNeeded(commandOpts)) | ||
| printUsageAndDie(commandOpts.parser, message) | ||
| if (isPrintVersionNeeded(commandOpts)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm.. I'm not sure this is called by all the commands that go through
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been through the scripts in bin/ and looked at how many would be affected by this. There are three classes that use CommandLineUtils but don't hit this method: ReplicaVerificationTool, Kafka, StreamsResetter. The issue with these classes is, I think, that they internally do not use an object that extends CommandDefaultOptions - hence ignore those options completely. The rest of the tools either call this method or handle argument parsing in a totally different way. Not sure what the correct way forward is, to be honest, command line parsing seems a little all over the place in general, so the only place where this is truly global is indeed in kafka-run-class.sh, but that doesn't feel right either, as it is a completely undocumented on the command line that way.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there only 3 exceptions, do you think it would be reasonable to implement
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @hachikuji In the interest of completion, handling those three would leave the following classes that do not support the version option (or help for that matter unless they implemented that separately):
I'm not sure why a small subset of these uses argparse4j, I briefly looked around but couldn't find a larger scheme to adopt this over the CommandLineUtils, do you know anything more about that? Should we extend these classes as well to honor the version flag? Should be simple-ish, but still requires adding an option to all parsers, unless we create the equivalent of the CommandDefaultOptions for argparse4j classes. But I'd say this is better suited for the follow-up PR you mentioned to standardize command line parsing. So, my proposal woud be: Fair?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm not sure why they use argparse4j. Maybe just to make our lives harder. Your suggestion sounds fine to me. Would you mind filing JIRAs for the remaining work?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect there are no good reasons, but starting a discussion is a good idea. There is an ancient KIP which was attempting to consolidate these tools: https://cwiki.apache.org/confluence/display/KAFKA/KIP-14+-+Tools+Standardization. If you have any interest, it would really be helpful for someone to pick that up again. I think one of the reasons for the naming inconsistencies has been the fact that we are using different libraries.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having looked some more at the two Connect classes, there is a small catch: everything we'd need to add the --version parameter to those classes is in the core Kafka project which Connect currently does not declare as a dependency. It seems a bit excessive to add that just for this purpose. |
||
| printVersionAndDie() | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -91,6 +103,11 @@ object CommandLineUtils extends Logging { | |
| Exit.exit(1, Some(message)) | ||
| } | ||
|
|
||
| def printVersionAndDie(): Nothing = { | ||
| System.out.println(VersionInfo.getVersionString) | ||
| Exit.exit(0) | ||
| } | ||
|
|
||
| /** | ||
| * Parse key-value pairs in the form key=value | ||
| * value may contain equals sign | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.