public Settings parse ( String [ ] arguments ) throws CommandLineException { Settings out = new Settings ( ) ; if ( arguments != null ) { // each argument is either a option or a option value CommandOption option = null ; for ( String argument : arguments ) { if ( isOption ( argument ) ) { // is this an option or an argument ... ? option = findOption ( argument ) ; if ( option != null && ! option . hasArguments ( ) ) { // this is a no arg option ... add it to list (we might override this in the next step) out . put ( option . getSetting ( ) , option . parse ( argument ) ) ; } continue ; } if ( option == null ) { throw new CommandLineException ( "Unknown command line option: " + argument ) ; } Object value = option . parse ( argument ) ; out . put ( option . getSetting ( ) , value ) ; } } // check if ConfigFileOption is provided and given CommandOption config = builder . getConfigFileOption ( ) ; // create copy of builder to override defaults if needed CommandBuilder defaults = new CommandBuilder ( builder . get ( ) ) ; if ( config != null ) { String file = ( String ) out . get ( config . getSetting ( ) ) ; // is provided? if ( file != null ) { ConfigFileReader reader = new ConfigFileReader ( ) ; Settings configSettings = reader . load ( file , builder ) ; // override default with read config defaults . setDefaults ( configSettings ) ; // remove config setting from output out . remove ( config . getSetting ( ) ) ; } } // add default options if any for ( CommandOption option : defaults . get ( ) ) { if ( ! ( option instanceof ConfigFileOption ) && ! out . containsKey ( option . getSetting ( ) ) ) { out . put ( option . getSetting ( ) , option . getDefault ( ) ) ; } } return out ; }
Returns HashMap of read out settings