Package org.kohsuke.args4j

Examples of org.kohsuke.args4j.CmdLineParser


  @SuppressWarnings("PMD.DataflowAnomalyAnalysis")
  protected int execute(final String[] args, final PrintWriter outputWriter) {
    int returnValue;
   
    final Context context = getContextInstance(new HashMap<String,String>());
    CmdLineParser parser = new CmdLineParser(context);
   
    // execute the app
    try {
      parser.parseArgument(args);
     
      // capture start time
      final long startTime = System.currentTimeMillis();
     
      // build the config element
      final ElementBuilder elementBuilder = getElementBuilderInstance();
      final JMXEval jmxEval = (JMXEval) elementBuilder.build(context);
   
      // process the evals
      jmxEval.process(context);

      // set elapsed time in seconds
      final double elapsedTime = (System.currentTimeMillis() - startTime) / 1000;
      context.getResponse().addPerfData(new PerfDataResult(
          "time", String.valueOf(elapsedTime), "s", null, null, null, null));
     
      // print response
      outputWriter.println(context.getResponse());
     
      // return status value to indicate execution status
      returnValue = context.getResponse().getStatus().getValue();
     
    } catch (ConfigurationException e) {
     
      // print exception
      outputWriter.println(e.getMessage());
      if (e.getCause() != null) {
        outputWriter.println("Error details:");
        e.printStackTrace(outputWriter);
      }
     
      // indicate error by returning a non-zero value
      returnValue = Status.UNKNOWN.getValue();
     
    } catch (EvalException e) {
     
      // print exception
      outputWriter.println(e.getMessage());
      if (e.getCause() != null) {
        outputWriter.println("Error details:");
        e.printStackTrace(outputWriter);
      }
     
      // indicate error by returning a non-zero value
      returnValue = e.getStatus().getValue();
    } catch (CmdLineException e) {
      e.printStackTrace();
      // print usage information
      System.err.println(e.getMessage());
      System.err.print("java -jar jmxeval.jar ");
      parser.printSingleLineUsage(System.err);
      System.err.println();
      parser.printUsage(System.err);
      returnValue = Status.UNKNOWN.getValue();
    }
   
    return returnValue;
  }
View Full Code Here


    /**
     * Parse the command line args usin arg4j.
     */
    public void parseCmdLineArgs(String[] args, CmdLineArgs opts) throws Exception {
      
        CmdLineParser parser = new CmdLineParser(opts);
        try {
            parser.parseArgument(args);
        } catch (CmdLineException e) {
            System.err.println(e.getMessage());
            System.err.println("java -jar jee2pctest-client.jar [options...]");
            System.err.println("   container.properties expected in the current working dir. ");
            // print the list of available options
            parser.printUsage(System.err);
            System.err.println();
            System.exit(1);
        }
    }
View Full Code Here

  private SoyMsgExtractor() {}


  private void execMain(String[] args) throws IOException, SoySyntaxException {

    final CmdLineParser cmdLineParser = MainClassUtils.parseFlags(this, args, USAGE_PREFIX);

    final Function<String, Void> exitWithErrorFn = new Function<String, Void>() {
      @Override public Void apply(String errorMsg) {
        MainClassUtils.exitWithError(errorMsg, cmdLineParser, USAGE_PREFIX);
        return null;
View Full Code Here

   * @return The CmdLineParser that was created and used to parse the args (can be used to print
   *     usage text for flags when reporting errors).
   */
  public static CmdLineParser parseFlags(Object objWithFlags, String[] args, String usagePrefix) {

    CmdLineParser cmdLineParser = new CmdLineParser(objWithFlags);
    cmdLineParser.setUsageWidth(100);

    try {
      cmdLineParser.parseArgument(args);

    } catch(CmdLineException cle) {
      exitWithError(cle.getMessage(), cmdLineParser, usagePrefix);
    }

View Full Code Here

  private SoyParseInfoGenerator() {}


  private void execMain(String[] args) throws IOException, SoySyntaxException {

    final CmdLineParser cmdLineParser = MainClassUtils.parseFlags(this, args, USAGE_PREFIX);

    final Function<String, Void> exitWithErrorFn = new Function<String, Void>() {
      @Override public Void apply(String errorMsg) {
        MainClassUtils.exitWithError(errorMsg, cmdLineParser, USAGE_PREFIX);
        return null;
View Full Code Here

  }


  private void execMain(String[] args) throws IOException, SoySyntaxException {

    final CmdLineParser cmdLineParser = MainClassUtils.parseFlags(this, args, USAGE_PREFIX);

    final Function<String, Void> exitWithErrorFn = new Function<String, Void>() {
      @Override public Void apply(String errorMsg) {
        MainClassUtils.exitWithError(errorMsg, cmdLineParser, USAGE_PREFIX);
        return null;
View Full Code Here

  private SoyToJsSrcCompiler() {}


  private void execMain(String[] args) throws IOException, SoySyntaxException {

    final CmdLineParser cmdLineParser = MainClassUtils.parseFlags(this, args, USAGE_PREFIX);

    final Function<String, Void> exitWithErrorFn = new Function<String, Void>() {
      @Override public Void apply(String errorMsg) {
        MainClassUtils.exitWithError(errorMsg, cmdLineParser, USAGE_PREFIX);
        return null;
View Full Code Here

  }


  private void execMain(String[] args) throws IOException {

    CmdLineParser cmdLineParser = new CmdLineParser(this);
    cmdLineParser.setUsageWidth(100);
    try {
      cmdLineParser.parseArgument(args);

    } catch(CmdLineException cle) {
      System.err.println("\nError: " + cle.getMessage() + "\n\n");
      System.err.println(USAGE_PREFIX);
      cmdLineParser.printUsage(System.err);
      System.exit(1);
    }

    Injector injector = Guice.createInjector(new SoyModule(), new XliffMsgPluginModule());
View Full Code Here

import org.kohsuke.args4j.CmdLineParser;

public class Main {
    public static void main(String[] args) throws Exception {
        XTestOptions opts = new XTestOptions();
        CmdLineParser parser = new CmdLineParser(opts);
        try {
            parser.parseArgument(args);
        } catch (Exception e) {
            parser.printUsage(System.err);
            return;
        }

        XTest xts = new XTest(opts);
        xts.init();
View Full Code Here

     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        Date start = new Date();
        final CmdLineOptions opts = new CmdLineOptions();
        CmdLineParser parser = new CmdLineParser(opts);

        // parse command line options, give error message if no arguments passed
        try {
            parser.parseArgument(args);
        } catch (Exception e) {
            parser.printUsage(System.err);
            return;
        }
        if (opts.arguments.isEmpty()) {
            parser.printUsage(System.err);
            return;
        }
        VXQuery vxq = new VXQuery(opts);
        vxq.execute();
        // if -timing argument passed, show the starting and ending times
View Full Code Here

TOP

Related Classes of org.kohsuke.args4j.CmdLineParser

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.