コード例 #1
0
  public void testArgumentList() throws Exception {
    class A implements Runnable {
      @Argument List<String> s;

      public void run() {}
    }

    //
    CommandDescriptor<A> desc = CommandFactory.DEFAULT.create(A.class);
    InvocationMatcher<A> analyzer = desc.matcher();

    //
    A a = new A();
    analyzer.parse("\" \" b").invoke(a);
    assertEquals(Arrays.asList(" ", "b"), a.s);

    //
    a = new A();
    analyzer.parse("\"'\" b").invoke(a);
    assertEquals(Arrays.asList("'", "b"), a.s);

    //
    a = new A();
    analyzer.parse("\"a b\" c").invoke(a);
    assertEquals(Arrays.asList("a b", "c"), a.s);
  }
コード例 #2
0
  public void testOption() throws Exception {
    class A implements Runnable {
      @Option(names = "o")
      String s;

      public void run() {}
    }

    //
    CommandDescriptor<A> desc = CommandFactory.DEFAULT.create(A.class);
    InvocationMatcher<A> matcher = desc.matcher("main");

    //
    A a = new A();
    matcher.parse("-o \" \"").invoke(a);
    assertEquals(" ", a.s);

    //
    a = new A();
    matcher.parse("-o \"'\"").invoke(a);
    assertEquals("'", a.s);

    //
    a = new A();
    matcher.parse("-o \" a b").invoke(a);
    assertEquals(" a b", a.s);
  }
コード例 #3
0
  public void testOption() throws Exception {

    //
    HelpDescriptor<A> desc = new HelpDescriptor<A>(CommandFactory.DEFAULT.create(A.class));
    OptionDescriptor help = desc.getOption("-h");
    assertNotNull(help);
    OptionDescriptor foo = desc.getOption("-f");
    assertNotNull(foo);
    CommandDescriptor<A> bar = desc.getSubordinate("bar");
    OptionDescriptor barHelp = bar.getOption("-h");
    assertNull(barHelp);

    //
    InvocationMatcher<A> matcher = desc.invoker("main");
    InvocationMatch<A> match = matcher.match("");
    CommandInvoker<A> invoker = match.getInvoker();
    invoker.invoke(new A());

    match = matcher.match("-f foo_value bar");
    invoker = match.getInvoker();
    assertEquals("invoked:foo_value", invoker.invoke(new A()));
  }