Package org.jnode.shell.CommandLine

Examples of org.jnode.shell.CommandLine.Token


        CommandLine cl;
        CommandInfo cmdInfo;
        Command cmd;

        cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("fileArg").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("intArg").getValues().length);

        cl =
                new CommandLine(new Token("cmd"), new Token[] {new Token("-f"), new Token("F1")},
                        null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("fileArg").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("intArg").getValues().length);
        Assert.assertEquals("F1", cmd.getArgumentBundle().getArgument("fileArg").getValue()
                .toString());

        cl =
                new CommandLine(new Token("cmd"), new Token[] {new Token("-f"), new Token("F1"),
                    new Token("-x"), new Token("-yz")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("fileArg").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("intArg").getValues().length);
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("flagArg1").getValues().length);
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("flagArg2").getValues().length);
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("flagArg3").getValues().length);

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("-yz")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("fileArg").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("intArg").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("flagArg1").getValues().length);
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("flagArg2").getValues().length);
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("flagArg3").getValues().length);

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {new Token("-xya")}, null);
            cl.parseCommandLine(shell);
            Assert.fail("no exception");
        } catch (CommandSyntaxException ex) {
            // expected
        }

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {new Token("-")}, null);
            cl.parseCommandLine(shell);
            Assert.fail("no exception");
        } catch (CommandSyntaxException ex) {
            // expected
        }
View Full Code Here


                char ch = value.charAt(i);
                String shortOptName = "-" + ch;
                boolean found = false;
                for (OptionSyntax flagOption : flagOptions) {
                    if (shortOptName.equals(flagOption.getShortOptName())) {
                        bundle.getArgument(flagOption).accept(new Token(shortOptName), 0);
                        found = true;
                        break;
                    }
                }
                if (!found) {
View Full Code Here

    }

    @Test
    @SuppressWarnings("deprecation")
    public void testTokenConstructors() {
        Token foo = new Token("foo");
        Token[] args = new Token[] {new Token("1"), new Token("2"), new Token("3")};

        CommandLine c1 = new CommandLine(foo, args, null);
        Assert.assertEquals("foo", c1.getCommandName());
        Assert.assertEquals(foo, c1.getCommandToken());
View Full Code Here

    public void testParse() throws Exception {
        TestShell shell = new TestShell();
        shell.addAlias("command", "org.jnode.test.shell.syntax.CommandLineTest$TestCommand");
        shell.addSyntax("command", new ArgumentSyntax("arg1"));
        CommandLine cl =
                new CommandLine(new Token("command"), new Token[] {new Token("fish")}, null);
        CommandInfo cmdInfo = cl.parseCommandLine(shell);
        Command cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals("fish", cmd.getArgumentBundle().getArgument("arg1").getValue());
    }
View Full Code Here

    public void testZeroToMany() throws Exception {
        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.RepeatSyntaxTest$Test");
        shell.addSyntax("cmd", new RepeatSyntax(new ArgumentSyntax("arg1")));

        CommandLine cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
        CommandInfo cmdInfo = cl.parseCommandLine(shell);
        Command cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg1").getValues().length);

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("arg1").getValues().length);

        cl =
                new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1")},
                        null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(2, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
View Full Code Here

        CommandLine cl;
        CommandInfo cmdInfo;
        Command cmd;

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
            cl.parseCommandLine(shell);
            Assert.fail("no exception");
        } catch (CommandSyntaxException ex) {
            // expected
        }

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("arg1").getValues().length);

        cl =
                new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1")},
                        null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(2, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
    }
View Full Code Here

        CommandLine cl;
        CommandInfo cmdInfo;
        Command cmd;

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
            cl.parseCommandLine(shell);
            Assert.fail("no exception");
        } catch (CommandSyntaxException ex) {
            // expected
        }

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("arg1").getValues().length);

        cl =
                new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1")},
                        null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(2, cmd.getArgumentBundle().getArgument("arg1").getValues().length);

        try {
            cl =
                    new CommandLine(new Token("cmd"), new Token[] {new Token("F1"),
                        new Token("F1"), new Token("F1")}, null);
            cl.parseCommandLine(shell);
            Assert.fail("no exception");
        } catch (CommandSyntaxException ex) {
            // expected
        }
View Full Code Here

        CommandInfo cmdInfo;
        @SuppressWarnings("unused")
        Command cmd;

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
            cl.parseCommandLine(shell);
            Assert.fail("no exception");
        } catch (CommandSyntaxException ex) {
            // expected
        }

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
            cl.parseCommandLine(shell);
        } catch (CommandSyntaxException ex) {
            // expected
        }

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1")}, null);
            cl.parseCommandLine(shell);
        } catch (CommandSyntaxException ex) {
            // expected
        }

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1"), new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1"), new Token("F1"),
            new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1"), new Token("F1"),
            new Token("F1"), new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1"), new Token("F1"),
            new Token("F1"), new Token("F1"), new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1"), new Token("F1"),
                new Token("F1"), new Token("F1"), new Token("F1"), new Token("F1")}, null);
            cl.parseCommandLine(shell);
            Assert.fail("no exception");
        } catch (CommandSyntaxException ex) {
            // expected
        }
View Full Code Here

        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.RepeatSyntaxTest$Test");
        shell.addSyntax("cmd", new SequenceSyntax(new RepeatSyntax(new ArgumentSyntax("arg1")),
                new RepeatSyntax(new ArgumentSyntax("arg2"))));

        CommandLine cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
        CommandInfo cmdInfo = cl.parseCommandLine(shell);
        Command cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg2").getValues().length);

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("arg2").getValues().length);

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
        Assert.assertEquals(2, cmd.getArgumentBundle().getArgument("arg2").getValues().length);
    }
View Full Code Here

        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.RepeatSyntaxTest$Test");
        shell.addSyntax("cmd", new SequenceSyntax(new RepeatSyntax(null, new ArgumentSyntax("arg1"), 0,
            Integer.MAX_VALUE, true, null), new RepeatSyntax(new ArgumentSyntax("arg2"))));

        CommandLine cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
        CommandInfo cmdInfo = cl.parseCommandLine(shell);
        Command cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg2").getValues().length);

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg2").getValues().length);

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(2, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg2").getValues().length);
    }
View Full Code Here

TOP

Related Classes of org.jnode.shell.CommandLine.Token

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.