Package org.jnode.shell.syntax

Examples of org.jnode.shell.syntax.FileArgument


                    break;
                case TOK_FOR_WORD:
                case TOK_FILE_NAME:
                    // Complete against the file system namespace
                    ac = new ArgumentCompleter(
                            new FileArgument("?", Argument.MANDATORY, null), token);
                    ac.complete(completions, shell);
                    break;
                case TOK_COMMAND_NAME:
                    // Complete against the command/alias/function namespaces
                    completeCommandWord(completions, shell, token);
View Full Code Here


                        if (from == null && !completing) {
                            throw new ShellSyntaxException("no filename after '<'");
                        } else if (completing &&
                                (from == null || (!tokenizer.hasNext() && !wspAfter))) {
                            return new ArgumentCompleter(
                                    new FileArgument("?", Argument.MANDATORY, null), from);
                        }
                        continue;
                    } else if (token.text.equals(">")) {
                        to = parseFileName(tokenizer, ">");
                        if (to == null && !completing) {
                            throw new ShellSyntaxException("no filename after '>'");
                        } else if (completing &&
                                (to == null || (!tokenizer.hasNext() && !wspAfter))) {
                            return new ArgumentCompleter(
                                    new FileArgument("?", Argument.MANDATORY, null), to);
                        }
                        continue;
                    } else if (token.text.equals("|")) {
                        pipeTo = true;
                        break;
View Full Code Here

public class ArgumentBundleTest {

    @Test
    public void testArgumentBundle() {
        new ArgumentBundle();
        new ArgumentBundle(new FileArgument("arg1", 0));
        try {
            new ArgumentBundle(new FileArgument("arg1", 0), new FileArgument("arg1", 0));
            Assert.fail("Didn't throw an IllegalArgumentException for duplicate labels");
        } catch (IllegalArgumentException ex) {
            // expected ...
        }
        try {
            new ArgumentBundle((Argument<?>) null);
            Assert.fail("Didn't throw an NullPointerException for null argument");
        } catch (NullPointerException ex) {
            // expected ...
        }
        try {
            new ArgumentBundle(new FileArgument(null, 0));
            Assert.fail("Didn't throw an NullPointerException for null label");
        } catch (NullPointerException ex) {
            // expected ...
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testGetArgumentString() {
        Argument<File> arg1 = new FileArgument("arg1", 0);
        Argument<File> arg2 = new FileArgument("arg2", 0);
        ArgumentBundle b = new ArgumentBundle(arg1, arg2);
        Assert.assertEquals(arg1, b.getArgument("arg1"));
        Assert.assertEquals(arg2, b.getArgument("arg2"));
        try {
            b.getArgument("arg3");
View Full Code Here

        }
    }

    @Test
    public void testCreateDefaultSyntax() {
        Argument<File> arg1 = new FileArgument("arg1", 0);
        Argument<File> arg2 = new FileArgument("arg2", 0);
        MyArgumentBundle b = new MyArgumentBundle(arg1, arg2);

        b.testCreateDefaultSyntax();
    }
View Full Code Here

                // that does its own argument parsing and completion like a UNIX shell; i.e.
                // completing each argument as a pathname.
                Syntax syntax = new RepeatSyntax(new ArgumentSyntax("argument"));
                syntaxes = new SyntaxBundle(cmd, syntax);
                bundle = new ArgumentBundle(
                    new FileArgument("argument", Argument.MULTIPLE));
            } else if (syntaxes == null) {
                // We're missing the syntax, but we do have an argument bundle.  Generate
                // a default syntax from the bundle.
                syntaxes = new SyntaxBundle(cmd, bundle.createDefaultSyntax());
            }  
View Full Code Here

    }

    @Test
    public void testStatefullParsing2() throws NoTokensAvailableException, CommandSyntaxException {
        IntegerArgument intArg = new IntegerArgument("intArg", Argument.MULTIPLE);
        FileArgument fileArg = new FileArgument("fileArg", Argument.MULTIPLE);
        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");
View Full Code Here

    }

    @Test
    public void testStatefullParsing3() throws NoTokensAvailableException, CommandSyntaxException {
        IntegerArgument intArg = new IntegerArgument("intArg", Argument.MULTIPLE);
        FileArgument fileArg = new FileArgument("fileArg", Argument.MULTIPLE);
        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

    }

    @Test
    public void testStatefullParsing4() throws NoTokensAvailableException, CommandSyntaxException {
        IntegerArgument intArg = new IntegerArgument("intArg", Argument.MULTIPLE);
        FileArgument fileArg = new FileArgument("fileArg", Argument.MULTIPLE);
        ArgumentBundle bundle = new ArgumentBundle(intArg, fileArg);

        // <root> ::= <<fileArg>> | ( <<intArg>> <root> )
        MuSyntax syntax =
                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);
View Full Code Here

    }

    @Test
    public void testStatefullParsing5() throws NoTokensAvailableException, CommandSyntaxException {
        IntegerArgument intArg = new IntegerArgument("intArg", Argument.MULTIPLE);
        FileArgument fileArg = new FileArgument("fileArg", Argument.MULTIPLE);
        ArgumentBundle bundle = new ArgumentBundle(intArg, fileArg);

        // <root> ::= ( <<intArg>> <root> ) | <<fileArg>>
        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);
View Full Code Here

TOP

Related Classes of org.jnode.shell.syntax.FileArgument

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.