Example usage for org.apache.commons.cli2.util HelpFormatter setGroup

List of usage examples for org.apache.commons.cli2.util HelpFormatter setGroup

Introduction

In this page you can find the example usage for org.apache.commons.cli2.util HelpFormatter setGroup.

Prototype

public void setGroup(Group group) 

Source Link

Document

Sets the Group of Options to document

Usage

From source file:com.gsinnovations.howdah.CommandLineUtil.java

public static void printHelp(Group group) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setGroup(group);
    formatter.print();//from  ww  w .  j  ava 2  s .  c o  m
}

From source file:com.gsinnovations.howdah.CommandLineUtil.java

/**
 * Print the options supported by <code>GenericOptionsParser</code>.
 * In addition to the options supported by the job, passed in as the
 * group parameter.// w  ww.j  av  a2  s .c  o  m
 *
 * @param group job-specific command-line options.
 */
public static void printHelpWithGenericOptions(Group group) {
    org.apache.commons.cli.Options ops = new org.apache.commons.cli.Options();
    new GenericOptionsParser(new Configuration(), ops, new String[0]);
    org.apache.commons.cli.HelpFormatter fmt = new org.apache.commons.cli.HelpFormatter();
    fmt.printHelp("<command> [Generic Options] [Job-Specific Options]", "Generic Options:", ops, "");

    PrintWriter pw = new PrintWriter(System.out);
    HelpFormatter formatter = new HelpFormatter();
    formatter.setGroup(group);
    formatter.setPrintWriter(pw);
    formatter.printHelp();
    pw.flush();
}

From source file:egat.cli.Main.java

protected static void printHelp(Group options) {
    HelpFormatter hf = new HelpFormatter();
    hf.setShellCommand("egat");
    hf.setGroup(options);

    hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_GROUP_NAME);
    hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
    hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
    hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_OPTIONAL_CHILD_GROUP);
    hf.setFooter("egat is developed by Patrick R. Jordan (prjordan@umich.edu).");
    hf.print();//from w  ww . ja  v a2s .c  o m
}

From source file:hack.VectorScan.java

private static void printHelp(Group group) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setGroup(group);
    formatter.print();/*from  w ww.  ja va2  s  .com*/
}

From source file:com.ibm.jaql.util.shell.JaqlShellArguments.java

@SuppressWarnings("unchecked")
private static void printHelpAndExit(Exception e, String message, Group options) {
    if (message != null)
        System.err.println(message);
    if (e != null)
        e.printStackTrace();/*from   w ww . jav  a2s.  c o  m*/
    HelpFormatter hf = new HelpFormatter();
    hf.setShellCommand("jaqlshell");
    hf.setGroup(options);
    hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
    hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
    hf.print();
    hf.printHelp();
    System.exit(1);
}

From source file:com.martinkampjensen.thesis.Main.java

private static void printHelp(Group group) {
    final HelpFormatter hf = new HelpFormatter();

    hf.setGroup(group);
    hf.setShellCommand(Constant.SHELL_COMMAND);

    hf.print();//from  www .j  a v  a 2 s .  c o m
}

From source file:it.jnrpe.server.JNRPEServer.java

/**
 * Prints the JNRPE Server usage and, eventually, the error about the last
 * invocation.// w ww .jav a 2 s  .c o m
 * 
 * @param e
 *            The last error. Can be null.
 */
@SuppressWarnings("unchecked")
private static void printUsage(final Exception e) {
    printVersion();
    if (e != null) {
        System.out.println(e.getMessage() + "\n");
    }

    HelpFormatter hf = new HelpFormatter();

    StringBuilder sbDivider = new StringBuilder("=");
    while (sbDivider.length() < hf.getPageWidth()) {
        sbDivider.append("=");
    }

    // DISPLAY SETTING
    hf.getDisplaySettings().clear();
    hf.getDisplaySettings().add(DisplaySetting.DISPLAY_GROUP_EXPANDED);
    hf.getDisplaySettings().add(DisplaySetting.DISPLAY_PARENT_CHILDREN);

    // USAGE SETTING

    hf.getFullUsageSettings().clear();
    hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
    hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
    hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_PARENT_CHILDREN);
    hf.getFullUsageSettings().add(DisplaySetting.DISPLAY_GROUP_EXPANDED);

    hf.setDivider(sbDivider.toString());

    hf.setGroup(configureCommandLine());
    hf.print();
    System.exit(0);
}

From source file:it.jnrpe.client.JNRPEClient.java

/**
 * Prints usage instrunctions and, eventually, an error message about the
 * latest execution./*from  w ww.  j  a v a 2  s .  c  om*/
 * 
 * @param e
 *            The exception error
 */
@SuppressWarnings("unchecked")
private static void printUsage(final Exception e) {
    printVersion();

    StringBuilder sbDivider = new StringBuilder("=");

    if (e != null) {
        System.out.println(e.getMessage() + "\n");
    }

    HelpFormatter hf = new HelpFormatter();
    while (sbDivider.length() < hf.getPageWidth()) {
        sbDivider.append('=');
    }

    // DISPLAY SETTING
    Set displaySettings = hf.getDisplaySettings();

    displaySettings.clear();
    displaySettings.add(DisplaySetting.DISPLAY_GROUP_EXPANDED);
    displaySettings.add(DisplaySetting.DISPLAY_PARENT_CHILDREN);

    // USAGE SETTING
    Set usageSettings = hf.getFullUsageSettings();
    usageSettings.clear();
    usageSettings.add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
    usageSettings.add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
    usageSettings.add(DisplaySetting.DISPLAY_PARENT_CHILDREN);
    usageSettings.add(DisplaySetting.DISPLAY_GROUP_EXPANDED);

    hf.setDivider(sbDivider.toString());

    hf.setGroup(configureCommandLine());
    hf.print();
}

From source file:br.edu.ifpb.pos.command.CommandExecute.java

@Override
public void run() throws ResourceException {
    System.out.println("");

    if (line.hasOption("--help")) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.setGroup(options);
        helpFormatter.setDivider(" ");
        helpFormatter.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_OUTER);
        helpFormatter.print();//from   w  ww  .j av a  2  s . com
    }

    if (line.hasOption("--insert")) {
        Representation representation = new StringRepresentation((CharSequence) line.getValue("--insert"),
                MediaType.APPLICATION_JSON);
        ClientResource clientResource;
        if (line.getValue("--type").equals(TYPE_PERSON)) {
            clientResource = new ClientResource(URL + "/person");
        } else {
            clientResource = new ClientResource(URL + "/user");
        }
        try {
            clientResource.post(representation).write(System.out);
            System.out.println("");
        } catch (IOException ex) {
            Logger.getLogger(CommandExecute.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    if (line.hasOption("--update")) {
        String entity = (String) line.getValue("--update");
        Representation representation = new StringRepresentation(entity, MediaType.APPLICATION_JSON);
        ClientResource clientResource;
        Gson gson = new Gson();
        if (line.getValue("--type").equals(TYPE_PERSON)) {
            Key key = gson.fromJson(entity, Key.class);
            clientResource = new ClientResource(URL + "/person/" + key.getKey());
        } else {
            Key key = gson.fromJson(entity, Key.class);
            clientResource = new ClientResource(URL + "/user/" + key.getKey());
        }
        try {
            clientResource.put(representation).write(System.out);
            System.out.println("");
        } catch (IOException ex) {
            Logger.getLogger(CommandExecute.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    if (line.hasOption("--delete")) {
        ClientResource clientResource;
        String key = getKey(line.getValue("--delete").toString());

        if (line.getValue("--type").equals(TYPE_PERSON)) {
            clientResource = new ClientResource(URL + "/person/" + key);
        } else {
            clientResource = new ClientResource(URL + "/user/" + key);

        }
        try {
            clientResource.delete().write(System.out);
            System.out.println("");
        } catch (IOException ex) {
            Logger.getLogger(CommandExecute.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    if (line.hasOption("--select")) {
        ClientResource clientResource;
        String key = getKey(line.getValue("--select").toString());
        if (line.getValue("--type").equals(TYPE_PERSON)) {
            clientResource = new ClientResource(URL + "/person/" + key);
        } else {
            clientResource = new ClientResource(URL + "/user/" + key);
        }
        Representation representation = clientResource.get();
        try {
            System.out.println(representation.getText());
        } catch (IOException ex) {
            Logger.getLogger(CommandExecute.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.digitalpebble.behemoth.tika.TikaDriver.java

public int run(String[] args) throws Exception {

    final FileSystem fs = FileSystem.get(getConf());
    GroupBuilder gBuilder = new GroupBuilder().withName("Options:");
    List<Option> options = new ArrayList<Option>();
    Option inputOpt = buildOption("input", "i", "The input path", true, true, null);
    options.add(inputOpt);/*from   ww w. ja  v  a2s.com*/
    Option outOpt = buildOption("output", "o", "The output path", true, true, null);
    options.add(outOpt);
    Option tikaOpt = buildOption("tikaProcessor", "t",
            "The fully qualified name of a TikaProcessor class that handles the extraction (optional)", true,
            false, null);
    options.add(tikaOpt);
    Option mimeTypeOpt = buildOption("mimeType", "m", "The mime type to use (optional)", true, false, "");
    options.add(mimeTypeOpt);
    for (Option opt : options) {
        gBuilder = gBuilder.withOption(opt);
    }

    Group group = gBuilder.create();

    try {
        Parser parser = new Parser();
        parser.setGroup(group);
        // TODO catch exceptions with parsing of opts
        CommandLine cmdLine = parser.parse(args);
        Path inputPath = new Path(cmdLine.getValue(inputOpt).toString());
        Path outputPath = new Path(cmdLine.getValue(outOpt).toString());
        String handlerName = null;
        if (cmdLine.hasOption(tikaOpt)) {
            handlerName = cmdLine.getValue(tikaOpt).toString();
        }

        JobConf job = new JobConf(getConf());
        job.setJarByClass(this.getClass());

        if (cmdLine.hasOption(mimeTypeOpt)) {
            String mimeType = cmdLine.getValue(mimeTypeOpt).toString();
            job.set(TikaConstants.TIKA_MIME_TYPE_KEY, mimeType);
        }

        if (handlerName != null && handlerName.equals("") == false) {
            job.set(TIKA_PROCESSOR_KEY, handlerName);
        }

        job.setJobName("Tika : " + inputPath.toString());

        job.setInputFormat(SequenceFileInputFormat.class);
        job.setOutputFormat(SequenceFileOutputFormat.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(BehemothDocument.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(BehemothDocument.class);

        job.setMapperClass(TikaMapper.class);

        boolean isFilterRequired = BehemothReducer.isRequired(job);
        if (isFilterRequired)
            job.setReducerClass(BehemothReducer.class);
        else {
            job.setNumReduceTasks(0);
        }

        FileInputFormat.addInputPath(job, inputPath);
        FileOutputFormat.setOutputPath(job, outputPath);

        try {
            long start = System.currentTimeMillis();
            JobClient.runJob(job);
            long finish = System.currentTimeMillis();
            if (log.isInfoEnabled()) {
                log.info("TikaDriver completed. Timing: " + (finish - start) + " ms");
            }
        } catch (Exception e) {
            log.error("Exception", e);
            return -1;
            // don't delete the output as some of it could be used
            // fs.delete(outputPath, true);
        } finally {
        }

    } catch (OptionException e) {
        log.error("OptionException", e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.setGroup(group);
        formatter.print();
        return -1;
    }

    return 0;
}