Examples of ArgumentBundle


Examples of org.jnode.shell.syntax.ArgumentBundle

     */
    public ArgumentCompleter(Argument<?> argument, CommandLine.Token token) {
        this.argument = argument;
        this.token = token;
        if (argument.getBundle() == null) {
            new ArgumentBundle(argument).setStatus(ArgumentBundle.PARSING);
        }
    }
View Full Code Here

Examples of org.jnode.shell.syntax.ArgumentBundle

     * @throws ShellException for problems instantiating the command class, or problems parsing
     *         the command arguments.
     */
    public void parseCommandLine(CommandLine cmdLine) throws ShellException {
        try {
            ArgumentBundle bundle = argBundle;
            if (bundle == null) {
                Command cmd = createCommandInstance();
                if (cmd != null) {
                    bundle = cmd.getArgumentBundle();
                }
            }
           
            if (bundle != null) {
                // Do a full parse to bind the command line argument tokens to corresponding
                // command arguments
                bundle.parse(cmdLine, syntaxBundle);
            }
        } catch (InstantiationException ex) {
            throw new ShellInvocationException("Command class cannot be instantiated", ex);
        } catch (IllegalAccessException ex) {
            throw new ShellInvocationException("Command class cannot be instantiated", ex);
View Full Code Here

Examples of org.jnode.shell.syntax.ArgumentBundle

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

Examples of org.jnode.shell.syntax.ArgumentBundle

    @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");
            Assert.fail("didn't throw exception");
        } catch (SyntaxFailureException ex) {
            // expected
        }
    }
View Full Code Here

Examples of org.jnode.shell.syntax.ArgumentBundle

    /**
     * A child class that uses this constructor will have an initially
     * empty argument; see getArgumentBundle.
     */
    public AbstractCommand(String description) {
        this.bundle = new ArgumentBundle(description);
    }
View Full Code Here

Examples of org.jnode.shell.syntax.ArgumentBundle

     * @param args Argument objects to be registered for use in command syntax
     * parsing and completion.
     */
    protected final void registerArguments(Argument<?> ... args) {
        if (bundle == null) {
            bundle = new ArgumentBundle();
        }
        for (Argument<?> arg : args) {
            bundle.addArgument(arg);
        }
    }
View Full Code Here

Examples of org.jnode.shell.syntax.ArgumentBundle

            } catch (Throwable ex) {
                throw new CompletionException("Problem creating a command instance", ex);
            }

            // Get the command's argument bundle and syntax
            ArgumentBundle bundle = (command == null)
                ? ci.getArgumentBundle()
                : command.getArgumentBundle();
            SyntaxBundle syntaxes = ci.getSyntaxBundle();
            if (syntaxes == null) {
                syntaxes = shell.getSyntaxManager().getSyntaxBundle(cmd);
            }

            if (bundle == null) {
                // We're missing the argument bundle.  We assume this is a 'classic' Java application
                // 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());
            }  
            try {
                bundle.complete(this, syntaxes, completions);
            } catch (CommandSyntaxException ex) {
                throw new CompletionException("Command syntax problem", ex);
            }
        } else {
            // We haven't got a command name yet, so complete the partial command name string
View Full Code Here

Examples of org.jnode.shell.syntax.ArgumentBundle

    }
   
    @Override
    public Help getHelp(String alias, CommandInfo cmdInfo) throws HelpException {
        SyntaxBundle syntaxes = null;
        ArgumentBundle bundle = null;
        try {
            final Shell shell = ShellUtils.getShellManager().getCurrentShell();
            final SyntaxManager syntaxManager = shell.getSyntaxManager();
            Command cmd = cmdInfo.createCommandInstance();
            if (cmd != null) {
                bundle = cmd.getArgumentBundle();
                syntaxes = syntaxManager.getSyntaxBundle(alias);
                if (syntaxes == null) {
                    syntaxes = new SyntaxBundle(alias, bundle.createDefaultSyntax());
                }
            }
        } catch (Exception ex) {
            throw new HelpException(ex.getMessage(), ex);
        }
View Full Code Here

Examples of org.jnode.shell.syntax.ArgumentBundle

public class MuParserTest2 {

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

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

Examples of org.jnode.shell.syntax.ArgumentBundle

    @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;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.