Java Code Examples for org.apache.commons.cli.ParseException#getMessage()

The following examples show how to use org.apache.commons.cli.ParseException#getMessage() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void testNoInputPathOptionSpecified() throws Exception {
  RunJobCli runJobCli = new RunJobCli(getMockClientContext());
  String expectedErrorMessage = "\"--" + CliConstants.INPUT_PATH + "\"" +
      " is absent";
  String actualMessage = "";
  try {
    runJobCli.run(
        new String[]{"--framework", getFrameworkName(),
            "--name", "my-job", "--docker_image", "tf-docker:1.1.0",
            "--checkpoint_path", "hdfs://output",
            "--num_workers", "1", "--worker_launch_cmd", "python run-job.py",
            "--worker_resources", "memory=4g,vcores=2", "--verbose",
            "--wait_job_finish"});
  } catch (ParseException e) {
    actualMessage = e.getMessage();
    e.printStackTrace();
  }
  assertEquals(expectedErrorMessage, actualMessage);
}
 
Example 2
@Test
public void testJobWithoutName() throws Exception {
  RunJobCli runJobCli = new RunJobCli(getMockClientContext());
  String expectedErrorMessage =
      "--" + CliConstants.NAME + " is absent";
  String actualMessage = "";
  try {
    runJobCli.run(
        new String[]{"--framework", getFrameworkName(),
            "--docker_image", "tf-docker:1.1.0",
            "--num_workers", "0", "--verbose"});
  } catch (ParseException e) {
    actualMessage = e.getMessage();
    e.printStackTrace();
  }
  assertEquals(expectedErrorMessage, actualMessage);
}
 
Example 3
@Test
public void testNoInputPathOptionSpecified() throws Exception {
  RunJobCli runJobCli = new RunJobCli(RunJobCliParsingCommonTest.getMockClientContext());
  String expectedErrorMessage = "\"--" + CliConstants.INPUT_PATH +
      "\" is absent";
  String actualMessage = "";
  try {
    runJobCli.run(
        new String[]{"--framework", "tensorflow",
            "--name", "my-job", "--docker_image", "tf-docker:1.1.0",
            "--checkpoint_path", "hdfs://output",
            "--num_workers", "1", "--worker_launch_cmd", "python run-job.py",
            "--worker_resources", "memory=4g,vcores=2", "--tensorboard",
            "true", "--verbose", "--wait_job_finish"});
  } catch (ParseException e) {
    actualMessage = e.getMessage();
    e.printStackTrace();
  }
  assertEquals(expectedErrorMessage, actualMessage);
}
 
Example 4
Source Project: Flink-CEPplus   File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
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());
	}
}
 
Example 5
Source Project: Flink-CEPplus   File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
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());
	}
}
 
Example 6
Source Project: Flink-CEPplus   File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
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());
	}
}
 
Example 7
Source Project: flink   File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
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());
	}
}
 
Example 8
Source Project: flink   File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
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());
	}
}
 
Example 9
Source Project: flink   File: CliOptionsParser.java    License: Apache License 2.0 6 votes vote down vote up
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());
	}
}
 
Example 10
public static CliOptions parseClient(String[] args) {
    if (args.length < 1) {
        throw new RuntimeException("./sql-submit -w <work_space_dir> -f <sql-file>");
    }
    try {
        DefaultParser parser = new DefaultParser();
        CommandLine line = parser.parse(CLIENT_OPTIONS, args, true);
        return new CliOptions(
                line.getOptionValue(CliOptionsParser.OPTION_SQL_FILE.getOpt()),
                line.getOptionValue(CliOptionsParser.OPTION_WORKING_SPACE.getOpt())
        );
    }
    catch (ParseException e) {
        throw new RuntimeException(e.getMessage());
    }
}
 
Example 11
@Override
public void importTable(com.cloudera.sqoop.manager.ImportJobContext context)
    throws IOException, ImportException {
  context.setConnManager(this);
  // The user probably should have requested --direct to invoke external
  // table option.
  // Display a warning informing them of this fact.
  if (!NetezzaManager.directModeWarningPrinted) {
    LOG.warn("It looks like you are importing from Netezza.");
    LOG.warn("This transfer can be faster! Use the --direct");
    LOG.warn("option to exercise a Netezza-specific fast path.");

    NetezzaManager.directModeWarningPrinted = true; // don't display this
                                                    // twice.
  }
  try {
    handleNetezzaImportExtraArgs(context);
  } catch (ParseException pe) {
    throw (ImportException) new ImportException(pe.getMessage(), pe);
  }
  // Then run the normal importTable() method.
  super.importTable(context);
}
 
Example 12
Source Project: Flink-CEPplus   File: CliFrontendParser.java    License: Apache License 2.0 5 votes vote down vote up
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());
	}
}
 
Example 13
Source Project: Flink-CEPplus   File: CliFrontendParser.java    License: Apache License 2.0 5 votes vote down vote up
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());
	}
}
 
Example 14
Source Project: flink   File: CliFrontendParser.java    License: Apache License 2.0 5 votes vote down vote up
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());
	}
}
 
Example 15
Source Project: flink   File: CliFrontendParser.java    License: Apache License 2.0 5 votes vote down vote up
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());
	}
}
 
Example 16
public DirectNetezzaManager(SqoopOptions opts) {
  super(opts);
  try {
    handleNetezzaExtraArgs(options);
  } catch (ParseException pe) {
    throw  new RuntimeException(pe.getMessage(), pe);
  }
}
 
Example 17
public CommandLineFacade build(String[] args) {
    if(hasHelpOption(args)) {
        return new CommandLineFacade(options);
    }

    CommandLineParser parser = new DefaultParser();
    try {
        return new CommandLineFacade(options, parser.parse(options, args), defaults, hasHelpOption(args));
    } catch (ParseException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}
 
Example 18
Source Project: titus-control-plane   File: CLI.java    License: Apache License 2.0 5 votes vote down vote up
private CommandLine parseOptions(CliCommand cmd) {
    Options options = cmd.getOptions();
    appendDefaultOptions(options);
    if (cmd.isRemote()) {
        appendConnectivityOptions(options);
    }
    CommandLineParser parser = new DefaultParser();
    try {
        return parser.parse(options, args);
    } catch (ParseException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}
 
Example 19
private CommandLine parseOptions(String[] args, Options options) {
    CommandLineParser parser = new DefaultParser();
    CommandLine cli;
    try {
        cli = parser.parse(options, args, true);
    } catch (ParseException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
    if (cli.getArgList().size() > 0) {
        throw new IllegalArgumentException("Too many command line arguments: " + cli.getArgList());
    }
    return cli;
}
 
Example 20
Source Project: hadoop   File: JMXGet.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * parse args
 */
private static CommandLine parseArgs(Options opts, String... args)
throws IllegalArgumentException {

  OptionBuilder.withArgName("NameNode|DataNode");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("specify jmx service (NameNode by default)");
  Option jmx_service = OptionBuilder.create("service");

  OptionBuilder.withArgName("mbean server");
  OptionBuilder.hasArg();
  OptionBuilder
  .withDescription("specify mbean server (localhost by default)");
  Option jmx_server = OptionBuilder.create("server");

  OptionBuilder.withDescription("print help");
  Option jmx_help = OptionBuilder.create("help");

  OptionBuilder.withArgName("mbean server port");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("specify mbean server port, "
      + "if missing - it will try to connect to MBean Server in the same VM");
  Option jmx_port = OptionBuilder.create("port");

  OptionBuilder.withArgName("VM's connector url");
  OptionBuilder.hasArg();
  OptionBuilder.withDescription("connect to the VM on the same machine;"
      + "\n use:\n jstat -J-Djstat.showUnsupported=true -snap <vmpid> | "
      + "grep sun.management.JMXConnectorServer.address\n "
      + "to find the url");
  Option jmx_localVM = OptionBuilder.create("localVM");

  opts.addOption(jmx_server);
  opts.addOption(jmx_help);
  opts.addOption(jmx_service);
  opts.addOption(jmx_port);
  opts.addOption(jmx_localVM);

  CommandLine commandLine = null;
  CommandLineParser parser = new GnuParser();
  try {
    commandLine = parser.parse(opts, args, true);
  } catch (ParseException e) {
    printUsage(opts);
    throw new IllegalArgumentException("invalid args: " + e.getMessage());
  }
  return commandLine;
}