Package net.sourceforge.argparse4j.inf

Examples of net.sourceforge.argparse4j.inf.MutuallyExclusiveGroup


        assertEquals("--", res.get("car"));
    }

    @Test
    public void testParseArgsWithMutexGroup() throws ArgumentParserException {
        MutuallyExclusiveGroup group = ap.addMutuallyExclusiveGroup("mutex");
        group.addArgument("--foo");
        group.addArgument("--bar");
        Namespace res = ap.parseArgs("--foo bar".split(" "));
        assertEquals("bar", res.get("foo"));
    }
View Full Code Here


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

    @Test
    public void testParseArgsWithMutexGroupDuplicate() throws ArgumentParserException {
        MutuallyExclusiveGroup group = ap.addMutuallyExclusiveGroup("mutex");
        group.addArgument("--foo");
        group.addArgument("--bar");
        try {
            ap.parseArgs("--foo bar --bar baz".split(" "));
            fail();
        } catch(ArgumentParserException e) {
            assertEquals("argument --bar: not allowed with argument --foo", e.getMessage());
View Full Code Here

        }
    }

    @Test
    public void testParseArgsWithMutexGroupRequired() throws ArgumentParserException {
        MutuallyExclusiveGroup group = ap.addMutuallyExclusiveGroup("mutex").required(true);
        group.addArgument("--foo");
        group.addArgument("--bar");
        Namespace res = ap.parseArgs("--foo bar".split(" "));
        assertEquals("bar", res.get("foo"));
    }
View Full Code Here

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

    @Test
    public void testParseArgsWithMutexGroupRequiredFail() throws ArgumentParserException {
        MutuallyExclusiveGroup group = ap.addMutuallyExclusiveGroup("mutex").required(true);
        group.addArgument("--foo");
        group.addArgument("--bar");
        try {
            ap.parseArgs(new String []{});
            fail();
        } catch(ArgumentParserException e) {
            assertEquals("one of the arguments --foo --bar is required", e.getMessage());
View Full Code Here

        }
    }

    @Test
    public void testParseArgsWithMutexGroupConcatDuplicate() throws ArgumentParserException {
        MutuallyExclusiveGroup group = ap.addMutuallyExclusiveGroup("mutex").required(true);
        group.addArgument("-a").action(Arguments.storeTrue());
        group.addArgument("-b").action(Arguments.storeTrue());
        ap.addArgument("-c").action(Arguments.storeTrue());
        try {
            ap.parseArgs("-acb".split(" "));
        } catch(ArgumentParserException e) {
            assertEquals("argument -b: not allowed with argument -a", e.getMessage());
View Full Code Here

        }
    }

    @Test
    public void testParseArgsWithMutexGroupConcat() throws ArgumentParserException {
        MutuallyExclusiveGroup group = ap.addMutuallyExclusiveGroup("mutex").required(true);
        group.addArgument("-a").action(Arguments.storeTrue());
        group.addArgument("-b").action(Arguments.storeTrue());
        ap.addArgument("-c");
        Namespace res = ap.parseArgs("-acfoo".split(" "));
        assertEquals(true, res.getBoolean("a"));
        assertEquals("foo", res.get("c"));
    }
View Full Code Here

    }

    @Test
    public void testParseArgsWithMutualExclusiveGroupAndSuppressHelp()
            throws ArgumentParserException {
        MutuallyExclusiveGroup mutex1 = ap.addMutuallyExclusiveGroup("mutex1")
                .required(true);
        mutex1.addArgument("-a").help(Arguments.SUPPRESS);
        Argument b = mutex1.addArgument("-b");
        // Check the suppressed argument is not shown in the error message
        try {
            ap.parseArgs(new String[]{});
            fail();
        } catch(ArgumentParserException e) {
View Full Code Here

        assertEquals(String.format(
                TextHelper.LOCALE_ROOT,
                "usage: argparse4j [-h]%n"), ap.formatUsage());
        ap.addArgument("-a");
        ap.addArgument("-b").required(true);
        MutuallyExclusiveGroup group = ap.addMutuallyExclusiveGroup("mutex").required(true);
        group.addArgument("-c").required(true);
        group.addArgument("-d").required(true);
        ap.addArgument("file");
        assertEquals(String.format(
                TextHelper.LOCALE_ROOT,
                "usage: argparse4j [-h] [-a A] -b B (-c C | -d D) file%n"),
                ap.formatUsage());
View Full Code Here

   
    @Test
    public void testFormatHelpWithMutexGroup()
            throws ArgumentParserException {
        ap.description("This is argparser4j.").epilog("This is epilog.");
        MutuallyExclusiveGroup group = ap.addMutuallyExclusiveGroup("group1")
                .description("group1 description");
        group.addArgument("--foo");
        group.addArgument("--bar");
        assertEquals(String.format(
                  TextHelper.LOCALE_ROOT,
                  "usage: argparse4j [-h] [--foo FOO | --bar BAR]%n"
                + "%n"
                + "This is argparser4j.%n"
View Full Code Here

    @Test
    public void testFormatHelpWithMutexGroupWithoutTitleAndDescription()
            throws ArgumentParserException {
        ap.description("This is argparser4j.").epilog("This is epilog.");
        MutuallyExclusiveGroup group = ap.addMutuallyExclusiveGroup();
        group.addArgument("--foo");
        ap.addArgument("-b").action(Arguments.storeTrue());
        // Without title and description, options in mutually exclusive group
        // is merged into other optional arguments.
        assertEquals(String.format(
                  TextHelper.LOCALE_ROOT,
View Full Code Here

TOP

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

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.