protected void printHelp() throws IOException { printHelpHeader(); HelpFormatter help = new HelpFormatter(); help.printHelp(getCmdName(), cliOptions, true); printHelpFooter(); }
@Override public List<Option> getOptions() { List<Option> options = super.getOptions(); options.add(repositoryOpt); return options; }
public static <T extends Enum<T>> T getEnum(CommandLine cmd, Option option, T defaultValue, Class<T> enumClass) { String value = getStringOption(cmd, option, null); if (value == null) { return defaultValue; } try { return Enum.valueOf(enumClass, value.toUpperCase()); } catch (IllegalArgumentException e) { throw new CliException("Invalid value for option " + option.getLongOpt() + ": " + value); } }
@Override public int run(CommandLine cmd) throws Exception { int status = super.run(cmd); if (status != 0) { return status; } LilyClient lilyClient = new LilyClient(zkConnectionString, 30000); TableManager tableManager = lilyClient.getRepository(repositoryName).getTableManager(); try { status = execute(tableManager); } finally { lilyClient.close(); } return status; }
@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; }
@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; }
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); } }
@Override protected void cleanup() { Closer.close(lilyClient); super.cleanup(); }
@Override protected int processOptions(CommandLine cmd) throws Exception { int result = super.processOptions(cmd); if (result != 0) { return result; } if (cmd.hasOption(repositoryOpt.getLongOpt())) { repositoryName = cmd.getOptionValue(repositoryOpt.getLongOpt()); } else { repositoryName = RepoAndTableUtil.DEFAULT_REPOSITORY; } return 0; }
public static String getStringOption(CommandLine cmd, Option option) { String opt = option.getOpt() == null ? option.getLongOpt() : option.getOpt(); if (cmd.hasOption(opt)) { return cmd.getOptionValue(opt); } else { throw new CliException("Missing value for option " + opt); } }
@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 List<Option> getOptions() { List<Option> options = super.getOptions(); options.add(pythonMapperPathArg); options.add(pythonSymbolArg); options.add(repositoryArg); options.add(outputTableArg); options.add(disableBulkOption); return options; }
@Override protected void cleanup() { Closer.close(repositoryModel); Closer.close(zk); super.cleanup(); } }
public static <T extends Enum<T>> T getEnum(CommandLine cmd, Option option, Class<T> enumClass) { String value = getStringOption(cmd, option); try { return Enum.valueOf(enumClass, value.toUpperCase()); } catch (IllegalArgumentException e) { throw new CliException("Invalid value for option " + option.getLongOpt() + ": " + value); } } }
public static int getIntOption(CommandLine cmd, Option option, int defaultValue) { String opt = option.getOpt() == null ? option.getLongOpt() : option.getOpt(); if (cmd.hasOption(opt)) { try { return Integer.parseInt(cmd.getOptionValue(opt)); } catch (NumberFormatException e) { throw new CliException("Invalid value for option " + option.getLongOpt() + ": " + cmd.getOptionValue(opt)); } } return defaultValue; }
@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 @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); recordIdOption = OptionBuilder .withArgName("record-id") .hasArg() .withDescription("A Lily record ID: UUID.something or USER.something") .withLongOpt("record-id") .create("r"); options.add(recordIdOption); tableOption = OptionBuilder .withArgName("table") .hasArg() .withDescription("Repository table name (defaults to record)") .withLongOpt("table") .create("t"); options.add(tableOption); return options; }
@Override protected void cleanup() { Closer.close(typeMgr); Closer.close(zk); HConnectionManager.deleteAllConnections(true); super.cleanup(); }
public static long getLongOption(CommandLine cmd, Option option, long defaultValue) { String opt = option.getOpt() == null ? option.getLongOpt() : option.getOpt(); if (cmd.hasOption(opt)) { try { return Long.parseLong(cmd.getOptionValue(opt)); } catch (NumberFormatException e) { throw new CliException("Invalid value for option " + option.getLongOpt() + ": " + cmd.getOptionValue(opt)); } } return defaultValue; }
@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; }