Package com.martiansoftware.jsap

Examples of com.martiansoftware.jsap.JSAPResult


    JSAPResult parsedArgs = parseArgs(args);
    return doCommand(parsedArgs);
  }
 
  private JSAPResult parseArgs(String[] args) throws ArgumentParsingException {
    JSAPResult parsedArgs = argsParser.parse(args);
   
    if(!parsedArgs.success()) {
      List<String> errorMessages = new ArrayList<>();
      Iterator<?> paramsIterator = parsedArgs.getBadParameterIDIterator();
     
      while(paramsIterator.hasNext()) {
        String paramName = (String) paramsIterator.next();
        errorMessages.add(parsedArgs.getException(paramName).getMessage());
      }
     
      throw new ArgumentParsingException(Joiner.on("\n  ").join(errorMessages), this);
    }
   
View Full Code Here


    }
   
    File resultDir = getResultsDir();
    JSAP argsParser = createArgsParser(mode);

    JSAPResult config = argsParser.parse(args);

    boolean success = true;
    if (!config.success())
    {
      throw new CommandArgumentsException("Invalid arguments provided.", testCommand);
    }
    else
    {
      TestRunner testRunner;
     
      try
      {       
        boolean testServerOnly = mode == RunMode.RUN_SERVER;
        boolean generateReports = (mode == RunMode.RUN_TESTS) && config.getBoolean(REPORT_SWITCH);
        boolean noBrowser = (mode == RunMode.RUN_SERVER) && config.getBoolean(NO_BROWSER_SWITCH);
       
        testRunner = new TestRunner(configFile, resultDir, Arrays.asList(config.getStringArray("browsers")), testServerOnly, noBrowser, generateReports);
      }
      catch (Exception ex)
      {
        throw new CommandOperationException("Error parsing test runner configuration file '" + configFile.getAbsolutePath() + "'.", ex);
      }

      if (mode == RunMode.RUN_SERVER)
      {
        try
        {
          testRunner.runServer();
        }
        catch (Exception ex)
        {
          throw new CommandOperationException("Error running server.", ex);
        }
      }
      else
      {
        try
        {
          success = testRunner.runTests(new File(config.getString("dir")), getTestTypeEnum(config.getString("testType")));
        }
        catch (Exception ex)
        {
          testRunner.showExceptionInConsole(ex);
          throw new CommandOperationException("Error running tests.", ex);
View Full Code Here

   *          An array of command line arguments to parse.
   */
  @Override
  public JSAPResult parse(String[] args)
  {
    JSAPResult result = super.parse(args);

    if (result.contains("help"))
    {
      displayUsage();
      if (exit_after_help)
        System.exit(0);

      return result;
    }

    // if we find a config-file being specified, read it and append it to our
    // arguments!
    if (enable_config && result.contains("config-file"))
    {
      try
      {
        String[] config_commands = CommandLineTokenizer.tokenize(getArgumentsFromFile(result.getFile("config-file")));

        String[] combined_commands = new String[args.length + config_commands.length];
        for (int i = 0; i < args.length; i++)
          combined_commands[i] = args[i];
        for (int i = 0; i < config_commands.length; i++)
          combined_commands[args.length + i] = config_commands[i];

        result = super.parse(combined_commands);
      }
      catch (IOException e)
      {
        result.addException("config-file", e);
      }
    }

    if (result.contains("help") && result.getBoolean("help"))
    {
      displayUsage();
      if (exit_after_help)
        System.exit(0);
    }
View Full Code Here

    app.registerParameter(new FlaggedOption("output", AppConfig.FILE_PARSER.setMustExist(false), "output.sage", false, 'O', "output", "Write SAGE output here (default: output.sage).").setUsageName("sage-file"));
    app.registerParameter(new FlaggedOption("l1-weight", AppConfig.KEYVALUE_PARSER, AppConfig.NO_DEFAULT, false, '1', "l1-weight", "Set L1 regularization weight.").setAllowMultipleDeclarations(true).setUsageName("key=weight"));
    app.registerParameter(new FlaggedOption("iterations", AppConfig.POSITIVE_INTEGER_PARSER, "10", false, 'i', "iterations", "Number of iterations to optimize for (default: infinity).").setUsageName("N"));
    app.registerParameter(new Switch("overwrite", AppConfig.NO_SHORTFLAG, "overwrite", "Overwrite output file?"));

    JSAPResult result = app.parse(args);

    if (!result.success())
    {
      for (java.util.Iterator errs = result.getErrorMessageIterator(); errs.hasNext();)
        System.err.println("Error: " + errs.next());

      System.err.println("\nUsage: java " + DemoApp.class.getName());
      System.err.println("            " + app.getUsage() + "\n" + app.getHelp());
      System.exit(1);
    }

    System.out.println("Parameters passed in:");
    System.out.format("  input-docs %s\n", result.getFile("input-docs"));
    System.out.format("  output %s\n", result.getFile("input-docs"));
    System.out.format("  iterations %d\n", result.getInt("iterations"));
    System.out.format("  overwrite? %s\n", result.getBoolean("overwrite") ? "true" : "false");

    SimpleEntry<String, Double>[] weights = KeyValueParser.getKeyValueArray("l1-weight", result);
    for (SimpleEntry<String, Double> se : weights)
      System.out.format("  l1-weight %s = %f\n", se.getKey(), se.getValue());
  }
View Full Code Here

                .setGreedy(true);
   
    opt2.setHelp("One or more names of people you would like to greet.");
    jsap.registerParameter(opt2);
   
    JSAPResult config = jsap.parse(args)

    if (!config.success()) {
      System.err.println();
      System.err.println("Usage: java "
                + Manual_HelloWorld_6.class.getName());
      System.err.println("                "
                + jsap.getUsage());
      System.err.println();
      // show full help as well
      System.err.println(jsap.getHelp());
      System.exit(1);
    }
   
    String[] names = config.getStringArray("name");
    for (int i = 0; i < config.getInt("count"); ++i) {
      for (int j = 0; j < names.length; ++j) {
        System.out.println((config.getBoolean("verbose") ? "Hello" : "Hi")
                + ", "
                + names[j]
                + "!");
      }
    }
View Full Code Here

        p.setProperty("s", "true");
        p.setProperty("flagged", "My Flagged Value");
        PropertyDefaultSource pds = new PropertyDefaultSource(p);
        jsap.registerDefaultSource(pds);

        JSAPResult result = jsap.parse("");
        assertTrue(result.success());

        assertEquals(result.getBoolean("testswitch"), true);
        assertEquals(result.getString("testflagged"), "My Flagged Value");

        p.setProperty("unexpected", "jsap won't know what to do with this");
        result = jsap.parse("");
        assertFalse(result.success());

        /*
        for (java.util.Iterator i1 = result.getBadParameterIDIterator(); i1.hasNext(); ) {
            String badID = (String) i1.next();
            for (java.util.Iterator i2 = result.getExceptionIterator(badID); i2.hasNext(); ) {
View Full Code Here

                .setGreedy(true);
   
    opt2.setHelp("One or more names of people you would like to greet.");
    jsap.registerParameter(opt2);
   
    JSAPResult config = jsap.parse(args)

    if (!config.success()) {
     
      System.err.println();

      // print out specific error messages describing the problems
      // with the command line, THEN print usage, THEN print full
      // help.  This is called "beating the user with a clue stick."
      for (java.util.Iterator errs = config.getErrorMessageIterator();
          errs.hasNext();) {
        System.err.println("Error: " + errs.next());
      }
     
      System.err.println();
      System.err.println("Usage: java "
                + Manual_HelloWorld_8.class.getName());
      System.err.println("                "
                + jsap.getUsage());
      System.err.println();
      System.err.println(jsap.getHelp());
      System.exit(1);
    }
   
    String[] names = config.getStringArray("name");
    String[] languages = config.getStringArray("verbose");
    for (int i = 0; i < languages.length; ++i) {
      System.out.println("language=" + languages[i]);
    }
    for (int i = 0; i < config.getInt("count"); ++i) {
      for (int j = 0; j < names.length; ++j) {
        System.out.println((config.getBoolean("verbose") ? "Hello" : "Hi")
                + ", "
                + names[j]
                + "!");
      }
    }
View Full Code Here

                .setRequired(false)
                .setGreedy(true);

    jsap.registerParameter(opt2);

    JSAPResult config = jsap.parse(args);

    String[] names = config.getStringArray("name");
    for (int i = 0; i < config.getInt("count"); ++i) {
      for (int j = 0; j < names.length; ++j) {
        System.out.println(
          (config.getBoolean("verbose") ? "Hello" : "Hi")
            + ", "
            + names[j]
            + "!");
      }
    }
View Full Code Here

        new UnflaggedOption( "name", JSAP.STRING_PARSER, "World", JSAP.REQUIRED, JSAP.GREEDY,
          "One or more names of people you would like to greet." )
      }
    );
   
    JSAPResult config = jsap.parse(args)
    if ( jsap.messagePrinted() ) System.exit( 1 );
       
    String[] names = config.getStringArray("name");
    String[] languages = config.getStringArray("verbose");
    for (int i = 0; i < languages.length; ++i) {
      System.out.println("language=" + languages[i]);
    }
    for (int i = 0; i < config.getInt("count"); ++i) {
      for (int j = 0; j < names.length; ++j) {
        System.out.println((config.getBoolean("verbose") ? "Hello" : "Hi")
                + ", "
                + names[j]
                + "!");
      }
    }
View Full Code Here

                .setShortFlag('n')
                .setLongFlag(JSAP.NO_LONGFLAG);
   
    jsap.registerParameter(opt1);

    JSAPResult config = jsap.parse(args)

    for (int i = 0; i < config.getInt("count"); ++i) {
      System.out.println("Hello, World!");
    }
  }
View Full Code Here

TOP

Related Classes of com.martiansoftware.jsap.JSAPResult

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.