Example usage for org.apache.commons.cli Option getLongOpt

List of usage examples for org.apache.commons.cli Option getLongOpt

Introduction

In this page you can find the example usage for org.apache.commons.cli Option getLongOpt.

Prototype

public String getLongOpt() 

Source Link

Document

Retrieve the long name of this Option.

Usage

From source file:com.asakusafw.directio.hive.tools.cli.GenerateCreateTable.java

private static String getOption(CommandLine cmd, Option option) {
    String value = cmd.getOptionValue(option.getOpt());
    LOG.debug("Option: {}={}", option.getLongOpt(), value); //$NON-NLS-1$
    return value;
}

From source file:com.asakusafw.lang.inspection.cli.Cli.java

private static String parseOpt(CommandLine cmd, Option opt, boolean mandatory) {
    String value = cmd.getOptionValue(opt.getLongOpt());
    if (value != null) {
        value = value.trim();//w  w  w  .  j  a  v  a  2 s  . com
        if (value.isEmpty()) {
            value = null;
        }
    }
    LOG.debug("--{}: {}", opt.getLongOpt(), value); //$NON-NLS-1$
    if (value == null) {
        if (mandatory) {
            throw new IllegalArgumentException(
                    MessageFormat.format("option \"--{0}\" is mandatory", opt.getLongOpt()));
        }
        return null;
    }
    return value;
}

From source file:name.livitski.databag.cli.Syntax.java

protected static String getOptionId(Option option) {
    return option.hasLongOpt() ? LONG_OPT_PREFIX + option.getLongOpt() : OPT_PREFIX + option.getOpt();
}

From source file:com.leshazlewood.scms.cli.Main.java

private static void printHelp(Options options, Exception e, boolean debug) {
    HelpFormatter help = new HelpFormatter();
    help.setWidth(80);/*  ww  w.j  a  v  a  2  s.c  om*/
    String command = "scms [options] [src_dir] dest_dir";
    String header = "Injests content files in [src dir] and renders a static website into dest_dir.\n\n"
            + "  [src_dir] is optional and defaults to the current working directory.\n"
            + "  dest_dir is required and cannot be the same as src_dir.";
    /*String footer = "\n" +
        "Injests source content files and page templates in [src dir] and renders a\n" +
        "renders a static website into destination_directory.\n\n" +
        "If unspecified, [source directory] defaults to the current working\n" +
        "directory.  destination_directory is required and cannot be the same\n" +
        "as the source directory.";*/

    printException(e, debug);

    System.out.println();

    System.out.println("Usage:");
    System.out.print("  ");
    System.out.println(command);
    System.out.println();
    System.out.println("Description:");
    System.out.print("  ");
    System.out.println(header);
    System.out.println();
    System.out.println("Options:");

    StringBuilder sb = new StringBuilder();

    int columnWidth = calculateColumnWidth(options);

    for (Object o : options.getOptions()) {
        Option option = (Option) o;
        StringBuilder csb = new StringBuilder("  ");
        csb.append("-").append(option.getOpt()).append(",--").append(option.getLongOpt());
        if (option.hasArg()) {
            csb.append(" <arg>");
        }
        int csbLength = csb.length();
        for (int i = 0; i < (columnWidth - csbLength); i++) {
            csb.append(" ");
        }
        sb.append(csb.toString()).append("   ").append(option.getDescription()).append("\n");
    }
    System.out.println(sb);

    //help.printHelp("", "", options, null);
    //System.out.println(footer);
}

From source file:com.leshazlewood.scms.cli.Main.java

private static int calculateColumnWidth(Options options) {
    int max = 0;/*  www .  j a v  a  2 s .  c o  m*/
    for (Object o : options.getOptions()) {
        Option opt = (Option) o;
        int columnWidth = "-".length() + opt.getOpt().length();
        if (opt.hasLongOpt()) {
            columnWidth += ",--".length();
            columnWidth += opt.getLongOpt().length();
        }
        if (opt.hasArg()) {
            columnWidth += " <arg>".length();
        }
        columnWidth += 3; //buffer between description
        max = Math.max(max, columnWidth);
    }
    return max;
}

From source file:gr.ntua.ece.cslab.panic.core.client.Benchmark.java

/**
 * Create csv file template where each column contains information about a
 * specific model./*  w  ww . j  ava  2 s.c om*/
 *
 * @param file needed to load input domain space and get labels
 * @param sampler sampler object, used to write it to csv as comment
 * @param picked
 * @throws Exception
 */
public static void createCSVForModels(CSVFileManager file, Sampler sampler, List<InputSpacePoint> picked)
        throws Exception {
    OutputSpacePoint headerPoint = file.getOutputSpacePoints().get(0);
    outputPrintStream.println("# Created: " + new Date());
    outputPrintStream.println("# Active sampler: " + sampler.getClass().toString());
    outputPrintStream.println("# Runtime options:");
    for (Option p : cmd.getOptions()) {
        outputPrintStream.println("#\t" + p.getLongOpt() + ":\t" + cmd.getOptionValue(p.getLongOpt()));
    }
    outputPrintStream.println("#");
    outputPrintStream.println("# Points picked");
    for (InputSpacePoint p : picked) {
        outputPrintStream.println("# \t" + p);
    }

    for (String k : headerPoint.getInputSpacePoint().getKeysAsCollection()) {
        outputPrintStream.print(k + "\t");
    }
    outputPrintStream.print(headerPoint.getKey() + "\t");

    for (Model m : models) {
        outputPrintStream.print(m.getClass().toString().substring(m.toString().lastIndexOf(".") + 7) + "\t");
    }
    outputPrintStream.println();

    for (OutputSpacePoint p : file.getOutputSpacePoints()) {
        outputPrintStream.print(p.getInputSpacePoint().toStringCSVFormat() + "\t"); // input space point
        outputPrintStream.format("%.4f\t", p.getValue());
        for (Model m : models) {
            outputPrintStream.format("%.4f\t", m.getPoint(p.getInputSpacePoint()).getValue());
        }
        outputPrintStream.println();
    }
    outputPrintStream.println();
    outputPrintStream.println();
}

From source file:name.livitski.databag.cli.Syntax.java

protected static String formatOptionHeader(Option option) {
    String title;//from w  w  w. j  a v a  2s .co m
    if (null == option.getOpt())
        title = LONG_OPT_PREFIX + option.getLongOpt();
    else
        title = OPT_PREFIX + option.getOpt()
                + (option.hasLongOpt() ? ", " + LONG_OPT_PREFIX + option.getLongOpt() : "");
    return title;
}

From source file:de.oth.keycloak.util.CheckParams.java

private static void printCommandLineHelp(Options options) {
    HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.setOptionComparator(new Comparator<Option>() {
        public int compare(Option option1, Option option2) {
            if (option1.isRequired() == option2.isRequired()) {
                if (option1.getOpt() != null && option2.getOpt() != null) {
                    return option1.getOpt().compareTo(option2.getOpt());
                } else if (option1.getLongOpt() != null && option2.getLongOpt() != null) {
                    return option1.getLongOpt().compareTo(option2.getLongOpt());
                } else {
                    return -1;
                }/*  w  w  w. ja  v a  2 s  .co  m*/
            } else {
                return (option1.isRequired() ? -1 : 1);
            }
        }
    });
    helpFormatter.setWidth(256);
    helpFormatter.printHelp("java " + InitKeycloakServer.class.getName(), options, true);
}

From source file:eu.project.ttc.tools.cli.TermSuiteCLIUtils.java

/**
 * Returns the key of the given option//w w w.  ja  v a 2  s.  c o m
 * 
 * @param opt
 *            The option
 * @return {@link Option#getOpt()} if the value returned is not empty, or
 *         {@link Option#getLongOpt()} otherwise.
 */
public static String getOptionKey(Option opt) {
    String key = opt.getOpt();
    if (key == null || key.isEmpty())
        key = opt.getLongOpt();
    return key;
}

From source file:com.alibaba.rocketmq.common.MixAll.java

public static Properties commandLine2Properties(final CommandLine commandLine) {
    Properties properties = new Properties();
    Option[] opts = commandLine.getOptions();

    if (opts != null) {
        for (Option opt : opts) {
            String name = opt.getLongOpt();
            String value = commandLine.getOptionValue(name);
            if (value != null) {
                properties.setProperty(name, value);
            }/*  w ww . j  ava 2  s.  c o  m*/
        }
    }

    return properties;
}