當前位置: 首頁>>代碼示例>>Java>>正文


Java CommandLine.getArgList方法代碼示例

本文整理匯總了Java中org.apache.commons.cli.CommandLine.getArgList方法的典型用法代碼示例。如果您正苦於以下問題:Java CommandLine.getArgList方法的具體用法?Java CommandLine.getArgList怎麽用?Java CommandLine.getArgList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.cli.CommandLine的用法示例。


在下文中一共展示了CommandLine.getArgList方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
@Override
public void execute(String commandName, ConsoleInput console, CommandLine commandLine) {

	List args = commandLine.getArgList();
	if( args.isEmpty() )
	{
		if( commandLine.hasOption('d') )
			console.out.println(commandName + " --delete requires the name of an alias to remove");
		else
			printAliases(console);
		return;
	}
	if( commandLine.hasOption('d') )
		deleteAlias(console, (String) args.get(0));
	else
	{
		String aliasName = (String) args.remove(0);
		if( args.isEmpty() )
		{
			printAlias(console, aliasName);
		}
		else
			addAlias( console, aliasName, args );
	}
}
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:26,代碼來源:Alias.java

示例2: testHandleArguments

import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
@Test
void testHandleArguments() throws ParseException {
	CommandLine line = ConversionEntry.cli(
			SKIP_VALIDATION, "file.txt", SKIP_DEFAULTS, "-t", "meep,mawp", "file2.txt");
	List<String> args = line.getArgList();

	assertWithMessage("should be comprised of the 2 files")
			.that(args.size())
			.isEqualTo(2);
	assertThat(args).containsExactly("file.txt", "file2.txt");
}
 
開發者ID:CMSgov,項目名稱:qpp-conversion-tool,代碼行數:12,代碼來源:ConversionEntryTest.java

示例3: ls

import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public int ls(String[] args) {

  Options lsOption = new Options();
  CommandLineParser parser = new GnuParser();
  try {
    CommandLine line = parser.parse(lsOption, args);

    List<String> argsList = line.getArgList();
    if (argsList.size() != 2) {
      return usageError("ls requires exactly one path argument", LS_USAGE);
    }
    if (!validatePath(argsList.get(1))) {
      return -1;
    }

    try {
      List<String> children = registry.list(argsList.get(1));
      for (String child : children) {
        sysout.println(child);
      }
      return 0;

    } catch (Exception e) {
      syserr.println(analyzeException("ls", e, argsList));
    }
    return -1;
  } catch (ParseException exp) {
    return usageError("Invalid syntax " + exp, LS_USAGE);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:32,代碼來源:RegistryCli.java

示例4: mknode

import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public int mknode(String[] args) {
  Options mknodeOption = new Options();
  CommandLineParser parser = new GnuParser();
  try {
    CommandLine line = parser.parse(mknodeOption, args);

    List<String> argsList = line.getArgList();
    if (argsList.size() != 2) {
      return usageError("mknode requires exactly one path argument",
          MKNODE_USAGE);
    }
    if (!validatePath(argsList.get(1))) {
      return -1;
    }

    try {
      registry.mknode(args[1], false);
      return 0;
    } catch (Exception e) {
      syserr.println(analyzeException("mknode", e, argsList));
    }
    return -1;
  } catch (ParseException exp) {
    return usageError("Invalid syntax " + exp.toString(), MKNODE_USAGE);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:28,代碼來源:RegistryCli.java

示例5: rm

import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public int rm(String[] args) {
  Option recursive = OptionBuilder.withArgName("recursive")
                                  .withDescription("delete recursively")
                                  .create("r");

  Options rmOption = new Options();
  rmOption.addOption(recursive);

  boolean recursiveOpt = false;

  CommandLineParser parser = new GnuParser();
  try {
    CommandLine line = parser.parse(rmOption, args);

    List<String> argsList = line.getArgList();
    if (argsList.size() != 2) {
      return usageError("RM requires exactly one path argument", RM_USAGE);
    }
    if (!validatePath(argsList.get(1))) {
      return -1;
    }

    try {
      if (line.hasOption("r")) {
        recursiveOpt = true;
      }

      registry.delete(argsList.get(1), recursiveOpt);
      return 0;
    } catch (Exception e) {
      syserr.println(analyzeException("rm", e, argsList));
    }
    return -1;
  } catch (ParseException exp) {
    return usageError("Invalid syntax " + exp.toString(), RM_USAGE);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:39,代碼來源:RegistryCli.java

示例6: processOptions

import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
@Override
protected void processOptions(CommandLine cmd) {
  List args = cmd.getArgList();
  if (args.size() > 0) {
    usage();
    throw new RuntimeException("No args expected.");
  }
  // We always want loadAndVerify action
  args.add("loadAndVerify");
  if (cmd.hasOption(USER_OPT)) {
    userNames = cmd.getOptionValue(USER_OPT);
  }
  super.processOptions(cmd);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:15,代碼來源:IntegrationTestWithCellVisibilityLoadAndVerify.java

示例7: parse

import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
public SpydraArgument parse(String[] args) throws IOException {
  DefaultParser parser = new DefaultParser();
  CommandLine cmdLine;

  cmdLine = CliHelper.tryParse(parser, options, args);

  SpydraArgument spydraArgument = new SpydraArgument();
  if (cmdLine.hasOption(CliConsts.SPYDRA_JSON_OPTION_NAME)) {
    String[] files = cmdLine.getOptionValues(CliConsts.SPYDRA_JSON_OPTION_NAME);
    for (String file : files) {
      spydraArgument = SpydraArgument.merge(spydraArgument,
          JsonHelper.objectMapper().readValue(new File(file), SpydraArgument.class));
    }
  }

  if (cmdLine.hasOption(CliConsts.JAR_OPTION_NAME)) {
    spydraArgument.getSubmit().getOptions().put(SpydraArgument.OPTION_JAR,
        cmdLine.getOptionValue(CliConsts.JAR_OPTION_NAME));
  }

  if (cmdLine.hasOption(CliConsts.CLIENT_ID_OPTION_NAME)) {
    spydraArgument.setClientId(cmdLine.getOptionValue(CliConsts.CLIENT_ID_OPTION_NAME));
  }

  if (cmdLine.hasOption(CliConsts.JARS_OPTION_NAME)) {
    spydraArgument.getSubmit().getOptions().put(SpydraArgument.OPTION_JARS,
        StringUtils.join(cmdLine.getOptionValues(CliConsts.JARS_OPTION_NAME), ","));
  }

  if (cmdLine.hasOption(CliConsts.JOBNAME_OPTION_NAME)) {
    spydraArgument.getSubmit().getOptions().put(SpydraArgument.OPTION_JOB_ID,
        sanitizeJobId(cmdLine.getOptionValue(CliConsts.JOBNAME_OPTION_NAME)));
  }

  if (spydraArgument.jobType.isPresent()) {
    spydraArgument.setJobType(spydraArgument.getJobType().toLowerCase());
  }

  if (cmdLine.hasOption(SpydraArgument.OPTION_DRYRUN)) {
    spydraArgument.setDryRun(true);
  }

  List<String> jobArgs = new LinkedList<>(cmdLine.getArgList());
  if (jobArgs.size() > 0) {
    spydraArgument.getSubmit().setJobArgs(jobArgs);
  }

  return spydraArgument;
}
 
開發者ID:spotify,項目名稱:spydra,代碼行數:50,代碼來源:SubmissionCliParser.java

示例8: resolve

import org.apache.commons.cli.CommandLine; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public int resolve(String[] args) {
  Options resolveOption = new Options();
  CommandLineParser parser = new GnuParser();
  try {
    CommandLine line = parser.parse(resolveOption, args);

    List<String> argsList = line.getArgList();
    if (argsList.size() != 2) {
      return usageError("resolve requires exactly one path argument",
          RESOLVE_USAGE);
    }
    if (!validatePath(argsList.get(1))) {
      return -1;
    }

    try {
      ServiceRecord record = registry.resolve(argsList.get(1));

      for (Endpoint endpoint : record.external) {
        sysout.println(" Endpoint(ProtocolType="
                       + endpoint.protocolType + ", Api="
                       + endpoint.api + ");"
                       + " Addresses(AddressType="
                       + endpoint.addressType + ") are: ");

        for (Map<String, String> address : endpoint.addresses) {
          sysout.println("[ ");
          for (Map.Entry<String, String> entry : address.entrySet()) {
            sysout.print("\t" + entry.getKey()
                           + ":" + entry.getValue());
          }

          sysout.println("\n]");
        }
        sysout.println();
      }
      return 0;
    } catch (Exception e) {
      syserr.println(analyzeException("resolve", e, argsList));
    }
    return -1;
  } catch (ParseException exp) {
    return usageError("Invalid syntax " + exp, RESOLVE_USAGE);
  }

}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:48,代碼來源:RegistryCli.java


注:本文中的org.apache.commons.cli.CommandLine.getArgList方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。