Package org.apache.commons.cli2.util

Examples of org.apache.commons.cli2.util.HelpFormatter


    Parser parser = new Parser();
    parser.setHelpOption(help);
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
      return false;
    }
View Full Code Here


    // /////////////////////////////////////////////////////////////////////
    //
    // Help Formatter
    //
    // /////////////////////////////////////////////////////////////////////
    final HelpFormatter cmdHlp = new HelpFormatter("| ", "  ", " |", 75);
    cmdHlp.setShellCommand(getToolName());
    cmdHlp.setHeader("Help");
    cmdHlp.setFooter(new StringBuffer(getToolName()
        + " - GeoSolutions S.a.s (C) 2006 - v ").append(getVersion())
        .toString());
    cmdHlp
        .setDivider("|-------------------------------------------------------------------------|");

    // /////////////////////////////////////////////////////////////////////
    //
    // Close Parser
View Full Code Here

            } finally {
            }

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

        return 0;
    }
View Full Code Here

    public static void main(String[] args) {
        Group group = createModel();

        // configure a HelpFormatter
        HelpFormatter hf = new HelpFormatter();

        // configure a parser
        Parser p = new Parser();
        p.setGroup(group);
        p.setHelpFormatter(hf);
        p.setHelpTrigger("--help");

        CommandLine cl = p.parseAndHelp(args);

        // abort application if no CommandLine was parsed
        hf.setGroup(group);

        if (cl == null) {
            //hf.print();
            System.exit(-1);
        }

        try {
            getOutput(cl);
        } catch (Exception e) {
            System.out.println("Wrong input: " + e.getMessage());
            e.printStackTrace();
            hf.print();
        }
    }
View Full Code Here

        "Default Configuration File").withArgument(defaultFile).create());

    gBuilder.withOption(oBuilder.reset().withId(OPTION_G).withShortName("g").withLongName("genconf").withDescription(
        "Generate configuration file from pid").withArgument(pid2).create());

    FileValidator fValidator = VFSFileValidator.getExistingFileInstance().setBase(".");
    fValidator.setFile(false);
    // fValidator.setReadable(true);
    gBuilder.withOption(aBuilder.reset().withName(CONF_FILE).withDescription("is the wrapper.conf to use.  Name must be absolute or relative")
        .withMinimum(0).withMaximum(10).create());

    Validator pValidator = new Validator()
View Full Code Here

        if ((isExisting() && !f.exists()) || (isFile() && !f.getType().equals(FileType.FILE))
            || (isDirectory() && !f.getType().equals(FileType.FILE)) || (isHidden() && !f.isHidden())
            || (isReadable() && !f.isReadable()) || (isWritable() && !f.isWriteable()))
        {

          throw new InvalidArgumentException(name);
        }

        i.set(name);
      }
      catch (Exception ex)
      {
        ex.printStackTrace();
        throw new InvalidArgumentException(name);
      }
    }
  }
View Full Code Here

        for (Iterator it = values.iterator(); it.hasNext();)
        {
          String p = (String) it.next();
          if (!Pattern.matches("wrapper\\..*=.*", p))
          {
            throw new InvalidArgumentException(p);
          }
        }

      }

View Full Code Here

        // Note : This code doesnt belong here, it should be changed to
        // an can exec check in java 6
        for (String file : (List<String>)values) {
          File f = new File(file)
          if ( ! f.exists() ) {
            throw new InvalidArgumentException("Argument : " +
                f.getAbsolutePath() + " doesn't exist.");
          }
          if ( ! f.isFile() ) {
            throw new InvalidArgumentException("Argument : " +
                f.getAbsolutePath() + " is not a file.");
          }
          if ( ! f.canRead() ) {
            throw new InvalidArgumentException("Argument : " +
                f.getAbsolutePath() + " is not accessible");
          }
        }
      }     
    };
View Full Code Here

    fValidator.setFile(false);
    // fValidator.setReadable(true);
    gBuilder.withOption(aBuilder.reset().withName(CONF_FILE).withDescription("is the wrapper.conf to use.  Name must be absolute or relative")
        .withMinimum(0).withMaximum(10).create());

    Validator pValidator = new Validator()
    {

      public void validate(List values) throws InvalidArgumentException
      {
        for (Iterator it = values.iterator(); it.hasNext();)
View Full Code Here

    return builder.withLongName(name).withDescription(desc).create();
  }
 
  private void setupOptions(){

    final Validator fileValidator = new Validator(){
      public void validate(final List values) throws InvalidArgumentException {
        // Note : This code doesnt belong here, it should be changed to
        // an can exec check in java 6
        for (String file : (List<String>)values) {
          File f = new File(file)
          if ( ! f.exists() ) {
            throw new InvalidArgumentException("Argument : " +
                f.getAbsolutePath() + " doesn't exist.");
          }
          if ( ! f.isFile() ) {
            throw new InvalidArgumentException("Argument : " +
                f.getAbsolutePath() + " is not a file.");
          }
          if ( ! f.canRead() ) {
            throw new InvalidArgumentException("Argument : " +
                f.getAbsolutePath() + " is not accessible");
          }
        }
      }     
    };

    // Note: not extending CLI2's FileValidator, that overwrites
    // the String arg into File and causes ClassCastException
    // in inheritance tree.
    final Validator execValidator = new Validator(){
      public void validate(final List values) throws InvalidArgumentException {
        // Note : This code doesnt belong here, it should be changed to
        // an can exec check in java 6
        for (String file : (List<String>)values) {
          try{
View Full Code Here

TOP

Related Classes of org.apache.commons.cli2.util.HelpFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.