Package org.jnode.shell

Examples of org.jnode.shell.CommandLine


        ArgumentBundle bundle = new ArgumentBundle(intArg);

        // <start> ::= <<intArg>>
        MuSyntax syntax = new MuArgument("intArg");
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"1"});

        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(new Integer(1), intArg.getValue());

        try {
            cl = new CommandLine(new String[] {"X"});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }

        try {
            cl = new CommandLine(new String[] {"1", "1"});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here


        ArgumentBundle bundle = new ArgumentBundle(intArg, fileArg);

        // <start> ::= <<intArg>> <<fileArg>>
        MuSyntax syntax = new MuSequence(new MuArgument("intArg"), new MuArgument("fileArg"));
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"1", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);

        Assert.assertEquals(new Integer(1), intArg.getValue());
        Assert.assertEquals(new File("x"), fileArg.getValue());

        try {
            cl = new CommandLine(new String[] {"1"});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
        try {
            cl = new CommandLine(new String[] {"1", ""});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
View Full Code Here

        ArgumentBundle bundle = new ArgumentBundle(intArg, fileArg);

        // <start> :: = <<intArg>> | <<fileArg>>
        MuSyntax syntax = new MuAlternation(new MuArgument("intArg"), new MuArgument("fileArg"));
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"1"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(new Integer(1), intArg.getValue());
        Assert.assertEquals(false, fileArg.isSet());

        cl = new CommandLine(new String[] {"x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(new File("x"), fileArg.getValue());
        Assert.assertEquals(false, intArg.isSet());

    }
View Full Code Here

                new MuAlternation("root", new MuArgument("fileArg"), new MuSequence(new MuArgument(
                        "intArg"), new MuBackReference("root")));
        syntax.resolveBackReferences();

        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(0, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(1, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "2", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(2, intArg.getValues().length);

        try {
            cl = new CommandLine(new String[] {"1", "2", ""});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("expected SEE");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

        MuSyntax syntax =
                new MuAlternation("root", new MuSequence(new MuArgument("intArg"),
                        new MuBackReference("root")), new MuArgument("fileArg"));
        syntax.resolveBackReferences();
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(0, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(1, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "1", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(2, intArg.getValues().length);

        try {
            cl = new CommandLine(new String[] {"1", "1", ""});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("expected SEE");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

            new MuAlternation(new MuSequence(new MuArgument("intArg"), new MuBackReference("root")),
                new MuArgument("bigArg")));
        syntax.resolveBackReferences();

        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"BIG"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, bigArg.getValues().length);
        Assert.assertEquals(0, smallArg.getValues().length);
        Assert.assertEquals(0, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "LARGE"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, bigArg.getValues().length);
        Assert.assertEquals(0, smallArg.getValues().length);
        Assert.assertEquals(1, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "2", "BIG"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, bigArg.getValues().length);
        Assert.assertEquals(0, smallArg.getValues().length);
        Assert.assertEquals(2, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "2", "3", "BIG", "SMALL"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, bigArg.getValues().length);
        Assert.assertEquals(1, smallArg.getValues().length);
        Assert.assertEquals(3, intArg.getValues().length);

        try {
            cl = new CommandLine(new String[] {"1", "2", "TINY"});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("expected SEE");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

    public void testOne() throws Exception {
        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.SequenceSyntaxTest$Test");
        shell.addSyntax("cmd", new SequenceSyntax(new ArgumentSyntax("fileArg")));

        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("fileArg").getValues().length);

        try {
            cl =
                    new CommandLine(new Token("cmd"),
                            new Token[] {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.SequenceSyntaxTest$Test");
        shell.addSyntax("cmd", new SequenceSyntax(new RepeatSyntax(new ArgumentSyntax("fileArg")),
                new ArgumentSyntax("intArg")));

        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) {
            //
        }

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

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

    public void testThree() throws Exception {
        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.SequenceSyntaxTest$Test");
        shell.addSyntax("cmd", new SequenceSyntax());

        CommandLine cl;

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

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

    public void testOne() throws Exception {
        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.OptionSyntaxTest$Test");
        shell.addSyntax("cmd", new OptionSyntax("fileArg", "file", 'f'));

        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("--file"), new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("fileArg").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")},
                        null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("fileArg").getValues().length);
        Assert.assertEquals("F1", cmd.getArgumentBundle().getArgument("fileArg").getValue()
                .toString());

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

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

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

TOP

Related Classes of org.jnode.shell.CommandLine

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.