當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。