org.apache.commons.cli.ParseException Java Examples

The following examples show how to use org.apache.commons.cli.ParseException. 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
Source File: RunJobCliParsingTensorFlowTest.java    From submarine with Apache License 2.0 6 votes vote down vote up
/**
 * when only run tensorboard, input_path is not needed
 * */
@Test
public void testNoInputPathOptionButOnlyRunTensorboard() throws Exception {
  RunJobCli runJobCli = new RunJobCli(RunJobCliParsingCommonTest.getMockClientContext());
  boolean success = true;
  try {
    runJobCli.run(
        new String[]{"--framework", "tensorflow",
            "--name", "my-job", "--docker_image", "tf-docker:1.1.0",
            "--num_workers", "0", "--tensorboard", "--verbose",
            "--tensorboard_resources", "memory=2G,vcores=2",
            "--tensorboard_docker_image", "tb_docker_image:001"});
  } catch (ParseException e) {
    success = false;
  }
  assertTrue(success);
}
 
Example #2
Source File: SerialScoreParameters.java    From metadata-qa-marc with GNU General Public License v3.0 6 votes vote down vote up
public SerialScoreParameters(String[] arguments) throws ParseException {
  super(arguments);

  if (cmd.hasOption("fileName"))
    fileName = cmd.getOptionValue("fileName");

  if (fileName.equals("stdout"))
    useStandardOutput = true;

  if (cmd.hasOption("limit"))
    limit = Integer.parseInt(cmd.getOptionValue("limit"));

  if (cmd.hasOption("offset"))
    offset = Integer.parseInt(cmd.getOptionValue("offset"));

  if (offset > -1 && limit > -1)
    limit += offset;
}
 
Example #3
Source File: RunParameters.java    From submarine with Apache License 2.0 6 votes vote down vote up
@Override
public void updateParameters(Parameter parametersHolder, ClientContext clientContext)
  throws ParseException,
    IOException, YarnException {
  String savedModelPath = parametersHolder.getOptionValue(
      CliConstants.SAVED_MODEL_PATH);
  this.setSavedModelPath(savedModelPath);

  List<String> envVars = getEnvVars((ParametersHolder)parametersHolder);
  this.setEnvars(envVars);

  String queue = parametersHolder.getOptionValue(
      CliConstants.QUEUE);
  this.setQueue(queue);

  String dockerImage = parametersHolder.getOptionValue(
      CliConstants.DOCKER_IMAGE);
  this.setDockerImageName(dockerImage);

  super.updateParameters(parametersHolder, clientContext);
}
 
Example #4
Source File: ReplicaStatsRetriever.java    From doctorkafka with Apache License 2.0 6 votes vote down vote up
/**
 *  Usage:  ReplicaStatsRetriever  \
 *             -brokerstatszk    datazk001:2181/data07    \
 *             -brokerstatstopic brokerstats              \
 *             -clusterzk  m10nzk001:2181,...,m10nzk007:2181/m10n07 \
 *             -seconds 43200
 */
private static CommandLine parseCommandLine(String[] args) {
  Option config = new Option(CONFIG, true, "operator config");
  Option brokerStatsZookeeper =
      new Option(BROKERSTATS_ZOOKEEPER, true, "zookeeper for brokerstats topic");
  Option brokerStatsTopic = new Option(BROKERSTATS_TOPIC, true, "topic for brokerstats");
  Option clusterZookeeper = new Option(CLUSTER_ZOOKEEPER, true, "cluster zookeeper");
  Option seconds = new Option(SECONDS, true, "examined time window in seconds");
  options.addOption(config).addOption(brokerStatsZookeeper).addOption(brokerStatsTopic)
      .addOption(clusterZookeeper).addOption(seconds);

  if (args.length < 6) {
    printUsageAndExit();
  }

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, args);
  } catch (ParseException | NumberFormatException e) {
    printUsageAndExit();
  }
  return cmd;
}
 
Example #5
Source File: BaseCommandLine.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
protected CommandLine doParse(String[] args) throws CommandLineParseException {
    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption(HELP_ARG)) {
            return printUsageAndThrow(null, ExitCode.HELP);
        }
        certificateAuthorityHostname = commandLine.getOptionValue(CERTIFICATE_AUTHORITY_HOSTNAME_ARG, TlsConfig.DEFAULT_HOSTNAME);
        days = getIntValue(commandLine, DAYS_ARG, TlsConfig.DEFAULT_DAYS);
        keySize = getIntValue(commandLine, KEY_SIZE_ARG, TlsConfig.DEFAULT_KEY_SIZE);
        keyAlgorithm = commandLine.getOptionValue(KEY_ALGORITHM_ARG, TlsConfig.DEFAULT_KEY_PAIR_ALGORITHM);
        keyStoreType = commandLine.getOptionValue(KEY_STORE_TYPE_ARG, getKeyStoreTypeDefault());
        if (KeystoreType.PKCS12.toString().equalsIgnoreCase(keyStoreType)) {
            logger.info("Command line argument --" + KEY_STORE_TYPE_ARG + "=" + keyStoreType + " only applies to keystore, recommended truststore type of " + KeystoreType.JKS.toString() +
                    " unaffected.");
        }
        signingAlgorithm = commandLine.getOptionValue(SIGNING_ALGORITHM_ARG, TlsConfig.DEFAULT_SIGNING_ALGORITHM);
        differentPasswordForKeyAndKeystore = commandLine.hasOption(DIFFERENT_KEY_AND_KEYSTORE_PASSWORDS_ARG);
    } catch (ParseException e) {
        return printUsageAndThrow("Error parsing command line. (" + e.getMessage() + ")", ExitCode.ERROR_PARSING_COMMAND_LINE);
    }
    return commandLine;
}
 
Example #6
Source File: ServerUtil.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public static CommandLine parseCmdLine(final String appName, String[] args, Options options,
    CommandLineParser parser) {
    HelpFormatter hf = new HelpFormatter();
    hf.setWidth(110);
    CommandLine commandLine = null;
    try {
        commandLine = parser.parse(options, args);
        if (commandLine.hasOption('h')) {
            hf.printHelp(appName, options, true);
            return null;
        }
    } catch (ParseException e) {
        hf.printHelp(appName, options, true);
    }

    return commandLine;
}
 
Example #7
Source File: LoadModel.java    From djl with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException, ModelException, TranslateException {
    Options options = Arguments.getOptions();
    try {
        DefaultParser parser = new DefaultParser();
        CommandLine cmd = parser.parse(options, args, null, false);
        Arguments arguments = new Arguments(cmd);

        Classifications classifications = predict(arguments);
        logger.info("{}", classifications);
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.setLeftPadding(1);
        formatter.setWidth(120);
        formatter.printHelp(e.getMessage(), options);
    }
}
 
Example #8
Source File: ValidatorParametersTest.java    From metadata-qa-marc with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDefaults() {
  String[] arguments = new String[]{"a-marc-file.mrc"};
  try {
    ValidatorParameters parameters = new ValidatorParameters(arguments);

    assertNotNull(parameters.getArgs());
    assertEquals(1, parameters.getArgs().length);
    assertEquals("a-marc-file.mrc", parameters.getArgs()[0]);

    assertFalse(parameters.doHelp());

    assertNotNull(parameters.getDetailsFileName());
    assertEquals("validation-report.txt", parameters.getDetailsFileName());
    assertFalse(parameters.useStandardOutput());

    assertEquals(-1, parameters.getLimit());
    assertEquals(-1, parameters.getOffset());

    assertFalse(parameters.doSummary());

    assertEquals(ValidationErrorFormat.TEXT, parameters.getFormat());
  } catch (ParseException e) {
    e.printStackTrace();
  }
}
 
Example #9
Source File: MappingParameters.java    From metadata-qa-marc with GNU General Public License v3.0 6 votes vote down vote up
public MappingParameters(String[] arguments) throws ParseException {
  cmd = parser.parse(getOptions(), arguments);

  if (cmd.hasOption("withSubfieldCodelists"))
    exportSubfieldCodes = true;

  if (cmd.hasOption("withSelfDescriptiveCode"))
    exportSelfDescriptiveCodes = true;

  if (cmd.hasOption("solrFieldType"))
    solrFieldType = SolrFieldType.byCode(cmd.getOptionValue("solrFieldType"));

  if (cmd.hasOption("withFrbrFunctions"))
    exportFrbrFunctions = true;

  if (cmd.hasOption("withCompilanceLevel"))
    exportCompilanceLevel = true;
}
 
Example #10
Source File: RunJobCliParsingTensorFlowTest.java    From submarine with Apache License 2.0 6 votes vote down vote up
@Test
public void testSchedulerDockerImageCannotBeDefined() throws Exception {
  RunJobCli runJobCli = new RunJobCli(RunJobCliParsingCommonTest.getMockClientContext());
  assertFalse(SubmarineLogs.isVerbose());

  expectedException.expect(ParseException.class);
  expectedException.expectMessage("cannot be defined for TensorFlow jobs");
  runJobCli.run(
      new String[] {"--framework", "tensorflow",
          "--name", "my-job", "--docker_image", "tf-docker:1.1.0",
          "--input_path", "hdfs://input", "--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",
          "--scheduler_docker_image", "schedulerDockerImage"});
}
 
Example #11
Source File: LibScoutConfig.java    From LibScout with Apache License 2.0 6 votes vote down vote up
private static void parseConfig(String key, Object value) throws ParseException {
    try {
        //logger.debug("Parse config key : " + key + "   value: " + value);

        if ("logging.log4j_config_file".equals(key)) {
            File f = checkIfValidFile((String) value);
            log4jConfigFileName = f.getAbsolutePath();

        } else if ("sdk.android_sdk_jar".equals(key)) {
            if (pathToAndroidJar == null)  // CLI takes precedence
                pathToAndroidJar = checkIfValidFile((String) value);

        } else if ("packageTree.ascii_rendering".equals(key)) {
            PckgTree.useAsciiRendering = (Boolean) value;

        } else if ("reporting.show_comments".equals(key)) {
            Reporting.showComments = (Boolean) value;

        } else
            logger.warn("Found unknown config key: " + key);

    } catch (ParseException e) {
       throw new ParseException("Could not parse config option " + key + " : " + e.getMessage());
    }
}
 
Example #12
Source File: CommandLineArguments.java    From zserio with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void readArguments() throws ParseException
{
    String[] arguments = parsedCommandLine.getArgs();
    if (arguments.length > 1)
    {
        // more than one unparsed argument (input file name) is always an error
        throw new ParseException("Unknown argument " + arguments[1]);
    }
    else if (arguments.length == 1)
    {
        // normalize slashes and backslashes
        inputFileName = new File(arguments[0]).getPath();
    }
    else
    {
        // don't fail yet - file name is not required for -h or -v
        inputFileName = null;
    }
}
 
Example #13
Source File: BootstrapMavenOptionsParser.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public static Map<String, Object> parse(String[] args) {
    final CommandLine cmdLine;
    try {
        cmdLine = new CLIManager().parse(args);
    } catch (ParseException e) {
        throw new IllegalStateException("Failed to parse Maven command line arguments", e);
    }

    final Map<String, Object> map = new HashMap<>();
    put(cmdLine, map, CLIManager.ALTERNATE_USER_SETTINGS);
    put(cmdLine, map, CLIManager.ALTERNATE_GLOBAL_SETTINGS);
    put(cmdLine, map, CLIManager.ALTERNATE_POM_FILE);
    put(map, String.valueOf(CLIManager.ACTIVATE_PROFILES), cmdLine.getOptionValues(CLIManager.ACTIVATE_PROFILES));

    putBoolean(cmdLine, map, CLIManager.OFFLINE);
    putBoolean(cmdLine, map, CLIManager.SUPRESS_SNAPSHOT_UPDATES);
    putBoolean(cmdLine, map, CLIManager.UPDATE_SNAPSHOTS);
    putBoolean(cmdLine, map, CLIManager.CHECKSUM_FAILURE_POLICY);
    putBoolean(cmdLine, map, CLIManager.CHECKSUM_WARNING_POLICY);

    return map;
}
 
Example #14
Source File: MarcToSolrParametersTest.java    From metadata-qa-marc with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDefaults() {
  String[] arguments = new String[]{"a-marc-file.mrc"};
  try {
    MarcToSolrParameters parameters = new MarcToSolrParameters(arguments);

    assertNotNull(parameters.getArgs());
    assertEquals(1, parameters.getArgs().length);
    assertEquals("a-marc-file.mrc", parameters.getArgs()[0]);

    assertFalse(parameters.doHelp());

    assertNull(parameters.getSolrUrl());
    assertFalse(parameters.doCommit());
    assertNotNull(parameters.getSolrFieldType());
    assertEquals(SolrFieldType.MARC, parameters.getSolrFieldType());
  } catch (ParseException e) {
    e.printStackTrace();
  }
}
 
Example #15
Source File: RunJobCliParsingPyTorchTest.java    From submarine with Apache License 2.0 6 votes vote down vote up
@Test
public void testTensorboardDockerImageCannotBeDefined() throws Exception {
  RunJobCli runJobCli = new RunJobCli(RunJobCliParsingCommonTest.getMockClientContext());
  assertFalse(SubmarineLogs.isVerbose());

  expectedException.expect(ParseException.class);
  expectedException.expectMessage("cannot be defined for PyTorch jobs");
  runJobCli.run(
      new String[]{"--framework", "pytorch",
          "--name", "my-job", "--docker_image", "tf-docker:1.1.0",
          "--input_path", "hdfs://input",
          "--checkpoint_path", "hdfs://output",
          "--num_workers", "3",
          "--worker_launch_cmd",
          "python run-job.py", "--worker_resources", "memory=2048M,vcores=2",
          "--tensorboard_docker_image", "TBDockerImage"});
}
 
Example #16
Source File: AmazonMqClient.java    From amazon-mq-workshop with Apache License 2.0 6 votes vote down vote up
private static CommandLine parseAndValidateCommandLineArguments(String[] args) throws ParseException {
    Options options = new Options();
    options.addOption("help", false, "Print the help message.");
    options.addOption("url", true, "The broker connection url.");
    options.addOption("user", true, "The user to connect to the broker.");
    options.addOption("password", true, "The password for the user.");
    options.addOption("mode", true, "Whether to act as 'sender' or 'receiver'");
    options.addOption("type", true, "Whether to use a queue or a topic.");
    options.addOption("destination", true, "The name of the queue or topic");
    options.addOption("name", true, "The name of the sender");
    options.addOption("interval", true, "The interval in msec at which messages are generated. Default 1000");
    options.addOption("notPersistent", false, "Send messages in non-persistent mode");
    options.addOption("ttl", true, "The time to live value for the message.");
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);

    if (cmd.hasOption("help")) {
        printUsage(options);
    }

    if (!(cmd.hasOption("url") && cmd.hasOption("type") && cmd.hasOption("mode") && cmd.hasOption("destination"))) {
        printUsage(options);
    }

    return cmd;
}
 
Example #17
Source File: RunJobCliParsingPyTorchTest.java    From submarine with Apache License 2.0 6 votes vote down vote up
@Test
public void testPSResourcesCannotBeDefined() throws Exception {
  RunJobCli runJobCli = new RunJobCli(RunJobCliParsingCommonTest.getMockClientContext());
  assertFalse(SubmarineLogs.isVerbose());

  expectedException.expect(ParseException.class);
  expectedException.expectMessage("cannot be defined for PyTorch jobs");
  runJobCli.run(
      new String[]{"--framework", "pytorch",
          "--name", "my-job", "--docker_image", "tf-docker:1.1.0",
          "--input_path", "hdfs://input",
          "--checkpoint_path", "hdfs://output",
          "--num_workers", "3",
          "--worker_launch_cmd",
          "python run-job.py", "--worker_resources", "memory=2048M,vcores=2",
          "--ps_resources", "memory=2048M,vcores=2"});
}
 
Example #18
Source File: RunJobCliParsingPyTorchTest.java    From submarine with Apache License 2.0 6 votes vote down vote up
@Test
public void testNumPSCannotBeDefined() throws Exception {
  RunJobCli runJobCli = new RunJobCli(RunJobCliParsingCommonTest.getMockClientContext());
  assertFalse(SubmarineLogs.isVerbose());

  expectedException.expect(ParseException.class);
  expectedException.expectMessage("cannot be defined for PyTorch jobs");
  runJobCli.run(
      new String[]{"--framework", "pytorch",
          "--name", "my-job", "--docker_image", "tf-docker:1.1.0",
          "--input_path", "hdfs://input",
          "--checkpoint_path", "hdfs://output",
          "--num_workers", "3",
          "--worker_launch_cmd",
          "python run-job.py", "--worker_resources", "memory=2048M,vcores=2",
          "--num_ps", "2"});
}
 
Example #19
Source File: RunJobCli.java    From submarine with Apache License 2.0 6 votes vote down vote up
@Override
public int run(String[] args)
    throws ParseException, IOException, YarnException, SubmarineException {
  if (CliUtils.argsForHelp(args)) {
    printUsages();
    return 0;
  }

  parseCommandLineAndGetRunJobParameters(args);
  ApplicationId applicationId = jobSubmitter.submitJob(parametersHolder);
  LOG.info("Submarine job is submitted, the job id is " + applicationId);
  RunJobParameters parameters =
      (RunJobParameters) parametersHolder.getParameters();
  storeJobInformation(parameters, applicationId, args);
  if (parameters.isWaitJobFinish()) {
    this.jobMonitor.waitTrainingFinal(parameters.getName());
  }

  return 0;
}
 
Example #20
Source File: RunJobCliParsingParameterizedTest.java    From submarine with Apache License 2.0 6 votes vote down vote up
@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 #21
Source File: ZserioTool.java    From zserio with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void execute(String[] args) throws Exception
{
    commandLineArguments.parse(args);
    if (commandLineArguments.hasHelpOption())
    {
        commandLineArguments.printHelp();
        extensionManager.printExtensions();
    }
    else if (commandLineArguments.hasVersionOption())
    {
        ZserioToolPrinter.printMessage("version " + ZserioVersion.VERSION_STRING);
    }
    else if (commandLineArguments.getInputFileName() == null)
    {
        throw new ParseException("Missing input file name!");
    }
    else
    {
        process();
    }
}
 
Example #22
Source File: URPChecker.java    From doctorkafka with Apache License 2.0 6 votes vote down vote up
/**
 *  Usage:  URPChecker  \
 *             -brokerstatszk    datazk001:2181/data07    \
 *             -brokerstatstopic brokerstats              \
 *             -clusterzk  m10nzk001:2181,...,m10nzk007:2181/m10n07
 */
private static CommandLine parseCommandLine(String[] args) {
  Option zookeeper = new Option(ZOOKEEPER, true, "cluster zookeeper");
  options.addOption(zookeeper);

  if (args.length < 2) {
    printUsageAndExit();
  }

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = null;
  try {
    cmd = parser.parse(options, args);
  } catch (ParseException | NumberFormatException e) {
    printUsageAndExit();
  }
  return cmd;
}
 
Example #23
Source File: CliOptionsParser.java    From Flink-CEPplus with 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 #24
Source File: RelaxedParser.java    From apimanager-swagger-promote with Apache License 2.0 5 votes vote down vote up
@Override
public CommandLine parse(Options options, String[] arguments) throws ParseException {
    List<String> knownArguments = new ArrayList<>();
    boolean addOptionValue = false;
    for (String arg : arguments) {
        if (options.hasOption(arg) || addOptionValue) {
            knownArguments.add(arg);
            addOptionValue = (addOptionValue) ? false : true;
        }
    }
    return super.parse(options, knownArguments.toArray(new String[knownArguments.size()]));
}
 
Example #25
Source File: LinkageCheckerArgumentsTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadCommandLine_jarFileList_absolutePath() throws ParseException, IOException {
  LinkageCheckerArguments parsedArguments =
      LinkageCheckerArguments.readCommandLine(
          "-j", "/foo/bar/A.jar,/foo/bar/B.jar,/foo/bar/C.jar");

  Truth.assertThat(parsedArguments.getJarFiles())
      .comparingElementsUsing(
          Correspondence.transforming(ClassPathEntry::getJar, "has path equals to"))
      // Using Path::toString to work in Windows
      .containsExactly(
          Paths.get("/foo/bar/A.jar").toAbsolutePath(),
          Paths.get("/foo/bar/B.jar").toAbsolutePath(),
          Paths.get("/foo/bar/C.jar").toAbsolutePath());
}
 
Example #26
Source File: RdmaConstants.java    From incubator-crail with Apache License 2.0 5 votes vote down vote up
public static void init(CrailConfiguration conf, String[] args) throws IOException {
	if (args != null) {
		Option interfaceOption = Option.builder("i").desc("interface to start server on").hasArg().build();
		Option portOption = Option.builder("p").desc("port to start server on").hasArg().build();
		Option persistencyOption = Option.builder("s").desc("start from persistent state").build();
		Options options = new Options();
		options.addOption(interfaceOption);
		options.addOption(portOption);
		options.addOption(persistencyOption);
		CommandLineParser parser = new DefaultParser();

		try {
			CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 0, args.length));
			if (line.hasOption(interfaceOption.getOpt())) {
				String ifname = line.getOptionValue(interfaceOption.getOpt());
				LOG.info("using custom interface " + ifname);
				conf.set(RdmaConstants.STORAGE_RDMA_INTERFACE_KEY, ifname);
			}
			if (line.hasOption(portOption.getOpt())) {
				String port = line.getOptionValue(portOption.getOpt());
				LOG.info("using custom port " + port);
				conf.set(RdmaConstants.STORAGE_RDMA_PORT_KEY, port);
			}
			if (line.hasOption(persistencyOption.getOpt())) {
				conf.set(RdmaConstants.STORAGE_RDMA_PERSISTENT_KEY, "true");
			}
		} catch (ParseException e) {
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp("RDMA storage tier", options);
			System.exit(-1);
		}
	}

	RdmaConstants.updateConstants(conf);
	RdmaConstants.verify();
}
 
Example #27
Source File: ValidatorParametersTest.java    From metadata-qa-marc with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testLimit() {
  String[] arguments = new String[]{"--limit", "3", "a-marc-file.mrc"};
  try {
    ValidatorParameters parameters = new ValidatorParameters(arguments);
    assertEquals(3, parameters.getLimit());
  } catch (ParseException e) {
    e.printStackTrace();
  }
}
 
Example #28
Source File: CLI.java    From titus-control-plane with 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 #29
Source File: BddStepPrinter.java    From vividus with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws ParseException, IOException
{
    CommandLineParser parser = new DefaultParser();
    Option helpOption = new Option("h", "help", false, "Print this message");
    Option fileOption = new Option("f", "file", true, "Name of file to save BDD steps");
    Options options = new Options();
    options.addOption(helpOption);
    options.addOption(fileOption);
    CommandLine commandLine = parser.parse(options, args);

    if (commandLine.hasOption(helpOption.getOpt()))
    {
        new HelpFormatter().printHelp("BddStepPrinter", options);
        return;
    }

    Vividus.init();
    Set<Step> steps = getSteps();

    int maxLocationLength = steps.stream().map(Step::getLocation).mapToInt(String::length).max().orElse(0);

    List<String> stepsLines = steps.stream().map(s -> String
            .format("%-" + (maxLocationLength + 1) + "s%-24s%s %s", s.getLocation(),
                    s.deprecated ? DEPRECATED : (s.compositeInStepsFile ? COMPOSITE : EMPTY), s.startingWord,
                    s.pattern))
            .collect(Collectors.toList());

    String file = commandLine.getOptionValue(fileOption.getOpt());
    if (file == null)
    {
        stepsLines.forEach(System.out::println);
    }
    else
    {
        Path path = Paths.get(file);
        FileUtils.writeLines(path.toFile(), stepsLines);
        System.out.println("File with BDD steps: " + path.toAbsolutePath());
    }
}
 
Example #30
Source File: Commands.java    From devops-cm-client with Apache License 2.0 5 votes vote down vote up
private static String getCommandName(CommandLine commandLine, String[] args) throws ParseException {

        if(commandLine.getArgs().length == 0) {
            throw new CMCommandLineException(format("Cannot extract command name from arguments: '%s'.",
                        getArgsLogString(args)));
        }

        String commandName = commandLine.getArgs()[0];
        logger.debug(format("Command name '%s' extracted from command line '%s'.", commandName, getArgsLogString(args)));
        return commandName;
    }