malliaridis commented on PR #2721:
URL: https://github.com/apache/solr/pull/2721#issuecomment-2380631255

   > You still have to check for each it apepars!! If you find some code that 
avoids that, let me know.
   
   I see that you are using the `Option#getOpt()` and `Option#getLongOpt()` 
when you use `CommandLine#getOptionValue(String option)` or 
`CommandLine#hasOption(String option)`.
   
   There is also a `CommandLine#getOptionValue(Option option)` and 
`CommandLine#getOptionValue(OptionGroup optionGroup)` that you could use 
instead. Same applies for `hasOption`. That way it is possible to use the 
`OptionGroup` and simplify logic as proposed before.
   
   You can also set things like `required` (exactly one of the options in the 
group is present) at the `OptionGroup` via `OptionGroup#setRequired(boolean 
required)`. This is useful for cases where required options are split intot two 
due to deprecation, made optional and checked later for presence explicitly, 
like in 
[ConfigTool.java](https://github.com/apache/solr/pull/2721/files#diff-4dc9e0c436824dac317a2023038313dacbb6cd6d5aa592cc8c3e06d071335a87):
   
   ```java
   Option.builder("v")
       .longOpt("value")
       .deprecated(...)
       .required(false)
       //...
   Option.builder()
       .longOpt("value")
       .required(false) // should be true when -v is removed.
       //...
   
   String value = SolrCLI.getOptionWithDeprecatedAndDefault(cli, "value", "v", 
null);
   //...
   if (value == null) {
       throw new MissingArgumentException("'value' is a required option.");
   }
   ```
   
   Using `OptionGroup`s will probably render 
`SolrCLI#getOptionWithDeprecatedAndDefault(...)` obsolete.


-- 
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

Reply via email to