for (Option option : getOptions()) { cliOptions.addOption(option); System.out.println(); printHelp(); return 1; int result = processOptions(cmd); if (result != 0) { return result; return run(cmd);
protected void start(String[] args) { int result = 1; try { System.out.println(); result = runBase(args); } catch (CliException e) { System.err.println(); System.err.println(e.getMessage()); System.exit(e.getExitCode()); } catch (Throwable t) { reportThrowable(t); } finally { try { cleanup(); } catch (Throwable t) { System.err.println("Error during cleanup:"); t.printStackTrace(); } } System.out.println(); if (result != 0) { System.exit(result); } }
protected void printHelp() throws IOException { printHelpHeader(); HelpFormatter help = new HelpFormatter(); help.printHelp(getCmdName(), cliOptions, true); printHelpFooter(); }
@Override public int run(CommandLine cmd) throws Exception { int result = super.run(cmd); if (result != 0) { return result;
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); zkOption = OptionBuilder .withArgName("connection-string") .hasArg() .withDescription("ZooKeeper connection string: hostname1:port,hostname2:port,... Can also be " + "specified through the environment variable LILY_CLI_ZK") .withLongOpt("zookeeper") .create("z"); options.add(zkOption); return options; }
/** * Process option values, typically this performs basic stuff like reading * the option value and validating it. First always call super, if non-zero * is returned, then return this value immediately. */ protected int processOptions(CommandLine cmd) throws Exception { if (cmd.hasOption(helpOption.getOpt())) { printHelp(); return 1; } if (cmd.hasOption(versionOption.getOpt())) { System.out.println(getVersion()); return 1; } if (cmd.hasOption(dumpLogConfOption.getOpt())) { IOUtils.copy(BaseCliTool.class.getResourceAsStream("log4j.properties"), System.out); return 1; } File logConfFile = null; if (cmd.hasOption(logConfOption.getOpt())) { logConfFile = new File(cmd.getOptionValue(logConfOption.getOpt())); if (!logConfFile.exists()) { System.err.println("Specified log4j configuration file does not exist:"); System.err.println(logConfFile); } } setupLogging(logConfFile); return 0; }
@Override public int run(CommandLine cmd) throws Exception { int result = super.run(cmd); if (result != 0) { return result;
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); nameserverOption = OptionBuilder .withArgName("nameserver") .hasArg() .withDescription("Non-default nameserver to use.") .withLongOpt("host") .create("n"); options.add(nameserverOption); return options; }
@Override public int run(CommandLine cmd) throws Exception { int result = super.run(cmd); if (result != 0) { return result;
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); collectionOption = OptionBuilder .withArgName("collection") .hasArg() .withDescription("Daisy collection name, default " + DEFFAULT_COLLECTION) .withLongOpt("collection") .create("c"); branchOption = OptionBuilder .withArgName("branch") .hasArg() .withDescription("Daisy branch, default " + DEFFAULT_BRANCH) .withLongOpt("branch") .create("b"); options.add(collectionOption); options.add(branchOption); return options; }
@Override public int run(CommandLine cmd) throws Exception { int result = super.run(cmd); if (result != 0) { return result; } int uuidSplits = OptionUtil.getIntOption(cmd, uuidSplitsOption, -1); int uuidSplitsLength = OptionUtil.getIntOption(cmd, uuidSplitsLengthOption, 3); int userIdSplits = OptionUtil.getIntOption(cmd, userIdSplitsOption, -1); int userIdSplitsLength = OptionUtil.getIntOption(cmd, userIdSplitsLengthOption, 3); boolean noPrefix = cmd.hasOption(noPrefixOption.getOpt()); if (uuidSplits != -1 && userIdSplits != -1) { String splitKeys = generateUserHexadecimalSplits(userIdSplits, userIdSplitsLength, noPrefix) + "," + Bytes.toStringBinary(new byte[] { 1 }) + "," + generateUuidSplits(uuidSplits, uuidSplitsLength, noPrefix); System.out.println(splitKeys); } else if (uuidSplits != -1) { System.out.println(generateUuidSplits(uuidSplits, uuidSplitsLength, noPrefix)); } else if (userIdSplits != -1) { System.out.println(generateUserHexadecimalSplits(userIdSplits, userIdSplitsLength, noPrefix)); } else { System.out.println("Nothing to do, use -h to get help."); } return 0; }
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); metricsFileOption = OptionBuilder .withArgName("filename") .hasArg() .withDescription("Name of the input metrics file") .withLongOpt("metrics-file") .create("m"); options.add(metricsFileOption); outputDirOption = OptionBuilder .withArgName("dirname") .hasArg() .withDescription("Name of the output dir") .withLongOpt("output-dir") .create("o"); options.add(outputDirOption); forceOption = OptionBuilder.withDescription("Force using the output directory even if it already exists") .withLongOpt("force").create("f"); options.add(forceOption); return options; }
@Override public int run(CommandLine cmd) throws Exception { int result = super.run(cmd); if (result != 0) { return result;
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions();