public static List < String > parse ( final String [ ] args , final Object ... objs ) throws IOException { final List < String > ret = Colls . list ( ) ; final List < Arg > allArgs = Colls . list ( ) ; final HashMap < String , Arg > shortArgs = new HashMap < String , Arg > ( ) ; final HashMap < String , Arg > longArgs = new HashMap < String , Arg > ( ) ; parseArgs ( objs , allArgs , shortArgs , longArgs ) ; for ( int i = 0 ; i < args . length ; i ++ ) { final String s = args [ i ] ; final Arg a ; if ( s . startsWith ( "--" ) ) { a = longArgs . get ( s . substring ( 2 ) ) ; if ( a == null ) { throw new IOException ( "Unknown switch: " + s ) ; } } else if ( s . startsWith ( "-" ) ) { a = shortArgs . get ( s . substring ( 1 ) ) ; if ( a == null ) { throw new IOException ( "Unknown switch: " + s ) ; } } else { a = null ; ret . add ( s ) ; } if ( a != null ) { if ( a . isSwitch ) { a . setField ( "true" ) ; } else { if ( i + 1 >= args . length ) { System . out . println ( "Missing parameter for: " + s ) ; } if ( a . isCatchAll ( ) ) { final List < String > ca = Colls . list ( ) ; for ( ++ i ; i < args . length ; ++ i ) { ca . add ( args [ i ] ) ; } a . setCatchAll ( ca ) ; } else { ++ i ; a . setField ( args [ i ] ) ; } } a . setPresent ( ) ; } } for ( final Arg a : allArgs ) { if ( ! a . isOk ( ) ) { throw new IOException ( "Missing mandatory argument: " + a ) ; } } return ret ; }
Parses command line arguments .