public static CommandLine processCommandLineArgs ( Option [ ] customOptions , String [ ] args ) { Options options = new Options ( ) ; options . addOption ( "h" , "help" , false , "Print this message" ) ; options . addOption ( "v" , "verbose" , false , "Generate verbose log messages" ) ; if ( customOptions != null ) { for ( int i = 0 ; i < customOptions . length ; i ++ ) options . addOption ( customOptions [ i ] ) ; } CommandLine cli = null ; try { cli = ( new GnuParser ( ) ) . parse ( options , args ) ; } catch ( ParseException exp ) { boolean hasHelpArg = false ; if ( args != null && args . length > 0 ) { for ( int z = 0 ; z < args . length ; z ++ ) { if ( "-h" . equals ( args [ z ] ) || "-help" . equals ( args [ z ] ) ) { hasHelpArg = true ; break ; } } } if ( ! hasHelpArg ) { System . err . println ( "Failed to parse command-line arguments due to: " + exp . getMessage ( ) ) ; } HelpFormatter formatter = new HelpFormatter ( ) ; formatter . printHelp ( SparkApp . class . getName ( ) , options ) ; System . exit ( 1 ) ; } if ( cli . hasOption ( "help" ) ) { HelpFormatter formatter = new HelpFormatter ( ) ; formatter . printHelp ( SparkApp . class . getName ( ) , options ) ; System . exit ( 0 ) ; } return cli ; }
Parses the command - line arguments passed by the user .