当前位置: 首页>>代码示例>>Java>>正文


Java CommandLine类代码示例

本文整理汇总了Java中org.apache.commons.cli.CommandLine的典型用法代码示例。如果您正苦于以下问题:Java CommandLine类的具体用法?Java CommandLine怎么用?Java CommandLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CommandLine类属于org.apache.commons.cli包,在下文中一共展示了CommandLine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseCommandLine

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
/**
 *  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;
}
 
开发者ID:pinterest,项目名称:doctorkafka,代码行数:24,代码来源:URPChecker.java

示例2: main

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
public static void main(String[] args) {
    CommandLineParser parser = new DefaultParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(buildOptions(), args);

        if (line.hasOption('h')) {
            printHelp();
            System.exit(0);
        }

        if (line.hasOption('v')) {
            System.out.println(VERSION_STRING);
            System.exit(0);
        }

        new CommandLineApp(System.out, line).extractTables(line);
    } catch (ParseException exp) {
        System.err.println("Error: " + exp.getMessage());
        System.exit(1);
    }
    System.exit(0);
}
 
开发者ID:redmyers,项目名称:484_P7_1-Java,代码行数:24,代码来源:CommandLineApp.java

示例3: processOptions

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
@Override
protected void processOptions(CommandLine cmd) {
  super.processOptions(cmd);

  String[] args = cmd.getArgs();
  if (args == null || args.length < 1) {
    usage();
    throw new RuntimeException("Incorrect Number of args.");
  }
  toRun = args[0];
  if (toRun.equalsIgnoreCase("search")) {
    if (args.length > 1) {
      keysDir = args[1];
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:IntegrationTestLoadAndVerify.java

示例4: parse

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
@Override
public CliCommand parse(String[] cmdArgs) throws CliParseException {
    Parser parser = new PosixParser();
    CommandLine cl;
    try {
        cl = parser.parse(options, cmdArgs);
    } catch (ParseException ex) {
        throw new CliParseException(ex);
    }
    args = cl.getArgs();
    if (args.length < 2) {
        throw new CliParseException(getUsageStr());
    }

    return this;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:17,代码来源:SyncCommand.java

示例5: testExecute

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
@Test
public void testExecute() {
    UpdateTopicSubCommand cmd = new UpdateTopicSubCommand();
    Options options = ServerUtil.buildCommandlineOptions(new Options());
    String[] subargs = new String[] {
        "-b 127.0.0.1:10911",
        "-c default-cluster",
        "-t unit-test",
        "-r 8",
        "-w 8",
        "-p 6",
        "-o false",
        "-u false",
        "-s false"};
    final CommandLine commandLine =
        ServerUtil.parseCmdLine("mqadmin " + cmd.commandName(), subargs, cmd.buildCommandlineOptions(options), new PosixParser());
    assertThat(commandLine.getOptionValue('b').trim()).isEqualTo("127.0.0.1:10911");
    assertThat(commandLine.getOptionValue('c').trim()).isEqualTo("default-cluster");
    assertThat(commandLine.getOptionValue('r').trim()).isEqualTo("8");
    assertThat(commandLine.getOptionValue('w').trim()).isEqualTo("8");
    assertThat(commandLine.getOptionValue('t').trim()).isEqualTo("unit-test");
    assertThat(commandLine.getOptionValue('p').trim()).isEqualTo("6");
    assertThat(commandLine.getOptionValue('o').trim()).isEqualTo("false");
    assertThat(commandLine.getOptionValue('u').trim()).isEqualTo("false");
    assertThat(commandLine.getOptionValue('s').trim()).isEqualTo("false");
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:27,代码来源:UpdateTopicSubCommandTest.java

示例6: main

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
/**
 * Executable function to demonstrate Apache Commons CLI
 * parsing of command-line arguments.
 *
 * @param arguments Command-line arguments to be parsed.
 */
public static void main(final String[] arguments)
{
   final Options options = generateOptions();

   if (arguments.length < 1)
   {
      printUsage(options);
      printHelp(options);
      System.exit(-1);
   }

   final CommandLine commandLine = generateCommandLine(options, arguments);

   // "interrogation" stage of processing with Apache Commons CLI
   if (commandLine != null)
   {
      final boolean verbose =
         commandLine.hasOption(VERBOSE_OPTION);
      final String fileName =
         commandLine.getOptionValue(FILE_OPTION);
      out.println("The file '" + fileName + "' was provided and verbosity is set to '" + verbose + "'.");
   }
}
 
开发者ID:dustinmarx,项目名称:java-cli-demos,代码行数:30,代码来源:MainWithBuilder.java

示例7: execute

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    final DefaultMQProducer producer = new DefaultMQProducer("PID_SMSC", rpcHook);
    producer.setInstanceName("PID_SMSC_" + System.currentTimeMillis());

    try {
        producer.start();
        String brokerName = commandLine.getOptionValue('b').trim();
        int messageSize = commandLine.hasOption('s') ? Integer.parseInt(commandLine.getOptionValue('s')) : 128;
        int count = commandLine.hasOption('c') ? Integer.parseInt(commandLine.getOptionValue('c')) : 50;

        producer.send(buildMessage(brokerName, 16));

        for (int i = 0; i < count; i++) {
            long begin = System.currentTimeMillis();
            SendResult result = producer.send(buildMessage(brokerName, messageSize));
            System.out.printf("rt:" + (System.currentTimeMillis() - begin) + "ms, SendResult=" + result);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        producer.shutdown();
    }
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:25,代码来源:SendMsgStatusCommand.java

示例8: parse

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
static DemoUiState parse(CommandLine line) {

        // if we have `help`, then no need to evaluate configuration
        final DemoUiState state = new DemoUiState();

        state.showHelp(help(line));

        state.live(live(line));
        state.demoMode(demo(line));
        state.configuration(configuration(line));

        state.adb(adb(line));
        state.demoMode(demo(line));
        state.demoGlobalSettingEnabled(demoEnabled(line));
        state.loadConfiguration(loadConfiguration(line));
        state.saveConfiguration(saveConfiguration(line));

        state.debug(debug(line));
        state.screenshot(screenshot(line));

        return state;
    }
 
开发者ID:noties,项目名称:DemoUi,代码行数:23,代码来源:DemoUiCommandLineParser.java

示例9: extract

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
@Override
public MixtureOptionPack extract(CommandLine cmdline) throws AlreadySelectedException {
  NumEmptyClusters = Integer.parseInt(cmdline.getOptionValue("NumEmptyClusters", defaultNumEmptyClusters));
  if (cmdline.hasOption("Reuse")) {
    alg.setSelected(reuse);
  } else if (cmdline.hasOption("Neal8")) {
    alg.setSelected(neal8);
  } else if (cmdline.hasOption("Slice")) {
    alg.setSelected(slice);
  } else {
    throw new Error("mixture algorithm option not set");
  }
  if (cmdline.hasOption("Marginalized")) {
    marg.setSelected(marginalized);
  } else if (cmdline.hasOption("Sampled")) {
    marg.setSelected(sampled);
  }
  
  //MaxEmptyClusters = Integer.parseInt(cmdline.getOptionValue("MaxEmptyClusters", defaultMaxEmptyClusters));
  return this;
}
 
开发者ID:BigBayes,项目名称:BNPMix.java,代码行数:22,代码来源:MixtureOptionPack.java

示例10: main

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
public final static void main(String[] args) throws Exception {
    logger.debug(format("%s called with arguments: '%s'.", ReleaseTransport.class.getSimpleName(), Commands.Helpers.getArgsLogString(args)));
    Options options = new Options();
    Commands.Helpers.addStandardParameters(options);

    if(helpRequested(args)) {
        handleHelpOption(
            format("%s <changeId> <transportId>", getCommandName(ReleaseTransport.class)),
            "Releases the transport specified by <changeId>, <transportId>.", new Options()); return;
    }

    CommandLine commandLine = new DefaultParser().parse(options, args);

    new ReleaseTransport(getHost(commandLine),
            getUser(commandLine),
            getPassword(commandLine),
            getChangeId(commandLine),
            TransportRelated.getTransportId(commandLine)).execute();
}
 
开发者ID:SAP,项目名称:devops-cm-client,代码行数:20,代码来源:ReleaseTransport.java

示例11: setServerImpl

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
static void setServerImpl(CommandLine cmd, Configuration conf) {
  ImplType chosenType = null;
  int numChosen = 0;
  for (ImplType t : values()) {
    if (cmd.hasOption(t.option)) {
      chosenType = t;
      ++numChosen;
    }
  }
  if (numChosen < 1) {
    LOG.info("Using default thrift server type");
    chosenType = DEFAULT;
  } else if (numChosen > 1) {
    throw new AssertionError("Exactly one option out of " +
      Arrays.toString(values()) + " has to be specified");
  }
  LOG.info("Using thrift server type " + chosenType.option);
  conf.set(SERVER_TYPE_CONF_KEY, chosenType.option);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:20,代码来源:ThriftServerRunner.java

示例12: transitionToActive

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
private int transitionToActive(final CommandLine cmd)
    throws IOException, ServiceFailedException {
  String[] argv = cmd.getArgs();
  if (argv.length != 1) {
    errOut.println("transitionToActive: incorrect number of arguments");
    printUsage(errOut, "-transitionToActive");
    return -1;
  }
  /*  returns true if other target node is active or some exception occurred 
      and forceActive was not set  */
  if(!cmd.hasOption(FORCEACTIVE)) {
    if(isOtherTargetNodeActive(argv[0], cmd.hasOption(FORCEACTIVE))) {
      return -1;
    }
  }
  HAServiceTarget target = resolveTarget(argv[0]);
  if (!checkManualStateManagementOK(target)) {
    return -1;
  }
  HAServiceProtocol proto = target.getProxy(
      getConf(), 0);
  HAServiceProtocolHelper.transitionToActive(proto, createReqInfo());
  return 0;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:25,代码来源:HAAdmin.java

示例13: parseCmdLine

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
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;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:18,代码来源:ServerUtil.java

示例14: loadConfigurations

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
private static Config loadConfigurations(CommandLine cmd, int id) {
  String twister2Home = cmd.getOptionValue("twister2_home");
  String container = cmd.getOptionValue("container_class");
  String configDir = cmd.getOptionValue("config_dir");
  String clusterType = cmd.getOptionValue("cluster_type");

  LOG.log(Level.INFO, String.format("Initializing process with "
      + "twister_home: %s container_class: %s config_dir: %s cluster_type: %s",
      twister2Home, container, configDir, clusterType));

  Config config = ConfigLoader.loadConfig(twister2Home, configDir + "/" + clusterType);
  return Config.newBuilder().putAll(config).
      put(MPIContext.TWISTER2_HOME.getKey(), twister2Home).
      put(MPIContext.TWISTER2_JOB_BASIC_CONTAINER_CLASS, container).
      put(MPIContext.TWISTER2_CONTAINER_ID, id).
      put(MPIContext.TWISTER2_CLUSTER_TYPE, clusterType).build();
}
 
开发者ID:DSC-SPIDAL,项目名称:twister2,代码行数:18,代码来源:MPIProcess.java

示例15: testParseProfile

import org.apache.commons.cli.CommandLine; //导入依赖的package包/类
@Test
public void testParseProfile() throws Exception {
    final ProtocolFactory factory = new ProtocolFactory(new HashSet<>(Collections.singleton(new SwiftProtocol() {
        @Override
        public boolean isEnabled() {
            return true;
        }
    })));
    final ProfilePlistReader reader = new ProfilePlistReader(factory, new DeserializerFactory(PlistDeserializer.class.getName()));
    final Profile profile = reader.read(
            new Local("../profiles/default/Rackspace US.cyberduckprofile")
    );
    assertNotNull(profile);

    final CommandLineParser parser = new PosixParser();
    final CommandLine input = parser.parse(new Options(), new String[]{});

    assertEquals(new Path("/cdn.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)),
            new CommandLinePathParser(input, new ProtocolFactory(new HashSet<>(Arrays.asList(new SwiftProtocol(), profile)))).parse("rackspace://[email protected]/"));
    assertEquals(new Path("/", EnumSet.of(Path.Type.directory, Path.Type.volume)),
            new CommandLinePathParser(input, new ProtocolFactory(new HashSet<>(Arrays.asList(new SwiftProtocol(), profile)))).parse("rackspace:///"));
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:23,代码来源:CommandLinePathParserTest.java


注:本文中的org.apache.commons.cli.CommandLine类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。