You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by tr...@apache.org on 2013/08/10 07:53:54 UTC

svn commit: r1512568 [6/39] - in /jackrabbit/commons/filevault/trunk: ./ parent/ vault-cli/ vault-cli/src/ vault-cli/src/main/ vault-cli/src/main/appassembler/ vault-cli/src/main/assembly/ vault-cli/src/main/java/ vault-cli/src/main/java/org/ vault-cli...

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/AbstractApplication.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,374 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.DisplaySetting;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.OptionException;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+import org.apache.commons.cli2.option.Command;
+import org.apache.commons.cli2.util.HelpFormatter;
+import org.apache.jackrabbit.vault.util.console.util.CliHelpFormatter;
+import org.apache.jackrabbit.vault.util.console.util.Log4JConfig;
+import org.apache.jackrabbit.vault.util.console.util.PomProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <code>Console</code>...
+ */
+public abstract class AbstractApplication {
+
+    /**
+     * the default logger
+     */
+    static final Logger log = LoggerFactory.getLogger(AbstractApplication.class);
+
+    private static final String LOG4J_PROPERTIES = "/org/apache/jackrabbit/vault/util/console/log4j.properties";
+
+    public static final String DEFAULT_CONF_FILENAME = "console.properties";
+
+    public static final String KEY_PROMPT = "prompt";
+    public static final String KEY_USER = "user";
+    public static final String KEY_PATH = "path";
+    public static final String KEY_HOST = "host";
+    public static final String KEY_LOGLEVEL = "loglevel";
+
+    /**
+     * The global env can be loaded and saved into the console properties.
+     */
+    private Properties globalEnv = new Properties();
+
+    //private Option optPropertyFile;
+    private Option optLogLevel;
+    private Option optVersion;
+    private Option optHelp;
+
+    public String getVersion() {
+        return getPomProperties().getVersion();
+    }
+
+    public PomProperties getPomProperties() {
+        return new PomProperties("org.apache.jackrabbit.vault", "vault-cli");
+    }
+    
+    public String getCopyrightLine() {
+        return "Copyright 2013 by Apache Software Foundation. See LICENSE.txt for more information.";
+    }
+    
+    public String getVersionString() {
+        return getApplicationName() + " [version " + getVersion() + "] " + getCopyrightLine();
+    }
+
+    public void printVersion() {
+        System.out.println(getVersionString());
+    }
+
+    /**
+     * Returns the name of this application
+     *
+     * @return the name of this application
+     */
+    public abstract String getApplicationName();
+
+
+    /**
+     * Returns the name of the shell command
+     *
+     * @return the name of the shell command
+     */
+    public abstract String getShellCommand();
+
+    public void printHelp(String cmd) {
+        if (cmd == null) {
+            getAppHelpFormatter().print();
+        } else {
+            getDefaultContext().printHelp(cmd);
+        }
+    }
+
+    protected HelpFormatter getAppHelpFormatter() {
+        CliHelpFormatter hf = CliHelpFormatter.create();
+        StringBuffer sep = new StringBuffer(hf.getPageWidth());
+        while (sep.length() < hf.getPageWidth()) {
+            sep.append("-");
+        }
+        hf.setHeader(getVersionString());
+        hf.setDivider(sep.toString());
+        hf.setShellCommand("  " + getShellCommand() + " [options] <command> [arg1 [arg2 [arg3] ..]]");
+        hf.setGroup(getApplicationCLGroup());
+        hf.setSkipToplevel(true);
+        hf.getFullUsageSettings().removeAll(DisplaySetting.ALL);
+
+        hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
+        hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+        hf.getDisplaySettings().add(DisplaySetting.DISPLAY_OPTIONAL);
+
+        hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
+        hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
+        hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
+        return hf;
+    }
+
+    public Group getApplicationCLGroup() {
+        return new GroupBuilder()
+                .withName("")
+                .withOption(addApplicationOptions(new GroupBuilder()).create())
+                .withOption(getDefaultContext().getCommandsGroup())
+                .withMinimum(0)
+                .create();
+    }
+
+    public GroupBuilder addApplicationOptions(GroupBuilder gbuilder) {
+        final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+        final ArgumentBuilder abuilder = new ArgumentBuilder();
+        /*
+        optPropertyFile =
+                obuilder
+                        .withShortName("F")
+                        .withLongName("console-settings")
+                        .withDescription(
+                                "The console settings property file. " +
+                                        "This is only required for interactive mode.")
+                        .withArgument(abuilder
+                                .withDescription("defaults to ...")
+                                .withMinimum(1)
+                                .withMaximum(1)
+                                .create()
+                        )
+                        .create();
+        optInteractive =
+                obuilder
+                        .withShortName("i")
+                        .withLongName("interactive")
+                        .withDescription("runs this application in an interactive mode.")
+                        .create();
+        */
+        optVersion =
+                obuilder
+                        .withLongName("version")
+                        .withDescription("print the version information and exit")
+                        .create();
+        optHelp =
+                obuilder
+                        .withShortName("h")
+                        .withLongName("help")
+                        .withDescription("print this help")
+                        .withArgument(abuilder
+                                .withName("command")
+                                .withMaximum(1)
+                                .create()
+                        )
+                        .create();
+
+        optLogLevel =
+                obuilder
+                        .withLongName("log-level")
+                        .withDescription("the log4j log level")
+                        .withArgument(abuilder
+                                .withName("level")
+                                .withMaximum(1)
+                                .create()
+                        )
+                        .create();
+
+        gbuilder
+                .withName("Global options:")
+                //.withOption(optPropertyFile)
+                .withOption(CliCommand.OPT_VERBOSE)
+                .withOption(CliCommand.OPT_QUIET)
+                .withOption(optVersion)
+                .withOption(optLogLevel)
+                .withOption(optHelp)
+                .withMinimum(0);
+        /*
+        if (getConsole() != null) {
+            gbuilder.withOption(optInteractive);
+        }
+        */
+        return gbuilder;
+    }
+
+    protected void init() {
+        globalEnv.setProperty(KEY_PROMPT,
+                "[${" + KEY_USER + "}@${" + KEY_HOST + "} ${" + KEY_PATH  +"}]$ ");
+    }
+
+    protected void initLogging() {
+        Log4JConfig.init(LOG4J_PROPERTIES);
+    }
+
+    protected void run(String[] args) {
+        // setup logging
+        try {
+            initLogging();
+        } catch (Throwable e) {
+            System.err.println("Error while initializing logging: " + e);
+        }
+
+        // setup and start
+        init();
+
+        Parser parser = new Parser();
+        parser.setGroup(getApplicationCLGroup());
+        parser.setHelpOption(optHelp);
+        try {
+            CommandLine cl = parser.parse(args);
+            String logLevel = getEnv().getProperty(KEY_LOGLEVEL);
+            if (cl.hasOption(optLogLevel)) {
+                logLevel = (String) cl.getValue(optLogLevel);
+            }
+            if (logLevel != null) {
+                Log4JConfig.setLevel(logLevel);
+            }
+            prepare(cl);
+            execute(cl);
+        } catch (OptionException e) {
+            log.error("{}. Type --help for more information.", e.getMessage());
+        } catch (ExecutionException e) {
+            log.error("Error while starting: {}", e.getMessage());
+        } finally {
+            close();
+        }
+    }
+
+    public void setLogLevel(String level) {
+        try {
+            Log4JConfig.setLevel(level);
+            getEnv().setProperty(KEY_LOGLEVEL, level);
+            System.out.println("Log level set to '" + Log4JConfig.getLevel() + "'");
+        } catch (Throwable e) {
+            System.err.println("Error while setting log level: " + e);
+        }
+    }
+
+    public void prepare(CommandLine cl) throws ExecutionException {
+        /*
+        try {
+            loadConfig((String) cl.getValue(optPropertyFile));
+        } catch (IOException e) {
+            throw new ExecutionException("Error while loading property file.", e);
+        }
+        */
+    }
+
+    public void execute(CommandLine cl) throws ExecutionException {
+        if (cl.hasOption(optVersion)) {
+            printVersion();
+        //} else if (cl.hasOption(optInteractive)) {
+        //    getConsole().run();
+        } else if (cl.hasOption(optHelp)) {
+            String cmd = (String) cl.getValue(optHelp);
+            if (cmd == null) {
+                // in this case, the --help is specified after the command
+                // eg: vlt checkout --help
+                Iterator iter = cl.getOptions().iterator();
+                while (iter.hasNext()) {
+                    Object o = iter.next();                    
+                    if (o instanceof Command) {
+                        cmd = ((Command) o).getPreferredName();
+                        break;
+                    }
+                }
+            }
+            printHelp(cmd);
+        } else {
+            if (!getDefaultContext().execute(cl)) {
+                log.error("Unknown command. Type '--help' for more information.");
+            }
+        }
+    }
+
+    public void saveConfig(String path) throws IOException {
+        File file = new File(path == null ? DEFAULT_CONF_FILENAME : path);
+        /*
+        Properties props = new Properties();
+        Iterator iter = globalEnv.keySet().iterator();
+        while (iter.hasNext()) {
+            String key = (String) iter.next();
+            if (key.startsWith("conf.") || key.startsWith("macro.")) {
+                props.put(key, globalEnv.getProperty(key));
+            }
+        }
+        props.store(out, "Console Configuration");
+        */
+        FileOutputStream out = new FileOutputStream(file);
+        globalEnv.store(out, "Console Configuration");
+        out.close();
+        log.info("Configuration saved to {}", file.getCanonicalPath());
+    }
+
+    public void loadConfig(String path) throws IOException {
+        File file = new File(path == null ? DEFAULT_CONF_FILENAME : path);
+        if (!file.canRead() && path == null) {
+            // ignore errors for default config
+            return;
+        }
+        Properties props = new Properties();
+        FileInputStream in = new FileInputStream(file);
+        props.load(in);
+        in.close();
+        Iterator iter = globalEnv.keySet().iterator();
+        while (iter.hasNext()) {
+            String key = (String) iter.next();
+            if (!props.containsKey(key)) {
+                props.put(key, globalEnv.getProperty(key));
+            }
+        }
+        globalEnv = props;
+        log.info("Configuration loaded from {}", file.getCanonicalPath());
+    }
+
+    protected void close() {
+    }
+
+    public Properties getEnv() {
+        return globalEnv;
+    }
+
+    public void setProperty(String key, String value) {
+        if (value == null) {
+            globalEnv.remove(key);
+        } else {
+            if (key.equals(KEY_LOGLEVEL)) {
+                setLogLevel(value);
+            } else {
+                globalEnv.setProperty(key, value);
+            }
+        }
+    }
+
+    public String getProperty(String key) {
+        return globalEnv.getProperty(key);
+    }
+
+    protected abstract ExecutionContext getDefaultContext();
+
+    public abstract Console getConsole();
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/CliCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/CliCommand.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/CliCommand.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/CliCommand.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+
+/**
+ * Command Line Command
+ */
+public interface CliCommand {
+
+    /**
+     * verbose option that can be globally used
+     */
+    Option OPT_VERBOSE = new DefaultOptionBuilder()
+            .withShortName("v")
+            .withLongName("verbose")
+            .withDescription("verbose output")
+            .create();
+
+    /**
+     * quiet option that can be globally used
+     */
+    Option OPT_QUIET = new DefaultOptionBuilder()
+            .withShortName("q")
+            .withLongName("quiet")
+            .withDescription("print as little as possible")
+            .create();
+
+    boolean execute(ExecutionContext ctx, CommandLine cl) throws Exception;
+
+    String getName();
+
+    String getShortDescription();
+
+    String getLongDescription();
+
+    String getExample();
+
+    boolean hasName(String name);
+
+    Option getCommand();
+    
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/Console.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/Console.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/Console.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/Console.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.jackrabbit.vault.util.console.util.Table;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import jline.Completor;
+import jline.ConsoleReader;
+import jline.History;
+import jline.SimpleCompletor;
+
+/**
+ * <code>Console</code>...
+ */
+public class Console {
+
+    /**
+     * the default logger
+     */
+    static final Logger log = LoggerFactory.getLogger(Console.class);
+
+    private ConsoleExecutionContext currentCtx;
+
+    private final Map contexts = new HashMap();
+
+    private final AbstractApplication app;
+
+    private ConsoleReader reader;
+
+    /**
+     * indicates console is running
+     */
+    private boolean running = false;
+
+
+    public Console(AbstractApplication app) {
+        this.app = app;
+    }
+
+    public void addContext(ConsoleExecutionContext ctx) {
+        if (contexts.containsKey(ctx.getName())) {
+            throw new IllegalArgumentException("Context with name '" + ctx.getName() + "' already registered.");
+        }
+        contexts.put(ctx.getName(), ctx);
+        ctx.attach(this);
+        currentCtx = ctx;
+    }
+
+    public void removeContext(ConsoleExecutionContext ctx) {
+        contexts.remove(ctx.getName());
+    }
+
+    public void switchContext(ConsoleExecutionContext ctx) {
+        if (!contexts.containsValue(ctx)) {
+            throw new IllegalArgumentException("Context not installed: " + ctx.getName());
+        }
+        switchContext(ctx.getName());
+    }
+
+    private void setCompletor() {
+        // always remove existing
+        Iterator iter = reader.getCompletors().iterator();
+        while (iter.hasNext()) {
+            reader.removeCompletor((Completor) iter.next());
+            iter = reader.getCompletors().iterator();
+        }
+        Set triggers = currentCtx.getCommandsGroup().getTriggers();
+        reader.addCompletor(new SimpleCompletor((String[]) triggers.toArray(new String[triggers.size()])));
+    }
+
+    public void switchContext(String name) {
+        if (name == null) {
+            Iterator iter = contexts.keySet().iterator();
+            Table t = new Table(2);
+            while (iter.hasNext()) {
+                name = (String) iter.next();
+                ConsoleExecutionContext c = (ConsoleExecutionContext) contexts.get(name);
+                if (c == currentCtx) {
+                    name = "*" + name;
+                } else {
+                    name = " " + name;
+                }
+                String path = c.getProperty(AbstractApplication.KEY_PATH);
+                t.addRow(name, path);
+            }
+            t.print();
+
+        } else {
+            if (!contexts.containsKey(name)) {
+                throw new ExecutionException("No such context: " + name);
+            }
+            currentCtx = (ConsoleExecutionContext) contexts.get(name);
+            setCompletor();
+            log.info("Switched to context '{}'", name);
+        }
+    }
+
+    protected void setup() {
+    }
+
+    protected AbstractApplication getApplication() {
+        return app;
+    }
+
+    protected void initJLine() {
+        History history = new History();
+        /*
+        try {
+            history = new History(new File(".consolehistory"));
+        } catch (IOException e) {
+            log.warn("Cannot read or write file for storing command line history: " + e.getMessage() + "");
+            history = new History();
+        }
+        */
+        reader.setHistory(history);
+        reader.setUseHistory(true);
+        setCompletor();
+    }
+
+    public void run() throws IOException {
+
+        reader = new ConsoleReader();
+        initJLine();
+        // setup and start
+        setup();
+
+        running = true;
+        while (running) {
+            try {
+                String line = reader.readLine(getPrompt());
+                if (line == null) {
+                    running = false;
+                } else {
+                    line = line.trim();
+                    if (line.length() > 0) {
+                        if (line.startsWith("!")) {
+                            // re-execute event from history
+                            String oldLine;
+                            try {
+                                int historyIndex = Integer.valueOf(line.substring(1).trim()).intValue();
+                                oldLine = (String) reader.getHistory().getHistoryList().get(historyIndex - 1);
+                            } catch (Exception e) {
+                                System.out.println("  " + line + ": event not found");
+                                continue;
+                            }
+                            reader.getHistory().addToHistory(oldLine);
+                            System.out.println("Executing '" + oldLine + "'");
+                            line = oldLine;
+                        }
+                        long now = System.currentTimeMillis();
+                        currentCtx.execute(line);
+                        long time = System.currentTimeMillis() - now;
+                        System.out.println("Command completed in " + time + "ms");
+                    }
+                }
+            } catch (Exception e) {
+                log.error("There was a unexpected problem while processing the line.", e);
+            }
+        }
+        close();
+    }
+
+    public ConsoleReader getReader() {
+        return reader;
+    }
+
+    public boolean isRunning() {
+        return running;
+    }
+
+    public void quit() {
+        running = false;
+    }
+
+    private String getPrompt() {
+        String p = app.getProperty(AbstractApplication.KEY_PROMPT);
+        StringBuffer out = new StringBuffer();
+        for (int i = 0; i < p.length(); i++) {
+            char c = p.charAt(i);
+            if (c == '$') {
+                c = p.charAt(++i);
+                if (c == '{') {
+                    int j = p.indexOf('}', i);
+                    String key = p.substring(i + 1, j);
+                    String prop = currentCtx.getProperty(key);
+                    if (prop != null && prop.length() > 40) {
+                        prop = "..." + prop.substring(prop.length() - 37);
+                    }
+                    out.append(prop);
+                    i = j;
+                } else {
+                    out.append('$');
+                    out.append(c);
+                }
+            } else {
+                out.append(c);
+            }
+        }
+        return out.toString();
+    }
+
+    protected boolean close() {
+        return true;
+    }
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleCommand.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleCommand.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleCommand.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console;
+
+import org.apache.commons.cli2.CommandLine;
+
+/**
+ * <code>Command</code>...
+ */
+public interface ConsoleCommand extends CliCommand {
+
+    public boolean execute(ConsoleExecutionContext ctx, CommandLine cl)
+            throws Exception;
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleExecutionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleExecutionContext.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleExecutionContext.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleExecutionContext.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.jackrabbit.vault.util.console.commands.CmdEnv;
+import org.apache.jackrabbit.vault.util.console.commands.CmdExec;
+import org.apache.jackrabbit.vault.util.console.commands.CmdExit;
+import org.apache.jackrabbit.vault.util.console.commands.CmdHelp;
+import org.apache.jackrabbit.vault.util.console.commands.CmdHistory;
+import org.apache.jackrabbit.vault.util.console.commands.CmdLoad;
+import org.apache.jackrabbit.vault.util.console.commands.CmdPwd;
+import org.apache.jackrabbit.vault.util.console.commands.CmdSet;
+import org.apache.jackrabbit.vault.util.console.commands.CmdStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <code>Console</code>...
+ */
+public class ConsoleExecutionContext extends ExecutionContext {
+
+    /**
+     * the default logger
+     */
+    static final Logger log = LoggerFactory.getLogger(ConsoleExecutionContext.class);
+
+    private final String name;
+
+    /**
+     * holds 'runtime' properties.
+     */
+    private Properties runtimeEnv = new Properties();
+
+    private Console console;
+
+    private ConsoleFile rootFile;
+
+    private ConsoleFile currentFile;
+
+    public ConsoleExecutionContext(AbstractApplication app) {
+        this(app, "default");
+    }
+
+    public ConsoleExecutionContext(AbstractApplication app, String name) {
+        super(app);
+        this.name = name;
+
+        // init commands
+        installCommand(new CmdHelp());
+        installCommand(new CmdEnv());
+        installCommand(new CmdHistory());
+        installCommand(new CmdSet());
+        installCommand(new CmdPwd());
+        installCommand(new CmdExit());
+        installCommand(new CmdStore());
+        installCommand(new CmdLoad());
+        installCommand(new CmdExec());
+    }
+
+    public void attach(Console console) {
+        this.console = console;
+    }
+
+    public Console getConsole() {
+        return console;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setFileSystem(ConsoleFile rootFile) {
+        this.rootFile = rootFile;
+        setCurrentFile(rootFile);
+    }
+
+    public ConsoleFile getRootFile() {
+        return rootFile;
+    }
+
+    public ConsoleFile getCurrentFile() {
+        assertFs();
+        return currentFile;
+    }
+
+    public ConsoleFile getFile(String path, boolean mustExist) {
+        assertFs();
+        if (path == null || path.equals(".")) {
+            return currentFile;
+        }
+        try {
+            return currentFile.getFile(path, mustExist);
+        } catch (IOException e) {
+            throw new ExecutionException(e);
+        }
+    }
+
+    public void cd(String path) {
+        setCurrentFile(getFile(path, true));
+    }
+
+    public void setCurrentFile(ConsoleFile currentFile) {
+        assertFs();
+        this.currentFile = currentFile;
+        runtimeEnv.setProperty(AbstractApplication.KEY_PATH, currentFile.getPath());
+    }
+
+    private void assertFs() {
+        if (rootFile == null) {
+            throw new ExecutionException("This context holds no fs.");
+        }
+    }
+
+    protected boolean doExecute(CliCommand cmd, CommandLine cl) throws Exception {
+        if (cmd instanceof ConsoleCommand) {
+            return (((ConsoleCommand) cmd).execute(this, cl));
+        } else {
+            return super.doExecute(cmd, cl);
+        }
+    }
+
+    public Properties getRuntimeEnv() {
+        return runtimeEnv;
+    }
+
+    public Set getPropertyKeys() {
+        Set ret = new HashSet();
+        ret.addAll(getApplication().getEnv().keySet());
+        ret.addAll(runtimeEnv.keySet());
+        return ret;
+    }
+    
+    public String getProperty(String key) {
+        return runtimeEnv.getProperty(key, getApplication().getProperty(key));
+    }
+
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleFile.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleFile.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleFile.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleFile.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console;
+
+import java.io.IOException;
+
+/**
+ * <code>FSContext</code>...
+ */
+public interface ConsoleFile {
+
+    public static final ConsoleFile[] EMPTY_ARRAY = new ConsoleFile[0];
+
+    Object unwrap();
+
+    String getPath();
+
+    String getName();
+
+    ConsoleFile getFile(String path, boolean mustExist) throws IOException;
+
+    ConsoleFile[] listFiles() throws IOException;
+
+    boolean allowsChildren();
+
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleFileSystem.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleFileSystem.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ConsoleFileSystem.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console;
+
+/**
+ * <code>ConsoleFileSystem</code>...
+ */
+public interface ConsoleFileSystem {
+
+    ConsoleFile getRoot();
+
+    public String getSchemePrefix();
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ExecutionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ExecutionContext.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ExecutionContext.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ExecutionContext.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.DisplaySetting;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+import org.apache.commons.cli2.util.HelpFormatter;
+import org.apache.jackrabbit.vault.util.console.util.CliHelpFormatter;
+import org.apache.jackrabbit.vault.util.console.util.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXException;
+
+/**
+ * <code>Console</code>...
+ */
+public class ExecutionContext {
+
+    /**
+     * the default logger
+     */
+    static final Logger log = LoggerFactory.getLogger(ExecutionContext.class);
+
+    private final AbstractApplication app;
+
+    /**
+     * list of commands
+     */
+    protected final ArrayList commands = new ArrayList();
+
+    private Group grpCommands;
+
+    public ExecutionContext(AbstractApplication app) {
+        this.app = app;
+    }
+
+    public void printHelp(String cmd) {
+        CliCommand cc = cmd == null ? null : getCommand(cmd);
+        getCmdHelpFormatter(cc).print();
+    }
+
+    public AbstractApplication getApplication() {
+        return app;
+    }
+
+    protected HelpFormatter getCmdHelpFormatter(CliCommand cmd) {
+        CliHelpFormatter hf = CliHelpFormatter.create();
+        if (cmd != null) {
+            hf.setCmd(cmd);
+            hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
+        } else {
+            hf.setGroup(getCommandsGroup());
+            hf.setShowUsage(false);
+            hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+        }
+        return hf;
+    }
+
+    public Group getCommandsGroup() {
+        if (grpCommands == null) {
+            try {
+                GroupBuilder gbuilder = new GroupBuilder()
+                        .withName("Commands:")
+                        .withMinimum(0)
+                        .withMaximum(1);
+                Iterator iter = commands.iterator();
+                while (iter.hasNext()) {
+                    CliCommand c = (CliCommand) iter.next();
+                    gbuilder.withOption(c.getCommand());
+                }
+                grpCommands = gbuilder.create();
+            } catch (Exception e) {
+                log.error("Error while building command group.", e);
+                throw new ExecutionException("Error while building command gorup.", e);
+            }
+        }
+        return grpCommands;
+    }
+
+    public void installCommand(CliCommand c) {
+        commands.add(c);
+    }
+
+    protected CliCommand getCommand(String name) {
+        Iterator iter = commands.iterator();
+        while (iter.hasNext()) {
+            CliCommand c = (CliCommand) iter.next();
+            if (c.hasName(name)) {
+                return c;
+            }
+        }
+        return null;
+    }
+
+    public boolean execute(String line) {
+        return execute(Text.parseLine(line));
+    }
+    
+    public boolean execute(String[] args) {
+        Parser parser = new Parser();
+        parser.setHelpFormatter(getCmdHelpFormatter(null));
+        parser.setGroup(getCommandsGroup());
+        CommandLine cl = parser.parseAndHelp(args);
+        return cl != null && execute(cl);
+    }
+
+    public boolean execute(CommandLine cl) {
+        Iterator iter = commands.iterator();
+        while (iter.hasNext()) {
+            CliCommand c = (CliCommand) iter.next();
+            try {
+                if (doExecute(c, cl)) {
+                    return true;
+                }
+            } catch (ExecutionException e) {
+                if (e.getCause() == null || e.getCause() == e) {
+                    log.error("{}: {}", c.getName(), e.getMessage());
+                } else {
+                    StringBuffer buf = new StringBuffer();
+                    addCause(buf, e.getCause(), null);
+                    log.error("{}: {}", c.getName(), buf.toString());
+
+                }
+            } catch (Throwable e) {
+                StringBuffer buf = new StringBuffer();
+                addCause(buf, e, null);
+                log.error("{}: {}", c.getName(), buf.toString());
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private static void addCause(StringBuffer buf, Throwable e, StringBuffer indent) {
+        if (indent == null) {
+            indent = new StringBuffer();
+        }
+        buf.append(e.getClass().getName()).append(": ").append(e.getMessage());
+        Throwable t = e.getCause();
+        if (e instanceof SAXException) {
+            t = ((SAXException) e).getException();
+        }
+        if (t != null && t != e) {
+            buf.append("\n").append(indent).append("caused by: ");
+            indent.append("  ");
+            addCause(buf, t, indent);
+        }
+    }
+
+    protected boolean doExecute(CliCommand cmd, CommandLine cl) throws Exception {
+        return cmd.execute(this, cl);
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ExecutionException.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ExecutionException.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ExecutionException.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/ExecutionException.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console;
+
+/**
+ * <code>ExecutionException</code> is used by commands reporting failure.
+ */
+public class ExecutionException extends RuntimeException {
+
+    public ExecutionException() {
+    }
+
+    public ExecutionException(String message) {
+        super(message);
+    }
+
+    public ExecutionException(Throwable cause) {
+        super(cause);
+    }
+
+    public ExecutionException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/AbstractCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/AbstractCommand.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/AbstractCommand.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/AbstractCommand.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.option.Command;
+import org.apache.jackrabbit.vault.util.console.CliCommand;
+import org.apache.jackrabbit.vault.util.console.ExecutionContext;
+
+/**
+ * <code>AbstractCommand</code>...
+ */
+public abstract class AbstractCommand implements CliCommand {
+
+    private Command cmd;
+
+    protected AbstractCommand() {
+    }
+
+    public boolean execute(ExecutionContext ctx, CommandLine cl) throws Exception {
+        if (cl.hasOption(getCommand())) {
+            doExecute(ctx, cl);
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public Option getCommand() {
+        if (cmd == null) {
+            cmd = createCommand();
+        }
+        return cmd;
+    }
+
+    public boolean hasName(String name) {
+        return getCommand().getTriggers().contains(name);
+    }
+
+    public String getName() {
+        return getCommand().getPreferredName();
+    }
+
+    public String toString() {
+        return getCommand().toString();
+    }
+
+    public String getLongDescription() {
+        return getShortDescription();
+    }
+
+    public String getExample() {
+        return null;
+    }
+
+    protected abstract void doExecute(ExecutionContext ctx, CommandLine cl)
+            throws Exception;
+
+    protected abstract Command createCommand();
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/AbstractConsoleCommand.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/AbstractConsoleCommand.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/AbstractConsoleCommand.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/AbstractConsoleCommand.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.jackrabbit.vault.util.console.ConsoleCommand;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+import org.apache.jackrabbit.vault.util.console.ExecutionContext;
+
+/**
+ * <code>AbstractCommand</code>...
+ */
+public abstract class AbstractConsoleCommand extends AbstractCommand implements ConsoleCommand {
+
+    public boolean execute(ConsoleExecutionContext ctx, CommandLine cl)
+            throws Exception {
+        if (cl.hasOption(getCommand())) {
+            doExecute(ctx, cl);
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    protected void doExecute(ExecutionContext ctx, CommandLine cl) throws Exception {
+        // overload this in order to support app-level commands
+        throw new IllegalStateException("Wrong setup. command not allowed to be invoked non-interactively.");
+    }
+
+    protected abstract void doExecute(ConsoleExecutionContext ctx, CommandLine cl)
+            throws Exception;
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdConsole.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdConsole.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdConsole.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdConsole.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import org.apache.commons.cli2.Argument;
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.commons.cli2.validation.FileValidator;
+import org.apache.jackrabbit.vault.util.console.AbstractApplication;
+import org.apache.jackrabbit.vault.util.console.ExecutionContext;
+
+/**
+ * <code>CmdShell</code>...
+ */
+public class CmdConsole extends AbstractCommand {
+
+    private Argument argFile;
+
+    protected void doExecute(ExecutionContext ctx, CommandLine cl) throws Exception {
+        String file = (String) cl.getValue(argFile);
+        ctx.getApplication().loadConfig(file);
+        ctx.getApplication().getConsole().run();
+    }
+
+    public String getShortDescription() {
+        return "Run an interactive console";
+    }
+
+    protected Command createCommand() {
+        return new CommandBuilder()
+                .withName("console")
+                .withDescription(getShortDescription())
+                .withChildren(new GroupBuilder()
+                        .withName("Options:")
+                        .withOption(new DefaultOptionBuilder()
+                                .withShortName("F")
+                                .withLongName("console-settings")
+                                .withDescription("specifies the console settings file. default is \"" + AbstractApplication.DEFAULT_CONF_FILENAME + "\"")
+                                .withArgument(argFile = new ArgumentBuilder()
+                                .withName("file")
+                                .withMinimum(1)
+                                .withMaximum(1)
+                                .withValidator(FileValidator.getExistingFileInstance())
+                                .create())
+                                .create()
+                                )
+                        .create())
+                .create();
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdCtx.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdCtx.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdCtx.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdCtx.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+
+/**
+ * <code>CmdExit</code>...
+ */
+public class CmdCtx extends AbstractConsoleCommand {
+
+    private Option argContext;
+
+    protected void doExecute(ConsoleExecutionContext ctx, CommandLine cl) throws Exception {
+        String arg = (String) cl.getValue(argContext);
+        ctx.getConsole().switchContext(arg);
+    }
+
+    public String getShortDescription() {
+        return "change the execution context.";
+    }
+
+    protected Command createCommand() {
+        return new CommandBuilder()
+                .withName("ctx")
+                .withDescription(getShortDescription())
+                .withChildren(new GroupBuilder()
+                        .withName("Options:")
+                        .withOption(argContext = new ArgumentBuilder()
+                                .withName("context")
+                                .withDescription("change to the given context. if empty display list.")
+                                .withMinimum(0)
+                                .withMaximum(1)
+                                .create()
+                        )
+                        .create()
+                )
+                .create();
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdEnv.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdEnv.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdEnv.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdEnv.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import java.util.Iterator;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+import org.apache.jackrabbit.vault.util.console.util.Table;
+
+/**
+ * <code>CmdEnv</code>...
+ */
+public class CmdEnv extends AbstractConsoleCommand {
+
+    protected void doExecute(ConsoleExecutionContext ctx, CommandLine cl) throws Exception {
+        Table t = new Table(2);
+        Iterator iter = ctx.getPropertyKeys().iterator();
+        while (iter.hasNext()) {
+            String key = (String) iter.next();
+            t.addRow(key, ctx.getProperty(key));
+        }
+        t.sort(0);
+        t.print();
+    }
+
+
+    public String getShortDescription() {
+        return "print the current environment properties";
+    }
+
+    protected Command createCommand() {
+        return new CommandBuilder()
+                .withName("env")
+                .withDescription(getShortDescription())
+                .create();
+    }
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdExec.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdExec.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdExec.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdExec.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+import org.apache.jackrabbit.vault.util.console.ExecutionException;
+
+/**
+ * Implements the 'exec' command.
+ */
+public class CmdExec extends AbstractConsoleCommand {
+
+    private Option argMacro;
+
+
+    protected void doExecute(ConsoleExecutionContext ctx, CommandLine cl) throws Exception {
+        String macro = (String) cl.getValue(argMacro);
+        String cmd = ctx.getProperty("macro." + macro);
+        if (cmd == null) {
+            throw new ExecutionException("Macro " + macro + " does not exist.");
+        }
+        ctx.execute(cmd);
+    }
+
+    public String getShortDescription() {
+        return "execute a macro";
+    }
+
+    protected Command createCommand() {
+        return new CommandBuilder()
+                .withName("exec")
+                .withDescription(getShortDescription())
+                .withChildren(new GroupBuilder()
+                        .withName("Options:")
+                        .withOption(argMacro = new ArgumentBuilder()
+                                .withName("macro")
+                                .withDescription(
+                                        "specifies the command stored in the environment property" +
+                                        " 'macro.<macro>'.")
+                                .withMinimum(1)
+                                .withMaximum(1)
+                                .create()
+                        )
+                        .create()
+                )
+                .create();
+    }
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdExit.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdExit.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdExit.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdExit.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+
+/**
+ * <code>CmdExit</code>...
+ */
+public class CmdExit extends AbstractConsoleCommand {
+
+    protected void doExecute(ConsoleExecutionContext ctx, CommandLine cl) throws Exception {
+        ctx.getConsole().quit();
+    }
+
+    public String getShortDescription() {
+        return "quit the console";
+    }
+
+    protected Command createCommand() {
+        return new CommandBuilder()
+                .withName("exit")
+                .withName("quit")
+                .withDescription(getShortDescription())
+                .create();
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdHelp.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdHelp.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdHelp.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdHelp.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.jackrabbit.vault.util.console.ExecutionContext;
+
+/**
+ * <code>CmdExit</code>...
+ */
+public class CmdHelp extends AbstractCommand {
+
+    private Option argCommand;
+
+    protected void doExecute(ExecutionContext ctx, CommandLine cl) throws Exception {
+        String cmd = (String) cl.getValue(argCommand);
+        ctx.printHelp(cmd);
+    }
+
+    public String getShortDescription() {
+        return "print this help.  Type 'help <subcommand>' for help on a specific subcommand.";
+    }
+
+    protected Command createCommand() {
+        return new CommandBuilder()
+                .withName("help")
+                .withDescription(getShortDescription())
+                .withChildren(new GroupBuilder()
+                        .withName("Options:")
+                        .withOption(argCommand = new ArgumentBuilder()
+                                .withName("command")
+                                .withDescription("prints the help for the given command")
+                                .withMinimum(0)
+                                .withMaximum(1)
+                                .create()
+                        )
+                        .create()
+                )
+                .create();
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdHistory.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdHistory.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdHistory.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdHistory.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import java.util.Iterator;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+
+/**
+ */
+public class CmdHistory extends AbstractConsoleCommand {
+
+    protected void doExecute(ConsoleExecutionContext ctx, CommandLine cl)
+            throws Exception {
+
+        // print the history
+        Iterator iter = ctx.getConsole().getReader().getHistory().getHistoryList().iterator();
+        int i=1;
+        while (iter.hasNext()) {
+            System.out.println("  " + i + "  " + iter.next());
+            i++;
+        }
+    }
+
+    public String getShortDescription() {
+        return "Print the command history";
+    }
+
+    public String getLongDescription() {
+        return  "Prints the history of commands. To re-execute " +
+                "a command in the history, use !<idx>, where <idx> is the index " +
+                "of the command in the history.\n";
+    }
+
+    protected Command createCommand() {
+        return new CommandBuilder()
+                .withName("history")
+                .withDescription(getShortDescription())
+                .create();
+    }
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdLoad.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdLoad.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdLoad.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdLoad.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.commons.cli2.validation.FileValidator;
+import org.apache.jackrabbit.vault.util.console.AbstractApplication;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+
+/**
+ * <code>CmdLs</code>...
+ */
+public class CmdLoad extends AbstractConsoleCommand {
+
+    private Option argFile;
+
+    protected void doExecute(ConsoleExecutionContext ctx, CommandLine cl) throws Exception {
+        String file = (String) cl.getValue(argFile);
+        ctx.getApplication().loadConfig(file);
+    }
+
+    public String getShortDescription() {
+        return "load a console configuration";
+    }
+
+    protected Command createCommand() {
+        return new CommandBuilder()
+                .withName("load")
+                .withDescription(getShortDescription())
+                .withChildren(new GroupBuilder()
+                        .withName("Options:")
+                        .withOption(argFile = new ArgumentBuilder()
+                                .withName("file")
+                                .withDescription("specifies the config file. default is \"" + AbstractApplication.DEFAULT_CONF_FILENAME + "\"")
+                                .withMinimum(0)
+                                .withMaximum(1)
+                                .withValidator(FileValidator.getExistingFileInstance())
+                                .create()
+                        )
+                        .create()
+                )
+                .create();
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdPwd.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdPwd.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdPwd.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdPwd.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+
+/**
+ * <code>CmdEnv</code>...
+ */
+public class CmdPwd extends AbstractConsoleCommand {
+
+    protected void doExecute(ConsoleExecutionContext ctx, CommandLine cl) throws Exception {
+        System.out.println(ctx.getCurrentFile().getPath());
+    }
+
+    public String getShortDescription() {
+        return "print the current work path";
+    }
+
+    protected Command createCommand() {
+        return new CommandBuilder()
+                .withName("pwd")
+                .withDescription(getShortDescription())
+                .create();
+    }
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdSet.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdSet.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdSet.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdSet.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import java.util.Iterator;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+import org.apache.jackrabbit.vault.util.console.util.Table;
+
+/**
+ * <code>CmdSetenv</code>...
+ */
+public class CmdSet extends AbstractConsoleCommand {
+
+    private Option argKey;
+
+    private Option argValue;
+
+    protected void doExecute(ConsoleExecutionContext ctx, CommandLine cl)
+            throws Exception {
+        String key = (String) cl.getValue(argKey);
+        String value = (String) cl.getValue(argValue);
+        if (key == null) {
+            Table t = new Table(2);
+            Iterator iter = ctx.getPropertyKeys().iterator();
+            while (iter.hasNext()) {
+                key = (String) iter.next();
+                t.addRow(key, ctx.getProperty(key));
+            }
+            t.sort(0);
+            t.print();
+        } else {
+            ctx.getApplication().setProperty(key, value);
+        }
+    }
+
+    public String getShortDescription() {
+        return "set a property or displays the environment";
+    }
+
+    public String getLongDescription() {
+        return  "Sets an environment property. If no argument is given the " +
+                "current environment is displayed.\n" +
+                "Please note that some properties are read-only and cannot be" +
+                "set.";
+    }
+
+    protected Command createCommand() {
+        return new CommandBuilder()
+                .withName("set")
+                .withDescription(getShortDescription())
+                .withChildren(new GroupBuilder()
+                        .withName("Options:")
+                        .withOption(argKey= new ArgumentBuilder()
+                                .withName("key")
+                                .withDescription("name of the property")
+                                .withMinimum(0)
+                                .withMaximum(1)
+                                .create()
+                        )
+                        .withOption(argValue= new ArgumentBuilder()
+                                .withName("value")
+                                .withDescription("value of the property. " +
+                                        "If empty the property will be deleted")
+                                .withMinimum(0)
+                                .withMaximum(1)
+                                .create()
+                        )
+                        .create()
+                )
+                .create();
+    }
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdStore.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdStore.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/commands/CmdStore.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.commands;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.jackrabbit.vault.util.console.AbstractApplication;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+
+/**
+ * <code>CmdLs</code>...
+ */
+public class CmdStore extends AbstractConsoleCommand {
+
+    private Option argFile;
+
+    protected void doExecute(ConsoleExecutionContext ctx, CommandLine cl) throws Exception {
+        String file = (String) cl.getValue(argFile);
+        ctx.getApplication().saveConfig(file);
+    }
+
+    public String getShortDescription() {
+        return "stores the current console configuration";
+    }
+
+    protected Command createCommand() {
+        return new CommandBuilder()
+                .withName("store")
+                .withDescription(getShortDescription())
+                .withChildren(new GroupBuilder()
+                        .withName("Options:")
+                        .withOption(argFile = new ArgumentBuilder()
+                                .withName("file")
+                                .withDescription("specifies the config file. default is \"" + AbstractApplication.DEFAULT_CONF_FILENAME + "\"")
+                                .withMinimum(0)
+                                .withMaximum(1)
+                                .create()
+                        )
+                        .create()
+                )
+                .create();
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/examples/CmdHello.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/examples/CmdHello.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/examples/CmdHello.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/examples/CmdHello.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.examples;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.jackrabbit.vault.util.console.ExecutionContext;
+import org.apache.jackrabbit.vault.util.console.commands.AbstractCommand;
+
+/**
+ * <code>CmdExit</code>...
+ */
+public class CmdHello extends AbstractCommand {
+
+    private Option argName;
+
+    protected void doExecute(ExecutionContext ctx, CommandLine cl)
+            throws Exception {
+        String name = (String) cl.getValue(argName);
+        if (name == null) {
+            System.out.println("Hello, world.");
+        } else {
+            System.out.println("Hello, " + name + ".");
+        }
+    }
+
+    public String getShortDescription() {
+        return "print hello";
+    }
+
+    protected Command createCommand() {
+        return new CommandBuilder()
+                .withName("hello")
+                .withDescription(getShortDescription())
+                .withChildren(new GroupBuilder()
+                        .withName("Options:")
+                        .withOption(argName = new ArgumentBuilder()
+                                .withName("name")
+                                .withDescription("print this name. default is 'world'")
+                                .withMinimum(0)
+                                .withMaximum(1)
+                                .create()
+                        )
+                        .create()
+                )
+                .create();
+    }
+}
\ No newline at end of file