Package com.martiansoftware.jsap

Examples of com.martiansoftware.jsap.JSAP


  private static ScigestConfiguration sc;
 
  public static void main(String[] args) throws ConfigurationException, IOException, JSAPException {
   
    sc = new ScigestConfiguration();
    JSAP jsap = new JSAP();

    CmdParser cmdParser = new CmdParser();
    UnflaggedOption command = new UnflaggedOption("command")
                      .setStringParser(cmdParser)
                      .setRequired(true);
   
    jsap.registerParameter(command);
   
    Switch local = new Switch("local")
                .setShortFlag('l')
                .setLongFlag("local");
   
    jsap.registerParameter(local);
   
    UnflaggedOption key = new UnflaggedOption("key")
                      .setStringParser(JSAP.STRING_PARSER)
                      .setRequired(false)
                      .setGreedy(false);
   
    jsap.registerParameter(key);

    UnflaggedOption val = new UnflaggedOption("value")
                      .setStringParser(JSAP.STRING_PARSER)
                      .setRequired(false)
                      .setGreedy(false);
   
    jsap.registerParameter(val);
   
    JSAPResult config = jsap.parse(args);
       
    usage(jsap, config);
   
    String subCmd = config.getString("command");
View Full Code Here


*
* @author Christophe Pollet
*/
public class Main {
    public static void main(String[] args) throws ParserException, IOException, DateTimeException, JSAPException {
        JSAP jsap = new ArgumentsParser();
        JSAPResult config = jsap.parse(args);

        if (!config.success() || config.getBoolean("help")) {
            System.out.println();
            for (Iterator errs = config.getErrorMessageIterator(); errs.hasNext();) {
                System.out.println("Error: " + errs.next());
            }
            System.out.println();
            System.out.println("Usage: java " + Main.class.getName());
            System.out.println("\t" + jsap.getUsage());
            System.out.println();
            System.out.println(jsap.getHelp());
            System.exit(0);
        }

        Database database = new Database();
        Parser parser     = new Parser(database);
View Full Code Here

    {
      throw new CommandOperationException(ex);
    }
   
    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);
View Full Code Here

    return TestRunner.TestType.valueOf(testType.replaceAll("UTs and ATs", "UTsAndATs"));
  }

  private JSAP createArgsParser(RunMode mode) throws CommandOperationException
  {
    JSAP argsParser = new JSAP();
    try
    {
      if (mode == RunMode.RUN_TESTS)
      {
        argsParser.registerParameter(new UnflaggedOption("dir").setRequired(true).setHelp("the directory from which to start looking for tests"));
        argsParser.registerParameter(new UnflaggedOption("testType").setDefault("UTsAndATs").setStringParser(EnumeratedStringParser.getParser("UTs;ATs;ITs;UTsAndATs;ALL;", true)).setHelp("(UTs|ATs|ITs|ALL)"));
      }
      argsParser.registerParameter(new FlaggedOption("browsers").setShortFlag('b').setList(true).setListSeparator(',').setHelp("you can use ALL to specify that the tests should be run on all browsers"));
      // this isnt in the if block above so it appears as the last option in the help menu
      if (mode == RunMode.RUN_TESTS)
      {
        argsParser.registerParameter(new Switch(REPORT_SWITCH).setLongFlag(REPORT_SWITCH).setDefault("false").setHelp("if supplied, generate the HTML reports after running tests"));
      }
      if (mode == RunMode.RUN_SERVER)
      {
        argsParser.registerParameter(new Switch(NO_BROWSER_SWITCH).setLongFlag(NO_BROWSER_SWITCH).setDefault("false").setHelp("you can start the test-server on it's own without a browser"));
      }
    }
    catch (Exception ex)
    {
      throw new CommandOperationException("Error initialising configuration.", ex);
View Full Code Here

   * @param args the command line.
   * @throws Exception for reasons made clear later in the manual.
   */
  // @@snip:Manual_HelloWorld_6@@
  public static void main(String[] args) throws Exception {
    JSAP jsap = new JSAP();
   
    FlaggedOption opt1 = new FlaggedOption("count")
                .setStringParser(JSAP.INTEGER_PARSER)
                .setDefault("1")
                .setRequired(true)
                .setShortFlag('n')
                .setLongFlag(JSAP.NO_LONGFLAG);
               
    opt1.setHelp("The number of times to say hello.");
    jsap.registerParameter(opt1);
   
    Switch sw1 = new Switch("verbose")
            .setShortFlag('v')
            .setLongFlag("verbose");
    sw1.setHelp("Requests verbose output.");
    jsap.registerParameter(sw1);
   
    UnflaggedOption opt2 = new UnflaggedOption("name")
                .setStringParser(JSAP.STRING_PARSER)
                .setDefault("World")
                .setRequired(true)
                .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) {
View Full Code Here

* @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
*/
public class TestPropertyDefaultSource extends TestCase {

    public void testUnexpectedProperties() {
        JSAP jsap = new JSAP();
        try {
            jsap.registerParameter(
                new FlaggedOption(
                    "testflagged",
                    StringStringParser.getParser(),
                    JSAP.NO_DEFAULT,
                    JSAP.NOT_REQUIRED,
                    'f',
                    "flagged"));
            jsap.registerParameter(
                new UnflaggedOption(
                    "testunflagged",
                    StringStringParser.getParser(),
                    JSAP.NO_DEFAULT,
                    JSAP.NOT_REQUIRED,
                    JSAP.NOT_GREEDY));
            jsap.registerParameter(new Switch("testswitch", 's', "switch"));
        } catch (Throwable t) {
            fail(t.getMessage());
        }

        Properties p = new Properties();
        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();
View Full Code Here

   * @param args the command line.
   * @throws Exception for reasons made clear later in the manual.
   */
  // @@snip:Manual_HelloWorld_8@@
  public static void main(String[] args) throws Exception {
    JSAP jsap = new JSAP();
   
    FlaggedOption opt1 = new FlaggedOption("count")
                .setStringParser(JSAP.INTEGER_PARSER)
                .setDefault("1")
                .setRequired(true)
                .setShortFlag('n')
                .setLongFlag(JSAP.NO_LONGFLAG);

    opt1.setHelp("The number of times to say hello.");
    jsap.registerParameter(opt1);
   
    QualifiedSwitch sw1 = (QualifiedSwitch)
                (new QualifiedSwitch("verbose")
                .setShortFlag('v')
                .setLongFlag("verbose")
                .setList(true)
                .setListSeparator(','));
   
    sw1.setHelp("Requests verbose output.");
    jsap.registerParameter(sw1);
   
    UnflaggedOption opt2 = new UnflaggedOption("name")
                .setStringParser(JSAP.STRING_PARSER)
                .setDefault("World")
                .setRequired(true)
                .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");
View Full Code Here

* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
*/
public class Example1 {

    public static void main(String[] args) throws Exception {
        JSAP jsap = new JSAP();

        FlaggedOption f1 = new FlaggedOption("myflagged");
        f1.setShortFlag('f').setLongFlag("flagged").setRequired(true).setHelp(
            "do flagged stuff");
        jsap.registerParameter(f1);

        UnflaggedOption f2 = new UnflaggedOption("myunflagged");
        f2.setGreedy(JSAP.GREEDY).setHelp("input files");
        jsap.registerParameter(f2);

        Switch sw1 = new Switch("myswitch");
        sw1.setLongFlag("verbose").setHelp(
            "display extra logging information.");
        jsap.registerParameter(sw1);

        System.out.println("Usage: Example1 " + jsap.getUsage());
        System.out.println(jsap.getHelp());
    }
View Full Code Here

   * @param args the command line.
   * @throws Exception for reasons made clear later in the manual.
   */
  // @@snip:Manual_HelloWorld_4@@
  public static void main(String[] args) throws Exception {
    JSAP jsap = new JSAP();

    FlaggedOption opt1 = new FlaggedOption("count")
                .setStringParser(JSAP.INTEGER_PARSER)
                .setDefault("1")
                .setRequired(true)
                .setShortFlag('n')
                .setLongFlag(JSAP.NO_LONGFLAG);

    jsap.registerParameter(opt1);

    Switch sw1 = new Switch("verbose")
            .setShortFlag('v')
            .setLongFlag("verbose");

    jsap.registerParameter(sw1);

    // Create an unflagged option called "names" that we'll use to
    // say hello to particular people.
    // To make it more interesting, we'll make it "greedy", so
    // it consumes all remaining unflagged tokens on the command line
    // as multiple values
    UnflaggedOption opt2 = new UnflaggedOption("name")
                .setStringParser(JSAP.STRING_PARSER)
                .setDefault("World")
                .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(
View Full Code Here

   * @param args the command line.
   * @throws Exception for reasons made clear later in the manual.
   */
  // @@snip:Manual_HelloWorld_2@@
  public static void main(String[] args) throws Exception {
    JSAP jsap = new JSAP();
   
    // create a flagged option we'll access using the id "count".
    // it's going to be an integer, with a default value of 1.
    // it's required (which has no effect since there's a default value)
    // its short flag is "n", so a command line containing "-n 5"
    //    will print our message five times.
    // it has no long flag.
    FlaggedOption opt1 = new FlaggedOption("count")
                .setStringParser(JSAP.INTEGER_PARSER)
                .setDefault("1")
                .setRequired(true)
                .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.JSAP

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.