@@ -22,6 +22,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2222import java .util .Iterator ;
2323import java .util .List ;
2424
25+ import org .apache .commons .cli .help .OptionFormatter ;
26+
2527/**
2628 * The class PosixParser provides an implementation of the {@link Parser#flatten(Options,String[],boolean) flatten}
2729 * method.
@@ -81,7 +83,7 @@ protected void burstToken(final String token, final boolean stopAtNonOption) {
8183 }
8284 break ;
8385 }
84- tokens .add ("-" + ch );
86+ tokens .add (OptionFormatter . DEFAULT_OPT_PREFIX + ch );
8587 currentOption = options .getOption (ch );
8688 if (currentOption .hasArg () && token .length () != i + 1 ) {
8789 tokens .add (token .substring (i + 1 ));
@@ -132,9 +134,9 @@ protected String[] flatten(final Options options, final String[] arguments, fina
132134 final String token = iter .next ();
133135 if (token != null ) {
134136 // single or double hyphen
135- if ("-" . equals (token ) || "--" .equals (token )) {
137+ if (OptionFormatter . DEFAULT_OPT_PREFIX . equals (token ) || OptionFormatter . DEFAULT_LONG_OPT_PREFIX .equals (token )) {
136138 tokens .add (token );
137- } else if (token .startsWith ("--" )) {
139+ } else if (token .startsWith (OptionFormatter . DEFAULT_LONG_OPT_PREFIX )) {
138140 // handle long option --foo or --foo=bar
139141 final int pos = DefaultParser .indexOfEqual (token );
140142 final String opt = pos == -1 ? token : token .substring (0 , pos ); // --foo
@@ -145,12 +147,12 @@ protected String[] flatten(final Options options, final String[] arguments, fina
145147 throw new AmbiguousOptionException (opt , matchingOpts );
146148 } else {
147149 currentOption = options .getOption (matchingOpts .get (0 ));
148- tokens .add ("--" + currentOption .getLongOpt ());
150+ tokens .add (OptionFormatter . DEFAULT_LONG_OPT_PREFIX + currentOption .getLongOpt ());
149151 if (pos != -1 ) {
150152 tokens .add (token .substring (pos + 1 ));
151153 }
152154 }
153- } else if (token .startsWith ("-" )) {
155+ } else if (token .startsWith (OptionFormatter . DEFAULT_OPT_PREFIX )) {
154156 if (token .length () == 2 || options .hasOption (token )) {
155157 processOptionToken (token , stopAtNonOption );
156158 } else if (!options .getMatchingOptions (token ).isEmpty ()) {
@@ -159,7 +161,7 @@ protected String[] flatten(final Options options, final String[] arguments, fina
159161 throw new AmbiguousOptionException (token , matchingOpts );
160162 }
161163 final Option opt = options .getOption (matchingOpts .get (0 ));
162- processOptionToken ("-" + opt .getLongOpt (), stopAtNonOption );
164+ processOptionToken (OptionFormatter . DEFAULT_OPT_PREFIX + opt .getLongOpt (), stopAtNonOption );
163165 }
164166 // requires bursting
165167 else {
@@ -205,7 +207,7 @@ private void init() {
205207 private void processNonOptionToken (final String value , final boolean stopAtNonOption ) {
206208 if (stopAtNonOption && (currentOption == null || !currentOption .hasArg ())) {
207209 eatTheRest = true ;
208- tokens .add ("--" );
210+ tokens .add (OptionFormatter . DEFAULT_LONG_OPT_PREFIX );
209211 }
210212 tokens .add (value );
211213 }
0 commit comments