janhoy commented on code in PR #3240: URL: https://github.com/apache/solr/pull/3240#discussion_r1982951185
########## solr/core/src/java/org/apache/solr/cli/CLIUtils.java: ########## @@ -216,12 +217,32 @@ public static String normalizeSolrUrl(CommandLine cli) throws Exception { } /** - * Get the ZooKeeper connection string from either the zk-host command-line option or by looking - * it up from a running Solr instance based on the solr-url option. + * Get the value of the specified CLI option with fallback to system property and default value. + * + * @param cli the command line + * @param option the commons cli {@link Option} + * @param sysprop the system property to fall back to + * @param defaultValue the default value. Use null if no default value is desired + * @return the value of the option or system property or the default value + */ + public static String getCliOptionOrPropValue( + CommandLine cli, Option option, String sysprop, String defaultValue) { + String value = cli.getOptionValue(option); + if (value == null) { + value = EnvUtils.getProperty(sysprop, defaultValue); + } + return value; + } Review Comment: @epugh In my last commit I generalized the util method to this `getCliOptionOrPropValue` which can be used by any Tool that wishes to read a CLI OPTION with a fallback to env/prop and also a fallback to defaultvalue. Currently I only use it for zkhost. IMO the calling code also becomes more clear, as you will see in the same line both the OPT name and the prop name. Perhaps this could be used also for SOLR_URL? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org