2424import java .util .Comparator ;
2525import java .util .Iterator ;
2626import java .util .List ;
27- import java .util .StringTokenizer ;
28- import java .io .InputStream ;
29- import java .io .ByteArrayOutputStream ;
3027
3128/**
3229 * A formatter of help messages for the current command line options
@@ -60,6 +57,9 @@ public class HelpFormatter
6057 /** default prefix for long Option */
6158 public static final String DEFAULT_LONG_OPT_PREFIX = "--" ;
6259
60+ /** default separator displayed between a long Option and its value */
61+ public static final String DEFAULT_LONG_OPT_SEPARATOR = " " ;
62+
6363 /** default name for an argument */
6464 public static final String DEFAULT_ARG_NAME = "arg" ;
6565
@@ -122,6 +122,9 @@ public class HelpFormatter
122122 */
123123 public String defaultLongOptPrefix = DEFAULT_LONG_OPT_PREFIX ;
124124
125+ /** The separator displayed between the long option and its value. */
126+ private String longOptSeparator = DEFAULT_LONG_OPT_SEPARATOR ;
127+
125128 /**
126129 * the name of the argument
127130 *
@@ -277,6 +280,30 @@ public String getLongOptPrefix()
277280 return defaultLongOptPrefix ;
278281 }
279282
283+ /**
284+ * Set the separator displayed between a long option and its value.
285+ * Ensure that the separator specified is supported by the parser used,
286+ * typically ' ' or '='.
287+ *
288+ * @param longOptSeparator the separator, typically ' ' or '='.
289+ * @since 1.3
290+ */
291+ public void setLongOptSeparator (String longOptSeparator )
292+ {
293+ this .longOptSeparator = longOptSeparator ;
294+ }
295+
296+ /**
297+ * Returns the separator displayed between a long option and its value.
298+ *
299+ * @return the separator
300+ * @since 1.3
301+ */
302+ public String getLongOptSeparator ()
303+ {
304+ return longOptSeparator ;
305+ }
306+
280307 /**
281308 * Sets the 'argName'.
282309 *
@@ -500,13 +527,12 @@ public void printHelp(PrintWriter pw, int width, String cmdLineSyntax,
500527 }
501528
502529 /**
503- * <p> Prints the usage statement for the specified application.</p>
530+ * Prints the usage statement for the specified application.
504531 *
505532 * @param pw The PrintWriter to print the usage statement
506533 * @param width The number of characters to display per line
507534 * @param app The application name
508535 * @param options The command line Options
509- *
510536 */
511537 public void printUsage (PrintWriter pw , int width , String app , Options options )
512538 {
@@ -607,7 +633,7 @@ private void appendOptionGroup(final StringBuffer buff, final OptionGroup group)
607633 * @param option the Option to append
608634 * @param required whether the Option is required or not
609635 */
610- private static void appendOption (final StringBuffer buff , final Option option , final boolean required )
636+ private void appendOption (final StringBuffer buff , final Option option , final boolean required )
611637 {
612638 if (!required )
613639 {
@@ -626,7 +652,8 @@ private static void appendOption(final StringBuffer buff, final Option option, f
626652 // if the Option has a value
627653 if (option .hasArg () && option .hasArgName ())
628654 {
629- buff .append (" <" ).append (option .getArgName ()).append (">" );
655+ buff .append (option .getOpt () == null ? longOptSeparator : " " );
656+ buff .append ("<" ).append (option .getArgName ()).append (">" );
630657 }
631658
632659 // if the Option is not a required option
@@ -652,8 +679,8 @@ public void printUsage(PrintWriter pw, int width, String cmdLineSyntax)
652679 }
653680
654681 /**
655- * <p> Print the help for the specified Options to the specified writer,
656- * using the specified width, left padding and description padding.</p>
682+ * Print the help for the specified Options to the specified writer,
683+ * using the specified width, left padding and description padding.
657684 *
658685 * @param pw The printWriter to write the help to
659686 * @param width The number of characters to display per line
@@ -756,7 +783,8 @@ protected StringBuffer renderOptions(StringBuffer sb, int width, Options options
756783 {
757784 if (option .hasArgName ())
758785 {
759- optBuf .append (" <" ).append (option .getArgName ()).append (">" );
786+ optBuf .append (option .hasLongOpt () ? longOptSeparator : " " );
787+ optBuf .append ("<" ).append (option .getArgName ()).append (">" );
760788 }
761789 else
762790 {
0 commit comments