public CommandLine parse(Options options, String[] arguments) throws ParseException { return parse(options, arguments, null); }
public CommandLine parse(Options options, String[] arguments, boolean stopAtNonOption) throws ParseException { return parse(options, arguments, null, stopAtNonOption); }
/** * Parse the arguments according to the specified options and properties. * * @param options the specified Options * @param arguments the command line arguments * @param properties command line option name-value pairs * @return the list of atomic option and value tokens * * @throws ParseException if there are any problems encountered * while parsing the command line tokens. */ public CommandLine parse(Options options, String[] arguments, Properties properties) throws ParseException { return parse(options, arguments, properties, false); }
public static CommandLine parse(Options options, String[] args, boolean stopAtNonOptions) throws CliArgsException { final DefaultParser parser = new DefaultParser(); try { return parser.parse(options, args, stopAtNonOptions); } catch (ParseException e) { throw new CliArgsException(e.getMessage()); } }
public static RunOptions parseRunCommand(String[] args) throws CliArgsException { try { DefaultParser parser = new DefaultParser(); CommandLine line = parser.parse(RUN_OPTIONS, args, true); return new RunOptions(line); } catch (ParseException e) { throw new CliArgsException(e.getMessage()); } }
/** * Parse command line options/flags and arguments. */ public CommandLine parseCommandLine(String[] args) throws ParseException { addOptions(); cmd = new DefaultParser().parse(this.options, args); return cmd; }
private static CommandLine parseArgs(String[] args) throws ParseException { initOptions(CLI_OPTIONS); return new DefaultParser().parse(CLI_OPTIONS, args); }
private void initCmdLineOptions(final String[] args) { this.options = buildExpectedOptions(); try { this.cmd = new DefaultParser().parse(this.options, args); } catch (final ParseException e) { logger.error("failed to parse command options.", e); printUsage(this.options); throw new GobblinClusterException("Failed to parse command line options", e); } }
public static CliOptions parseGatewayModeGateway(String[] args) { try { DefaultParser parser = new DefaultParser(); CommandLine line = parser.parse(GATEWAY_MODE_GATEWAY_OPTIONS, args, true); return new CliOptions( line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()), null, null, checkUrl(line, CliOptionsParser.OPTION_DEFAULTS), checkUrls(line, CliOptionsParser.OPTION_JAR), checkUrls(line, CliOptionsParser.OPTION_LIBRARY), null ); } catch (ParseException e) { throw new SqlClientException(e.getMessage()); } }
public static CliOptions parseGatewayModeClient(String[] args) { try { DefaultParser parser = new DefaultParser(); CommandLine line = parser.parse(GATEWAY_MODE_CLIENT_OPTIONS, args, true); return new CliOptions( line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()), checkSessionId(line), checkUrl(line, CliOptionsParser.OPTION_ENVIRONMENT), null, checkUrls(line, CliOptionsParser.OPTION_JAR), checkUrls(line, CliOptionsParser.OPTION_LIBRARY), line.getOptionValue(CliOptionsParser.OPTION_UPDATE.getOpt()) ); } catch (ParseException e) { throw new SqlClientException(e.getMessage()); } }
public static CliOptions parseEmbeddedModeClient(String[] args) { try { DefaultParser parser = new DefaultParser(); CommandLine line = parser.parse(EMBEDDED_MODE_CLIENT_OPTIONS, args, true); return new CliOptions( line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()), checkSessionId(line), checkUrl(line, CliOptionsParser.OPTION_ENVIRONMENT), checkUrl(line, CliOptionsParser.OPTION_DEFAULTS), checkUrls(line, CliOptionsParser.OPTION_JAR), checkUrls(line, CliOptionsParser.OPTION_LIBRARY), line.getOptionValue(CliOptionsParser.OPTION_UPDATE.getOpt()) ); } catch (ParseException e) { throw new SqlClientException(e.getMessage()); } }
@SuppressWarnings("deprecation") private CommandLine parse(CommandLineParser parser, Options opts, String[] args, Properties properties) throws ParseException { if (parser instanceof Parser) { return ((Parser) parser).parse(opts, args, properties); } else if (parser instanceof DefaultParser) { return ((DefaultParser) parser).parse(opts, args, properties); } else { throw new UnsupportedOperationException("Default options not supported by this parser"); } }
/** * Parse command line arguments and return a {@link java.util.Properties} object for the gobblin job found. * @param caller Class of the calling main method. Used for error logs. * @param args Command line arguments. * @return Instance of {@link Properties} for the Gobblin job to run. * @throws IOException */ public static Properties parseArgs(Class<?> caller, String[] args) throws IOException { try { // Parse command-line options CommandLine cmd = new DefaultParser().parse(options(), args); if (cmd.hasOption(HELP_OPTION.getOpt())) { printUsage(caller); System.exit(0); } if (!cmd.hasOption(SYS_CONFIG_OPTION.getLongOpt()) || !cmd.hasOption(JOB_CONFIG_OPTION.getLongOpt())) { printUsage(caller); System.exit(1); } // Load system and job configuration properties Properties sysConfig = JobConfigurationUtils.fileToProperties(cmd.getOptionValue(SYS_CONFIG_OPTION.getLongOpt())); Properties jobConfig = JobConfigurationUtils.fileToProperties(cmd.getOptionValue(JOB_CONFIG_OPTION.getLongOpt())); return JobConfigurationUtils.combineSysAndJobProperties(sysConfig, jobConfig); } catch (ParseException | ConfigurationException e) { throw new IOException(e); } }
public static void main(String[] args) throws Exception { Options options = buildOptions(); try { CommandLine cmd = new DefaultParser().parse(options, args); if (!cmd.hasOption(GobblinClusterConfigurationKeys.APPLICATION_NAME_OPTION_NAME)) { printUsage(options); System.exit(1); } Log4jConfigurationHelper.updateLog4jConfiguration(GobblinApplicationMaster.class, GobblinYarnConfigurationKeys.GOBBLIN_YARN_LOG4J_CONFIGURATION_FILE, GobblinYarnConfigurationKeys.GOBBLIN_YARN_LOG4J_CONFIGURATION_FILE); LOGGER.info(JvmUtils.getJvmInputArguments()); ContainerId containerId = ConverterUtils.toContainerId(System.getenv().get(ApplicationConstants.Environment.CONTAINER_ID.key())); try (GobblinApplicationMaster applicationMaster = new GobblinApplicationMaster( cmd.getOptionValue(GobblinClusterConfigurationKeys.APPLICATION_NAME_OPTION_NAME), containerId, ConfigFactory.load(), new YarnConfiguration())) { applicationMaster.start(); } } catch (ParseException pe) { printUsage(options); System.exit(1); } } }
@Test(expected = AmbiguousOptionException.class) public void testAmbiquousOptionName() throws ParseException { new DefaultParser().parse(getOptions(), new String[]{"--pref"}); }
@Test public void testExactOptionNameMatch() throws ParseException { new DefaultParser().parse(getOptions(), new String[]{"--prefix"}); }
@Test public void shouldParseShortOptionWithValue() throws Exception { String[] shortOptionWithValue = new String[]{"-t1", "path/to/my/db"}; final CommandLine commandLine = parser.parse(options, shortOptionWithValue); assertEquals("path/to/my/db", commandLine.getOptionValue("t1")); assertFalse(commandLine.hasOption("last")); }
@Test public void shouldParseShortOptionWithoutValue() throws Exception { String[] twoShortOptions = new String[]{"-t1", "-last"}; final CommandLine commandLine = parser.parse(options, twoShortOptions); assertTrue(commandLine.hasOption("t1")); assertNotEquals("Second option has been used as value for first option", "-last", commandLine.getOptionValue("t1")); assertTrue("Second option has not been detected", commandLine.hasOption("last")); }
@Test public void shouldParseConcatenatedShortOptions() throws Exception { String[] concatenatedShortOptions = new String[] { "-t1", "-ab" }; final CommandLine commandLine = parser.parse(options, concatenatedShortOptions); assertTrue(commandLine.hasOption("t1")); assertNull(commandLine.getOptionValue("t1")); assertTrue(commandLine.hasOption("a")); assertTrue(commandLine.hasOption("b")); assertFalse(commandLine.hasOption("last")); } }
@Override public void execute(Cli.GlobalOptions globalOptions, String[] otherArgs) { this.options = createCommandLineOptions(); DefaultParser parser = new DefaultParser(); AdminClient adminClient = null; try { CommandLine parsedOpts = parser.parse(options, otherArgs); int resultLimit = parseResultsLimit(parsedOpts); adminClient = new AdminClient(globalOptions.getAdminServerHost(), globalOptions.getAdminServerPort()); try { getAction(parsedOpts).execute(parsedOpts, adminClient, resultLimit); } catch (CommandException e) { printHelpAndExit(e.getMessage()); } } catch (ParseException e) { printHelpAndExit("Failed to parse jobs arguments: " + e.getMessage()); } finally { if (adminClient != null) adminClient.close(); } }