public < O extends BaseOption > ArgumentParser add ( O option ) { if ( option . getName ( ) != null ) { if ( longNameOptions . containsKey ( option . getName ( ) ) ) { throw new IllegalArgumentException ( "Option " + option . getName ( ) + " already exists" ) ; } if ( parent != null && parent . longNameOptions . containsKey ( option . getName ( ) ) ) { throw new IllegalArgumentException ( "Option " + option . getName ( ) + " already exists in parent" ) ; } longNameOptions . put ( option . getName ( ) , option ) ; } if ( option instanceof Flag ) { String negate = ( ( Flag ) option ) . getNegateName ( ) ; if ( negate != null ) { if ( longNameOptions . containsKey ( negate ) ) { throw new IllegalArgumentException ( "Flag " + negate + " already exists" ) ; } if ( parent != null && parent . longNameOptions . containsKey ( negate ) ) { throw new IllegalArgumentException ( "Flag " + negate + " already exists in parent" ) ; } longNameOptions . put ( negate , option ) ; } } if ( option . getShortNames ( ) . length ( ) > 0 ) { for ( char s : option . getShortNames ( ) . toCharArray ( ) ) { if ( shortOptions . containsKey ( s ) ) { throw new IllegalArgumentException ( "Short option -" + s + " already exists" ) ; } if ( parent != null && parent . shortOptions . containsKey ( s ) ) { throw new IllegalArgumentException ( "Short option -" + s + " already exists in parent" ) ; } shortOptions . put ( s , option ) ; } } this . options . add ( option ) ; return this ; }
Add a command line option .