Package net.sourceforge.argparse4j.inf

Examples of net.sourceforge.argparse4j.inf.Subparsers


        ap = new ArgumentParserImpl("argparse4j", true, ArgumentParsers.DEFAULT_PREFIX_CHARS, "@");
        ap.addArgument("-f");
        ap.addArgument("--baz").nargs(2);
        ap.addArgument("x");
        ap.addArgument("y").nargs(2);
        Subparsers subparsers = ap.addSubparsers();
        Subparser subparser = subparsers.addParser("add");
        subparser.addArgument("--foo");
        subparser.addArgument("--bar").action(Arguments.storeTrue());

        Namespace res = ap.parseArgs("-f foo @target/test-classes/args.txt --baz alpha @target/test-classes/args2.txt x y1 @target/test-classes/args3.txt add --bar @target/test-classes/args4.txt".split(" "));
        assertEquals("bar", res.getString("f"));
View Full Code Here


    }

    @Test
    public void testParseArgsWithSubparsers() throws ArgumentParserException {
        ap.addArgument("-f");
        Subparsers subparsers = ap.addSubparsers();
        Subparser parserA = subparsers.addParser("install");
        parserA.addArgument("pkg1");
        parserA.setDefault("func", "install");
        Subparser parserB = subparsers.addParser("search");
        parserB.addArgument("pkg2");
        parserB.setDefault("func", "search");
        Namespace res = ap.parseArgs("install aria2".split(" "));
        assertEquals("aria2", res.get("pkg1"));
        assertEquals("install", res.get("func"));
View Full Code Here

        assertEquals("install", res.get("func"));
    }

    @Test
    public void testParseArgsWithSubparsersAlias() throws ArgumentParserException {
        Subparsers subparsers = ap.addSubparsers();
        Subparser checkout = subparsers.addParser("checkout").aliases("co");
        checkout.setDefault("func", "checkout");
        Namespace res = ap.parseArgs("co".split(" "));
        assertEquals("checkout", res.get("func"));
    }
View Full Code Here

    }

    @Test
    public void testParseArgsWithSubparsersAmbiguousCommand() throws ArgumentParserException {
        Namespace res;
        Subparsers subparsers = ap.addSubparsers();
        Subparser checkout = subparsers.addParser("clone")
                .setDefault("func", "clone");
        Subparser clean = subparsers.addParser("clean")
                .setDefault("func", "clean");

        res = ap.parseArgs("clo".split(" "));
        assertEquals("clone", res.get("func"));
View Full Code Here

        assertEquals("foo", res.get("c"));
    }

    @Test
    public void testParseArgsWithCommandAfterSeparator() throws ArgumentParserException {
        Subparsers subparsers = ap.addSubparsers();
        subparsers.addParser("install");
        try {
            ap.parseArgs("-- install".split(" "));
            fail();
        } catch(ArgumentParserException e) {
            assertEquals("unrecognized arguments: 'install'", e.getMessage());
View Full Code Here

        }
    }

    @Test
    public void testParseArgsWithoutSubcommand() throws ArgumentParserException {
        Subparsers subparsers = ap.addSubparsers();
        subparsers.addParser("install");
        try {
            ap.parseArgs(new String[]{});
            fail();
        } catch(ArgumentParserException e) {
            assertEquals("too few arguments", e.getMessage());
View Full Code Here

        }
    }
   
    @Test
    public void testSubparsersDest() throws ArgumentParserException {
        Subparsers subparsers = ap.addSubparsers().dest("command");
        subparsers.addParser("install").addArgument("--command")
                .setDefault("default");
        Namespace res = ap.parseArgs("install".split(" "));
        assertEquals("install", res.get("command"));
    }
View Full Code Here

        }
    }

    @Test
    public void testSubparserWithoutAddHelp() throws ArgumentParserException {
        Subparsers subparsers = ap.addSubparsers();
        subparsers.addParser("install", false, ArgumentParsers.DEFAULT_PREFIX_CHARS);
        try {
            ap.parseArgs("install -h".split(" "));
            fail();
        } catch (ArgumentParserException e) {
            assertEquals("unrecognized arguments: '-h'", e.getMessage());
View Full Code Here

        mutex2.addArgument("-f");
        mutex2.addArgument("-g");
        ap.addArgument("s");
        ap.addArgument("t");
        ap.addArgument("u").help(Arguments.SUPPRESS);
        Subparsers subparsers = ap.addSubparsers();
        Subparser sap = subparsers.addParser("add");
        sap.addArgument("-i").help(Arguments.SUPPRESS);
        sap.addArgument("-j");

        assertEquals(String.format(
                     TextHelper.LOCALE_ROOT,
View Full Code Here


    @Test
    public void testSubparserFormatHelp() throws ArgumentParserException {
        ap.addArgument("--bar");
        Subparsers subparsers = ap.addSubparsers();
        Subparser parser = subparsers.addParser("install");
        parser.description("This is sub-command of argparser4j.").epilog(
                "This is epilog of sub-command.");
        parser.addArgument("--foo");
        assertEquals(String.format(
                  TextHelper.LOCALE_ROOT,
View Full Code Here

TOP

Related Classes of net.sourceforge.argparse4j.inf.Subparsers

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.