Package org.jnode.shell.syntax

Examples of org.jnode.shell.syntax.SyntaxBundle


            if (!syntaxDescriptor.getName().equals("syntax")) {
                continue;
            }
            SyntaxSpecAdapter adaptedElement = new XMLSyntaxSpecAdapter(syntaxDescriptor);
            try {
                SyntaxBundle bundle = loader.loadSyntax(adaptedElement);
                if (bundle != null) {
                    syntaxMgr.add(bundle);
                }
            } catch (Exception ex) {
                throw new EmuException("problem in syntax", ex);
View Full Code Here


            // 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);
View Full Code Here

    public DefaultHelpFactory() {
    }
   
    @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

    public void addAlias(String alias, String className) {
        getAliasManager().add(alias, className);
    }

    public void addSyntax(String alias, Syntax syntax) {
        getSyntaxManager().add(new SyntaxBundle(alias, syntax));
    }
View Full Code Here

        PrintWriter out = getOutput().getPrintWriter();
        PrintWriter err = getError().getPrintWriter();
        SyntaxManager synMgr = ShellUtils.getCurrentSyntaxManager();
        if (argDumpAll.isSet()) {
            for (String alias : synMgr.getKeys()) {
                SyntaxBundle bundle = synMgr.getSyntaxBundle(alias);
                dumpSyntax(alias, bundle, out);
            }
        } else {
            String alias;
            if (argDump.isSet()) {
                alias = getAlias();
                SyntaxBundle bundle = synMgr.getSyntaxBundle(alias);
                if (bundle == null) {
                    err.format(err_no_alias, alias);
                } else {
                    dumpSyntax(alias, bundle, out);
                }
            } else if (argFile.isSet()) {
                alias = getAlias();
                File file = argFile.getValue();
                XMLElement xml = new XMLElement();
                FileReader reader = null;
                try {
                    reader = new FileReader(file);
                    xml.parseFromReader(new BufferedReader(reader));
                    xml.setAttribute("alias", alias);
                    SyntaxBundle bundle =
                        new SyntaxSpecLoader().loadSyntax(new XMLSyntaxSpecAdapter(xml));
                    synMgr.add(bundle);
                } catch (IOException ex) {
                    err.format(err_file_read, alias, ex.getLocalizedMessage());
                } finally {
View Full Code Here

            am.add("cat", "org.jnode.test.shell.MyCatCommand");
            am.add("alias", "org.jnode.test.shell.MyAliasCommand");
            aliasCompletions = new String[]{"alias ", "cat ", "cpuid ", "dir ", "duh ", "gc ", "set "};

            SyntaxManager sm = this.getSyntaxManager();
            sm.add(new SyntaxBundle("set",
                new SequenceSyntax(new ArgumentSyntax("key"), new ArgumentSyntax("value"))));
            sm.add(new SyntaxBundle("duh", new ArgumentSyntax("path")));
            sm.add(new SyntaxBundle("cpuid", new SequenceSyntax()));
            sm.add(new SyntaxBundle("alias",
                new EmptySyntax(null, "Print all available aliases and corresponding classnames"),
                new SequenceSyntax(null, "Set an aliases for given classnames",
                    new ArgumentSyntax("alias"), new ArgumentSyntax("classname")),
                new OptionSyntax("remove", 'r', null, "Remove an alias")));
        }
View Full Code Here

     * @param cmd an alias or class name
     * @return a {@code CommandInfo} object representing the given command
     * @throws ShellException, if the class could not be found
     */
    public CommandInfo getCommandInfo(String cmd) throws ShellException {
        SyntaxBundle syntaxBundle = getSyntaxManager().getSyntaxBundle(cmd);
        try {
            Class<?> cls = aliasMgr.getAliasClass(cmd);
            if (Command.class.isAssignableFrom(cls)) {
                return new CommandInfo(cls, cmd, syntaxBundle, aliasMgr.isInternal(cmd));
            } else {
View Full Code Here

TOP

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

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.