Package org.kohsuke.args4j

Examples of org.kohsuke.args4j.CmdLineParser.parseArgument()


    public void testParseWithOneParam() throws Exception {

        TestBean bean = new TestBean();

        CmdLineParser parser = new CmdLineParser(bean);
        parser.parseArgument("test1", "test2", "-opt", "test3");

        Assert.assertEquals(Arrays.asList("test3"), Arrays.asList(bean.stringArray));
        Assert.assertEquals(Arrays.asList("test1", "test2"), Arrays.asList(bean.rest));
    }
   
View Full Code Here


    public void testParseWithTwoParams() throws Exception {

        TestBean bean = new TestBean();

        CmdLineParser parser = new CmdLineParser(bean);
        parser.parseArgument("test1", "test2", "-opt", "test3", "-opt", "test4");

        Assert.assertEquals(Arrays.asList("test3", "test4"), Arrays.asList(bean.stringArray));
        Assert.assertEquals(Arrays.asList("test1", "test2"), Arrays.asList(bean.rest));
    }
   
View Full Code Here

        TestBean bean = new TestBean();
        bean.stringArray = null; // remove
       
        CmdLineParser parser = new CmdLineParser(bean);
        parser.parseArgument("test1", "test2", "-opt", "test3", "-opt", "test4");

        Assert.assertEquals(Arrays.asList("test3", "test4"), Arrays.asList(bean.stringArray));
        Assert.assertEquals(Arrays.asList("test1", "test2"), Arrays.asList(bean.rest));
    }   
}
View Full Code Here

    @Option(name="-b")
    int y;

    public void test1() throws Exception {
        CmdLineParser p = new CmdLineParser(this);
        p.parseArgument("-a","3","-b","2");
        assertEquals(x,3);
        assertEquals(y,2);

        p = new CmdLineParser(this);
        try {
View Full Code Here

        assertEquals(x,3);
        assertEquals(y,2);

        p = new CmdLineParser(this);
        try {
            p.parseArgument("-b","2");
            fail();
        } catch(CmdLineException e) {
            System.out.println(e.getMessage());
            assertTrue(e.getMessage().contains("-a"));
        }
View Full Code Here

    }

    protected Object subCommand(SubCommand c, final Parameters params) throws CmdLineException {
        Object subCmd = instantiate(c);
        CmdLineParser p = configureParser(subCmd,c);
        p.parseArgument(new AbstractList<String>() {
            @Override
            public String get(int index) {
                try {
                    return params.getParameter(index+1);
                } catch (CmdLineException e) {
View Full Code Here

    }

    public void parseArgs(String[] args) throws IOException {
        CmdLineParser parser = new CmdLineParser(this);
        try {
            parser.parseArgument(args);
        } catch( CmdLineException e ) {
            int start = e.getMessage().indexOf('"')+1;
            int end   = e.getMessage().lastIndexOf('"');
            String wrongArgument = e.getMessage().substring(start, end);
            System.err.println("Unknown argument: " + wrongArgument);
View Full Code Here

        // here 80 is also the default
        parser.setUsageWidth(80);

        try {
            // parse the arguments.
            parser.parseArgument(args);

            // you can parse additional arguments if you want.
            // parser.parseArgument("more","args");

            // after parsing arguments, you should check
View Full Code Here

   */
  public static void parseOptions(MoeOptions options, List<String> args) {
    CmdLineParser parser = new CmdLineParser(options);
    boolean parseError = false;
    try {
      parser.parseArgument(processArgs(args).toArray(new String[] {}));
    } catch (CmdLineException e) {
      logger.log(Level.SEVERE, "Failure", e);
      parseError = true;
    }

View Full Code Here

    CmdLineParser parser = new CmdLineParser(flags);
    boolean parseError = false;
    try {
      List<String> nextArgs = Lists.newArrayList(args);
      nextArgs.remove(0); // Remove the directive.
      parser.parseArgument(
          processArgs(nextArgs).toArray(new String[] {}));
    } catch (CmdLineException e) {
      logger.log(Level.SEVERE, "Failure", e);
      parseError = true;
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.