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

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

Introduction

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

Prototype

public String getDescription() 

Source Link

Document

Retrieve the self-documenting description of this Option

Usage

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);//from w  w w .  j  a v  a 2s. c o m
    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.zenoss.zenpacks.zenjmx.OptionsPrinter.java

/**
 * Returns a user-readable representation of an Option
 *///ww  w .j  a  v  a  2 s.  c o  m
private String print(Option option) {
    return "  " + option.getOpt() + ": " + option.getDescription();
}

From source file:com.marklogic.contentpump.utilities.CommandlineOption.java

public CommandlineOption(Option opt) throws IllegalArgumentException {
    super(opt.getOpt(), opt.hasArg(), opt.getDescription());

    this.setLongOpt(opt.getLongOpt());
    this.setRequired(opt.isRequired());
    this.setArgName(opt.getArgName());
    this.setArgs(opt.getArgs());
    this.setOptionalArg(opt.hasOptionalArg());
    this.setType(opt.getType());
    this.setValueSeparator(opt.getValueSeparator());
}

From source file:henplus.AbstractCommand.java

@Override
public String getLongDescription(final String cmd) {
    final Collection<Option> handledCommandLineOptions = getHandledCommandLineOptions();
    if (handledCommandLineOptions != null && handledCommandLineOptions.size() > 0) {
        final StringBuilder sb = new StringBuilder("\tRecognized options are:\n");
        for (final Option option : handledCommandLineOptions) {
            sb.append(String.format("\t -%s %s\n", option.getOpt(), option.getDescription()));
        }//from w w w .ja va  2  s.  c  o m
        return sb.toString();
    }
    return null;
}

From source file:net.sourceforge.metware.binche.execs.CommandLineMain.java

@SuppressWarnings("unchecked")
public void printHelp() {

    for (Object obj : options.getOptions().toArray(new Option[0])) {
        Option opt = (Option) obj;
        System.out.println(/*from ww  w  .  j a v  a  2 s  . c  o m*/
                String.format("  -%s|--%-30s ", opt.getOpt(), opt.getLongOpt()) + opt.getDescription());
    }
    System.exit(0);
}

From source file:com.kaikoda.cah.CardGeneratorOptions.java

/**
 * Prints an annotated list of the options that are valid for use with this
 * application.//from   w w  w.  j a  va 2  s . c  o m
 * 
 * @return a list of all the Card Generator options.
 */
private String getHelp() {

    String help = "The options that can be used with this application are:\n";

    Collection<Option> optionsCollection = this.getOptions();
    Iterator<Option> validOptions = optionsCollection.iterator();
    while (validOptions.hasNext()) {
        Option option = validOptions.next();

        help = help + "\n-" + option.getOpt() + "\t" + option.getDescription() + "\n";
    }

    return help;
}

From source file:com.engineering.ses.spell.clientstubj.cmdclient.CommandClient.java

/***************************************************************************
 * Show help text /*  w ww .j  a va 2 s.c  o  m*/
 **************************************************************************/
private void showHelp() {
    System.out.println("Usage: java -jar <jarfile> [options]");
    System.out.println();
    System.out.println("Available options:");
    for (Object obj : m_optionsDef.getOptions()) {
        Option opt = (Option) obj;
        System.out.println(
                "     -" + opt.getArgName() + ", --" + opt.getLongOpt() + " : " + opt.getDescription());
    }
    System.out.println();
}

From source file:net.nicholaswilliams.java.licensing.licensor.interfaces.cli.spi.TestCliOptionsBuilder.java

@Test
public void testWithDescription() {
    Option option = this.builder.withDescription("testDescription01").create("test");
    assertNotNull("The option should not be null.", option);
    assertEquals("The description is not correct.", "testDescription01", option.getDescription());
}

From source file:com.bc.fiduceo.ingest.IngestionToolTest.java

@Test
public void testGetOptions() {
    final Options options = IngestionTool.getOptions();
    assertNotNull(options);/*ww w.j  av  a2s  .  com*/

    final Option helpOption = options.getOption("h");
    assertNotNull(helpOption);
    assertEquals("h", helpOption.getOpt());
    assertEquals("help", helpOption.getLongOpt());
    assertEquals("Prints the tool usage.", helpOption.getDescription());
    assertFalse(helpOption.hasArg());

    final Option sensorOption = options.getOption("sensor");
    assertNotNull(sensorOption);
    assertEquals("s", sensorOption.getOpt());
    assertEquals("sensor", sensorOption.getLongOpt());
    assertEquals("Defines the sensor to be ingested.", sensorOption.getDescription());
    assertTrue(sensorOption.hasArg());

    final Option configOption = options.getOption("config");
    assertNotNull(configOption);
    assertEquals("c", configOption.getOpt());
    assertEquals("config", configOption.getLongOpt());
    assertEquals("Defines the configuration directory. Defaults to './config'.", configOption.getDescription());
    assertTrue(configOption.hasArg());

    final Option startTime = options.getOption("start-time");
    assertNotNull(startTime);
    assertEquals("start", startTime.getOpt());
    assertEquals("start-time", startTime.getLongOpt());
    assertEquals("Define the starting time of products to inject.", startTime.getDescription());
    assertTrue(startTime.hasArg());

    final Option endTime = options.getOption("end-time");
    assertNotNull(endTime);
    assertEquals("end", endTime.getOpt());
    assertEquals("end-time", endTime.getLongOpt());
    assertEquals("Define the ending time of products to inject.", endTime.getDescription());
    assertTrue(endTime.hasArg());

    final Option version = options.getOption("version");
    assertNotNull(version);
    assertEquals("v", version.getOpt());
    assertEquals("version", version.getLongOpt());
    assertEquals("Define the sensor version.", version.getDescription());
    assertTrue(version.hasArg());
}

From source file:com.somerledsolutions.pa11y.client.cli.OptionsBuilderTest.java

private void assertHelpOption(Options options) {
    Option helpOption = options.getOption("h");
    assertEquals("h", helpOption.getOpt());
    assertEquals("Help", helpOption.getArgName());
    assertEquals("help", helpOption.getLongOpt());
    assertEquals("Shows this help", helpOption.getDescription());
}