当前位置: 首页>>代码示例>>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;未经允许,请勿转载。