private String [ ] parseOpts ( String [ ] args ) { if ( args == null || args . length == 0 ) { return new String [ 0 ] ; } final List < String > remainingArgs = new ArrayList < String > ( ) ; final List < String > argsList = Arrays . asList ( args ) ; final ListIterator < String > argsIt = argsList . listIterator ( ) ; while ( argsIt . hasNext ( ) ) { String word = argsIt . next ( ) ; if ( word . startsWith ( "--" ) ) { // long option --foo final String option = stripLeadingHyphens ( word ) ; if ( VERBOSE_LONG_OPT . equals ( option ) ) { longOpts . put ( option , "true" ) ; } else if ( DEBUG_LONG_OPT . equals ( option ) ) { longOpts . put ( option , "true" ) ; } else if ( HELP_LONG_OPT . equals ( option ) ) { longOpts . put ( option , "true" ) ; } else { final String arg = parseOptionArg ( option , argsIt ) ; longOpts . put ( option , arg ) ; } } else if ( word . startsWith ( "-" ) ) { String options = stripLeadingHyphens ( word ) ; // single short option -f if ( options . length ( ) == 1 ) { // only slurp argument if option is argumented final String arg = parseOptionArg ( options , argsIt ) ; shortOpts . put ( options , arg ) ; continue ; } // multiple short options -fxy, // treat as non-argumented java.lang.Boolean variables, no slurp for ( int i = 0 ; i < options . length ( ) ; i ++ ) { final String option = Character . toString ( options . charAt ( i ) ) ; shortOpts . put ( option , "true" ) ; } } else { remainingArgs . add ( word ) ; } } return remainingArgs . toArray ( new String [ 0 ] ) ; }
Parse the options for the command .