001/*
002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bstefanescu
018 */
019package org.nuxeo.shell.equinox.cmds;
020
021import org.nuxeo.shell.Argument;
022import org.nuxeo.shell.Command;
023import org.nuxeo.shell.Context;
024import org.nuxeo.shell.Shell;
025import org.nuxeo.shell.cmds.Interactive;
026import org.nuxeo.shell.equinox.Connector;
027import org.nuxeo.shell.equinox.EquinoxCommandCompletor;
028
029/**
030 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
031 */
032@Command(name = "run", help = "Run an Equinox command")
033public class Run implements Runnable {
034
035    @Context
036    protected Shell shell;
037
038    @Context
039    protected Connector connector;
040
041    @Argument(name = "cmd", index = 0, completor = EquinoxCommandCompletor.class, help = "The command to run. If not specified the list of all commands is displayed.")
042    protected String cmd;
043
044    @Argument(name = "cmd arg1", index = 1, help = "Command argument")
045    protected String arg1;
046
047    @Argument(name = "cmd arg2", index = 2, help = "Command argument")
048    protected String arg2;
049
050    @Argument(name = "cmd arg3", index = 3, help = "Command argument")
051    protected String arg3;
052
053    @Argument(name = "cmd arg4", index = 4, help = "Command argument")
054    protected String arg4;
055
056    @Argument(name = "cmd arg5", index = 5, help = "Command argument")
057    protected String arg5;
058
059    @Argument(name = "cmd arg6", index = 6, help = "Command argument")
060    protected String arg6;
061
062    public void run() {
063        if (cmd == null) {
064            cmd = "help";
065        } else {
066            cmd = Interactive.getCurrentCmdLine().trim();
067            cmd = cmd.substring("run".length()).trim();
068        }
069        shell.getConsole().println(connector.send(cmd));
070    }
071}