org.apache.commons.cli.ParseException#getMessage ( )源码实例Demo

下面列出了org.apache.commons.cli.ParseException#getMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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);
}
 
@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);
}
 
@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);
}
 
源代码4 项目: Flink-CEPplus   文件: CliOptionsParser.java
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());
	}
}
 
源代码5 项目: Flink-CEPplus   文件: CliOptionsParser.java
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());
	}
}
 
源代码6 项目: Flink-CEPplus   文件: CliOptionsParser.java
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());
	}
}
 
源代码7 项目: flink   文件: CliOptionsParser.java
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());
	}
}
 
源代码8 项目: flink   文件: CliOptionsParser.java
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());
	}
}
 
源代码9 项目: flink   文件: CliOptionsParser.java
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());
	}
}
 
源代码10 项目: flink-sql-submit   文件: CliOptionsParser.java
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());
    }
}
 
@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);
}
 
源代码12 项目: Flink-CEPplus   文件: CliFrontendParser.java
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());
	}
}
 
源代码13 项目: Flink-CEPplus   文件: CliFrontendParser.java
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());
	}
}
 
源代码14 项目: flink   文件: CliFrontendParser.java
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());
	}
}
 
源代码15 项目: flink   文件: CliFrontendParser.java
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 DirectNetezzaManager(SqoopOptions opts) {
  super(opts);
  try {
    handleNetezzaExtraArgs(options);
  } catch (ParseException pe) {
    throw  new RuntimeException(pe.getMessage(), pe);
  }
}
 
源代码17 项目: titus-control-plane   文件: CommandLineBuilder.java
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());
    }
}
 
源代码18 项目: titus-control-plane   文件: CLI.java
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());
    }
}
 
源代码19 项目: titus-control-plane   文件: AbstractCassTool.java
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;
}
 
源代码20 项目: hadoop   文件: JMXGet.java
/**
 * 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;
}