public void parseAndInject ( String [ ] args , T injectee ) throws InvalidCommandException { this . injectee = injectee ; pendingInjections . clear ( ) ; Iterator < String > argsIter = Iterators . forArray ( args ) ; ImmutableList . Builder < String > builder = ImmutableList . builder ( ) ; while ( argsIter . hasNext ( ) ) { String arg = argsIter . next ( ) ; if ( arg . equals ( "--" ) ) { break ; // "--" marks the end of options and the beginning of positional arguments. } else if ( arg . startsWith ( "--" ) ) { parseLongOption ( arg , argsIter ) ; } else if ( arg . startsWith ( "-" ) ) { parseShortOptions ( arg , argsIter ) ; } else { builder . add ( arg ) ; // allow positional arguments to mix with options since many linux commands do } } for ( PendingInjection pi : pendingInjections ) { pi . injectableOption . inject ( pi . value , injectee ) ; } ImmutableList < String > leftovers = builder . addAll ( argsIter ) . build ( ) ; invokeMethod ( injectee , injectionMap . leftoversMethod , leftovers ) ; }
Parses the command - line arguments args setting the