@@ -371,6 +371,20 @@ public static Options getToolOptions(Tool tool) {
371371    return  options ;
372372  }
373373
374+   // TODO: SOLR-17429 - remove the custom logic when CommonsCLI is upgraded and 
375+   // makes stderr the default, or makes Option.toDeprecatedString() public. 
376+   private  static  void  deprecatedHandlerStdErr (Option  o ) {
377+     if  (o .isDeprecated ()) {
378+       final  StringBuilder  buf  =
379+           new  StringBuilder ().append ("Option '-" ).append (o .getOpt ()).append ('\'' );
380+       if  (o .getLongOpt () != null ) {
381+         buf .append (",'--" ).append (o .getLongOpt ()).append ('\'' );
382+       }
383+       buf .append (": " ).append (o .getDeprecated ());
384+       CLIO .err (buf .toString ());
385+     }
386+   }
387+ 
374388  /** Parses the command-line arguments passed by the user. */ 
375389  public  static  CommandLine  processCommandLineArgs (Tool  tool , String [] args ) {
376390    List <Option > customOptions  = tool .getOptions ();
@@ -387,7 +401,11 @@ public static CommandLine processCommandLineArgs(Tool tool, String[] args) {
387401
388402    CommandLine  cli  = null ;
389403    try  {
390-       cli  = (new  DefaultParser ()).parse (options , args );
404+       cli  =
405+           DefaultParser .builder ()
406+               .setDeprecatedHandler (SolrCLI ::deprecatedHandlerStdErr )
407+               .build ()
408+               .parse (options , args );
391409    } catch  (ParseException  exp ) {
392410      // Check if we passed in a help argument with a non parsing set of arguments. 
393411      boolean  hasHelpArg  = false ;
@@ -642,7 +660,7 @@ public static String normalizeSolrUrl(String solrUrl, boolean logUrlFormatWarnin
642660        String  newSolrUrl  =
643661            uri .resolve (urlPath .substring (0 , urlPath .lastIndexOf ("/solr" ) + 1 )).toString ();
644662        if  (logUrlFormatWarning ) {
645-           CLIO .out (
663+           CLIO .err (
646664              "WARNING: URLs provided to this tool needn't include Solr's context-root (e.g. \" /solr\" ). Such URLs are deprecated and support for them will be removed in a future release. Correcting from [" 
647665                  + solrUrl 
648666                  + "] to [" 
@@ -670,13 +688,11 @@ public static String normalizeSolrUrl(CommandLine cli) throws Exception {
670688          cli .hasOption ("zk-host" ) ? cli .getOptionValue ("zk-host" ) : cli .getOptionValue ("zkHost" );
671689      if  (zkHost  == null ) {
672690        solrUrl  = SolrCLI .getDefaultSolrUrl ();
673-         CLIO .getOutStream ()
674-             .println (
675-                 "Neither --zk-host or --solr-url parameters provided so assuming solr url is " 
676-                     + solrUrl 
677-                     + "." );
691+         CLIO .err (
692+             "Neither --zk-host or --solr-url parameters provided so assuming solr url is " 
693+                 + solrUrl 
694+                 + "." );
678695      } else  {
679- 
680696        try  (CloudSolrClient  cloudSolrClient  = getCloudHttp2SolrClient (zkHost )) {
681697          cloudSolrClient .connect ();
682698          Set <String > liveNodes  = cloudSolrClient .getClusterState ().getLiveNodes ();
0 commit comments