[seam-commits] Seam SVN: r13361 - in sandbox/encore/shell/src/main/java/org/jboss/encore/shell: cli and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Jul 12 18:29:40 EDT 2010


Author: lincolnthree
Date: 2010-07-12 18:29:39 -0400 (Mon, 12 Jul 2010)
New Revision: 13361

Added:
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Execution.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/Echo.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/CommandParser.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/CompositeCommandParser.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/NamedBooleanOptionParser.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/NamedValueOptionParser.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/NamedValueVarargsOptionParser.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/OrderedValueOptionParser.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/OrderedValueVarargsOptionParser.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/ParseErrorParser.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/BuiltIn.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Command.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Option.java
Removed:
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Execution.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/BuiltIn.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Command.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Option.java
Modified:
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Shell.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandLibraryExtension.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandMetadata.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/ExecutionParser.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/OptionMetadata.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginCommandCompletionHandler.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginMetadata.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/ExitShell.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/Help.java
   sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Plugin.java
Log:
More consistent parsing algorithm & plugin execution

Deleted: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Execution.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Execution.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Execution.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -1,101 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.encore.shell;
-
-import java.util.Set;
-
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-
-import org.jboss.encore.shell.cli.CommandMetadata;
-import org.jboss.encore.shell.plugins.Plugin;
-
-/**
- * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
- * 
- */
-public class Execution
-{
-   @Inject
-   private BeanManager manager;
-
-   private CommandMetadata command;
-   private Object[] parameterArray;
-
-   @SuppressWarnings("unchecked")
-   public void perform()
-   {
-      if (command != null)
-      {
-         try
-         {
-            Class<? extends Plugin> pluginType = command.getParent().getType();
-            Set<Bean<?>> beans = manager.getBeans(pluginType);
-            Bean<? extends Object> bean = manager.resolve(beans);
-
-            Plugin plugin = null;
-            if (bean != null)
-            {
-               CreationalContext<? extends Plugin> context = (CreationalContext<? extends Plugin>) manager
-                        .createCreationalContext(bean);
-               if (context != null)
-               {
-                  plugin = (Plugin) manager.getReference(bean, pluginType, context);
-                  command.getMethod().invoke(plugin, parameterArray);
-               }
-            }
-
-         }
-         catch (Exception e)
-         {
-            System.err.println("I don't understand what you meant.");
-         }
-      }
-      else
-      {
-         System.err.println("I don't understand what you meant.");
-      }
-   }
-
-   public CommandMetadata getCommand()
-   {
-      return command;
-   }
-
-   public void setCommand(final CommandMetadata command)
-   {
-      this.command = command;
-   }
-
-   public Object[] getParameterArray()
-   {
-      return parameterArray;
-   }
-
-   public void setParameterArray(final Object... parameters)
-   {
-      this.parameterArray = parameters;
-   }
-
-}

Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Shell.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Shell.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Shell.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -31,6 +31,7 @@
 import jline.console.ConsoleReader;
 import jline.console.completer.Completer;
 
+import org.jboss.encore.shell.cli.Execution;
 import org.jboss.encore.shell.cli.ExecutionParser;
 import org.jboss.encore.shell.events.AcceptUserInput;
 import org.jboss.encore.shell.events.Shutdown;
@@ -62,7 +63,7 @@
    private ConsoleReader reader;
    private boolean exitRequested = false;
 
-   public void init(@Observes final Startup event) throws Exception
+   void init(@Observes final Startup event) throws Exception
    {
       System.out.println("Startup");
       log.info("Encore Shell - Starting up.");
@@ -71,9 +72,14 @@
       reader.setHistoryEnabled(true);
       reader.setPrompt(prompt);
       reader.addCompleter(completer);
+
+      if (parameters.contains("--verbose"))
+      {
+         // TODO set verbose mode
+      }
    }
 
-   public void doShell(@Observes final AcceptUserInput event)
+   void doShell(@Observes final AcceptUserInput event)
    {
       String line;
       try
@@ -90,18 +96,61 @@
       }
       catch (IOException e)
       {
-         throw new IllegalStateException("Shell line reading failure", e);
+         throw new IllegalStateException("Shell input stream failure", e);
       }
    }
 
    private void execute(final String line)
    {
-      Execution execution = parser.parse(line);
-      execution.perform();
+      Execution execution = null;
+      try
+      {
+         execution = parser.parse(line);
+         try
+         {
+            execution.perform();
+         }
+         catch (Exception e)
+         {
+            System.err.println("Error executing command: " + execution.getOriginalStatement() + " : " + e.getMessage());
+         }
+      }
+      catch (Exception e)
+      {
+         System.err.println("Error parsing input: " + e.getMessage());
+      }
    }
 
-   public void teardown(@Observes final Shutdown event)
+   void teardown(@Observes final Shutdown event)
    {
       exitRequested = true;
    }
+
+   /**
+    * Prompt the user for input, using {@link message} as the prompt text.
+    */
+   public String prompt(final String message)
+   {
+      System.out.print(message);
+      try
+      {
+         String currentPrompt = reader.getPrompt();
+         reader.setPrompt(" ");
+         String line = reader.readLine();
+         reader.setPrompt(currentPrompt);
+         return line;
+      }
+      catch (IOException e)
+      {
+         throw new IllegalStateException("Shell input stream failure", e);
+      }
+   }
+
+   /**
+    * Write the given {@link line} to the console output.
+    */
+   public void write(final String line)
+   {
+      System.out.println(line);
+   }
 }
\ No newline at end of file

Deleted: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/BuiltIn.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/BuiltIn.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/BuiltIn.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -1,48 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.encore.shell.cli;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import org.jboss.encore.shell.plugins.Plugin;
-
-/**
- * Defines a #{@link Plugin} as built in, thus, commands will be accessible without providing a plugin name;
- * 
- * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
- * 
- */
- at Target({ TYPE, METHOD, PARAMETER, FIELD })
- at Retention(RUNTIME)
- at Documented
-public @interface BuiltIn
-{
-
-}

Deleted: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Command.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Command.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Command.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -1,57 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.encore.shell.cli;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * Represents a single command to be run on a Shell.
- * 
- * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
- * 
- */
- at Qualifier
- at Target({ METHOD, PARAMETER, TYPE, FIELD })
- at Retention(RUNTIME)
- at Documented
-public @interface Command
-{
-   /**
-    * One or more names for this command.
-    */
-   String[] value() default {};
-
-   /**
-    * Help text for this command.
-    */
-   String help() default "";
-}

Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandLibraryExtension.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandLibraryExtension.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandLibraryExtension.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -34,6 +34,9 @@
 import javax.enterprise.inject.spi.ProcessBean;
 import javax.inject.Named;
 
+import org.jboss.encore.shell.plugins.BuiltIn;
+import org.jboss.encore.shell.plugins.Command;
+import org.jboss.encore.shell.plugins.Option;
 import org.jboss.encore.shell.plugins.Plugin;
 import org.jboss.encore.shell.util.Annotations;
 
@@ -115,7 +118,7 @@
                      option.setParent(commandMeta);
                      option.setName(opt.value());
                      option.setHelp(opt.help());
-                     option.setRequired(opt.requred());
+                     option.setRequired(opt.required());
                   }
                }
                commandMeta.addOption(option);
@@ -140,6 +143,6 @@
       {
          name = plugin.getSimpleName();
       }
-      return name;
+      return name.toLowerCase();
    }
 }

Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandMetadata.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandMetadata.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandMetadata.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -38,6 +38,35 @@
    private String help;
    private List<OptionMetadata> options = new ArrayList<OptionMetadata>();
 
+   public OptionMetadata getNamedOption(final String name) throws IllegalArgumentException
+   {
+      for (OptionMetadata option : options)
+      {
+         if (option.isNamed() && option.getName().equals(name))
+         {
+            return option;
+         }
+      }
+      throw new IllegalArgumentException("No such option [" + name + "] for command: " + this);
+   }
+
+   public OptionMetadata getOrderedOptionByIndex(final int index) throws IllegalArgumentException
+   {
+      int currentIndex = 0;
+      for (OptionMetadata option : options)
+      {
+         if (!option.isNamed() && (index == currentIndex))
+         {
+            return option;
+         }
+         else if (!option.isNamed())
+         {
+            currentIndex++;
+         }
+      }
+      throw new IllegalArgumentException("No option with index [" + index + "] exists for command: " + this);
+   }
+
    public Method getMethod()
    {
       return method;
@@ -99,16 +128,4 @@
    {
       this.parent = parent;
    }
-
-   public OptionMetadata getNamedOption(final String token)
-   {
-      for (OptionMetadata option : options)
-      {
-         if (option.isNamed() && option.getName().equals(token))
-         {
-            return option;
-         }
-      }
-      return null;
-   }
 }
\ No newline at end of file

Copied: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Execution.java (from rev 13360, sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Execution.java)
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Execution.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Execution.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli;
+
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+import org.jboss.encore.shell.plugins.Plugin;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class Execution
+{
+   @Inject
+   private BeanManager manager;
+
+   private CommandMetadata command;
+   private Object[] parameterArray;
+   private String originalStatement;
+
+   @SuppressWarnings("unchecked")
+   public void perform()
+   {
+      if (command != null)
+      {
+         try
+         {
+            Class<? extends Plugin> pluginType = command.getParent().getType();
+            Set<Bean<?>> beans = manager.getBeans(pluginType);
+            Bean<? extends Object> bean = manager.resolve(beans);
+
+            Plugin plugin = null;
+            if (bean != null)
+            {
+               CreationalContext<? extends Plugin> context = (CreationalContext<? extends Plugin>) manager
+                        .createCreationalContext(bean);
+               if (context != null)
+               {
+                  plugin = (Plugin) manager.getReference(bean, pluginType, context);
+
+                  command.getMethod().invoke(plugin, parameterArray);
+               }
+            }
+
+         }
+         catch (Exception e)
+         {
+            System.err.println("I don't understand what you meant.");
+         }
+      }
+      else
+      {
+         System.err.println("I don't understand what you meant.");
+      }
+   }
+
+   public CommandMetadata getCommand()
+   {
+      return command;
+   }
+
+   public void setCommand(final CommandMetadata command)
+   {
+      this.command = command;
+   }
+
+   public Object[] getParameterArray()
+   {
+      return parameterArray;
+   }
+
+   public void setParameterArray(final Object... parameters)
+   {
+      this.parameterArray = parameters;
+   }
+
+   public String getOriginalStatement()
+   {
+      return originalStatement;
+   }
+
+   public void setOriginalStatement(final String originalStatement)
+   {
+      this.originalStatement = originalStatement;
+   }
+
+}

Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/ExecutionParser.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/ExecutionParser.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/ExecutionParser.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -21,10 +21,8 @@
  */
 package org.jboss.encore.shell.cli;
 
-import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.HashMap;
 import java.util.LinkedList;
-import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Queue;
@@ -32,7 +30,14 @@
 import javax.enterprise.inject.Instance;
 import javax.inject.Inject;
 
-import org.jboss.encore.shell.Execution;
+import org.jboss.encore.shell.cli.parser.CommandParser;
+import org.jboss.encore.shell.cli.parser.CompositeCommandParser;
+import org.jboss.encore.shell.cli.parser.NamedBooleanOptionParser;
+import org.jboss.encore.shell.cli.parser.NamedValueOptionParser;
+import org.jboss.encore.shell.cli.parser.NamedValueVarargsOptionParser;
+import org.jboss.encore.shell.cli.parser.OrderedValueOptionParser;
+import org.jboss.encore.shell.cli.parser.OrderedValueVarargsOptionParser;
+import org.jboss.encore.shell.cli.parser.ParseErrorParser;
 
 /**
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
@@ -48,18 +53,15 @@
 
    public Execution parse(final String line)
    {
-      Queue<String> tokens = new LinkedList<String>();
-      for (String token : line.split("\\s+"))
-      {
-         tokens.add(token);
-      }
+      Queue<String> tokens = tokenize(line);
 
       Map<String, PluginMetadata> plugins = registry.getPlugins();
       Map<String, PluginMetadata> builtInPlugins = registry.getBuiltInPlugins();
 
       Execution execution = executionInstance.get();
+
+      execution.setOriginalStatement(line);
       CommandMetadata command = null;
-      List<Object> parameters = new ArrayList<Object>();
 
       if (tokens.size() > 0)
       {
@@ -82,7 +84,7 @@
          {
             command = plugin.getCommands().get(0);
          }
-         else if (tokens.size() > 1)
+         else if (tokens.size() > 0)
          {
             String second = tokens.peek();
             if ((plugin != null) && (command == null))
@@ -98,11 +100,55 @@
          if (command != null)
          {
             execution.setCommand(command);
-            parameters.addAll(Arrays.asList(tokens.toArray()));
-            execution.setParameterArray(parameters.toArray());
+
+            // parse parameters and set order / nulls for command invocation
+
+            Object[] parameters = parseParameters(command, tokens);
+            execution.setParameterArray(parameters);
          }
+         else
+         {
+            throw new IllegalStateException("Missing command for plugin: " + plugin.getName());
+         }
       }
 
       return execution;
    }
+
+   private Queue<String> tokenize(final String line)
+   {
+      Queue<String> tokens = new LinkedList<String>();
+
+      for (String token : line.split("\\s+"))
+      {
+         tokens.add(token);
+      }
+      return tokens;
+   }
+
+   private Object[] parseParameters(final CommandMetadata command, final Queue<String> tokens)
+   {
+      Map<OptionMetadata, Object> valueMap = new HashMap<OptionMetadata, Object>();
+
+      CommandParser commandParser = new CompositeCommandParser(new NamedBooleanOptionParser(),
+               new NamedValueOptionParser(),
+               new NamedValueVarargsOptionParser(), new OrderedValueOptionParser(),
+               new OrderedValueVarargsOptionParser(), new ParseErrorParser());
+
+      commandParser.parse(command, valueMap, tokens);
+
+      Object[] parameters = new Object[command.getOptions().size()];
+      for (OptionMetadata option : command.getOptions())
+      {
+         Object value = valueMap.get(option);
+         if (option.isRequired() && (value == null))
+         {
+            throw new IllegalStateException("Command is missing required option: " + option);
+         }
+
+         parameters[option.getIndex()] = value;
+      }
+
+      return parameters;
+   }
 }

Deleted: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Option.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Option.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Option.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -1,60 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.encore.shell.cli;
-
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * A command option.
- * 
- * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
- * 
- */
- at Qualifier
- at Target({ METHOD, PARAMETER })
- at Retention(RUNTIME)
- at Documented
-public @interface Option
-{
-   /**
-    * The name of this option;
-    */
-   String value() default "";
-
-   /**
-    * Specify whether or not this option is required.
-    */
-   boolean requred() default false;
-
-   /**
-    * Help text for this option.
-    */
-   String help() default "";
-}

Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/OptionMetadata.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/OptionMetadata.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/OptionMetadata.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -109,4 +109,14 @@
       this.parent = parent;
    }
 
+   public boolean isBoolean()
+   {
+      return (Boolean.TYPE.equals(getType()) || Boolean.class.equals(getType()));
+   }
+
+   public boolean isVarargs()
+   {
+      return getType().isArray();
+   }
+
 }

Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginCommandCompletionHandler.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginCommandCompletionHandler.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginCommandCompletionHandler.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -23,6 +23,7 @@
 
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.inject.Inject;
 
@@ -45,27 +46,36 @@
       String[] tokens = buffer.split("\\s+");
       if (tokens.length == 1)
       {
-         String plugin = tokens[0];
-         for (String pluginName : plugins.keySet())
+         String token = tokens[0];
+         for (Entry<String, PluginMetadata> p : plugins.entrySet())
          {
-            if (pluginName.startsWith(plugin))
+            String pluginName = p.getValue().getName();
+            if (isPotentialMatch(pluginName, token))
             {
                PluginMetadata pluginMetadata = plugins.get(pluginName);
-               if (pluginMetadata.isImplicitCommand())
+               if (pluginMetadata.isBuiltIn() && pluginMetadata.isImplicitCommand())
                {
                   List<String> names = pluginMetadata.getCommands().get(0).getNames();
                   for (String name : names)
                   {
-                     candidates.add(name);
+                     if (isPotentialMatch(name, token))
+                     {
+                        candidates.add(name.toLowerCase() + " ");
+                     }
                   }
                }
                else
                {
-                  candidates.add(pluginName);
+                  candidates.add(pluginName.toLowerCase() + " ");
                }
             }
          }
       }
       return 0;
    }
+
+   private boolean isPotentialMatch(final String name, final String token)
+   {
+      return name.matches("(?i)" + token + ".*");
+   }
 }

Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginMetadata.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginMetadata.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginMetadata.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -61,7 +61,7 @@
     */
    public boolean isImplicitCommand()
    {
-      return commands.size() == 1;
+      return (commands.size() == 1) && isBuiltIn();
    }
 
    public String getName()

Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/Echo.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/Echo.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/Echo.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli.builtin;
+
+import javax.inject.Inject;
+
+import org.jboss.encore.shell.Shell;
+import org.jboss.encore.shell.plugins.Command;
+import org.jboss.encore.shell.plugins.Option;
+import org.jboss.encore.shell.plugins.Plugin;
+
+/**
+ * Implements a demonstration {@link Plugin}
+ * 
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class Echo implements Plugin
+{
+   @Inject
+   Shell shell;
+
+   @Command(help = "This is a demo command")
+   public void run(@Option(help = "The text to be echoed") final String text)
+   {
+      shell.write("Echo plugin says: \"" + text + "\"");
+   }
+}

Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/ExitShell.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/ExitShell.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/ExitShell.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -24,9 +24,9 @@
 import javax.enterprise.event.Event;
 import javax.inject.Inject;
 
-import org.jboss.encore.shell.cli.BuiltIn;
-import org.jboss.encore.shell.cli.Command;
 import org.jboss.encore.shell.events.Shutdown;
+import org.jboss.encore.shell.plugins.BuiltIn;
+import org.jboss.encore.shell.plugins.Command;
 import org.jboss.encore.shell.plugins.Plugin;
 
 /**

Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/Help.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/Help.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/Help.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -21,14 +21,12 @@
  */
 package org.jboss.encore.shell.cli.builtin;
 
-import javax.enterprise.event.Event;
-import javax.inject.Inject;
-import javax.inject.Named;
+import java.util.Arrays;
 
-import org.jboss.encore.shell.cli.BuiltIn;
-import org.jboss.encore.shell.cli.Command;
-import org.jboss.encore.shell.cli.Option;
 import org.jboss.encore.shell.events.Shutdown;
+import org.jboss.encore.shell.plugins.BuiltIn;
+import org.jboss.encore.shell.plugins.Command;
+import org.jboss.encore.shell.plugins.Option;
 import org.jboss.encore.shell.plugins.Plugin;
 
 /**
@@ -38,15 +36,18 @@
  * 
  */
 @BuiltIn
- at Named("help")
 public class Help implements Plugin
 {
-   @Inject
-   private Event<Shutdown> shutdown;
-
    @Command(help = "Get help about specific commands")
-   public void help(@Option(requred = true) final String command, @Option final String subcommand)
+   public void help(@Option("test") final String test, @Option final String... commands)
    {
-      System.out.println("You requested help for: " + command);
+      if (commands == null)
+      {
+         System.out.println("Welcome to Encore!");
+      }
+      else
+      {
+         System.out.println("You requested help for: " + Arrays.deepToString(commands));
+      }
    }
 }

Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/CommandParser.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/CommandParser.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/CommandParser.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli.parser;
+
+import java.util.Map;
+import java.util.Queue;
+
+import org.jboss.encore.shell.cli.CommandMetadata;
+import org.jboss.encore.shell.cli.OptionMetadata;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public interface CommandParser
+{
+   public void parse(CommandMetadata command, Map<OptionMetadata, Object> valueMap, Queue<String> tokens);
+}

Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/CompositeCommandParser.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/CompositeCommandParser.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/CompositeCommandParser.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli.parser;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+
+import org.jboss.encore.shell.cli.CommandMetadata;
+import org.jboss.encore.shell.cli.OptionMetadata;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class CompositeCommandParser implements CommandParser
+{
+   List<CommandParser> parsers = new ArrayList<CommandParser>();
+
+   public CompositeCommandParser(final CommandParser... parsers)
+   {
+      this.parsers = Arrays.asList(parsers);
+   }
+
+   @Override
+   public void parse(final CommandMetadata command, final Map<OptionMetadata, Object> valueMap,
+            final Queue<String> tokens)
+   {
+      boolean complete = false;
+      while (!complete)
+      {
+         boolean altered = false;
+         for (CommandParser parser : parsers)
+         {
+            if (tokens.size() == 0)
+            {
+               complete = true;
+               break;
+            }
+
+            int size = tokens.size();
+            parser.parse(command, valueMap, tokens);
+
+            if (size > tokens.size())
+            {
+               altered = true;
+               break;
+            }
+         }
+
+         if (!altered)
+         {
+            break;
+         }
+      }
+   }
+
+}

Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/NamedBooleanOptionParser.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/NamedBooleanOptionParser.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/NamedBooleanOptionParser.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli.parser;
+
+import java.util.Map;
+import java.util.Queue;
+
+import org.jboss.encore.shell.cli.CommandMetadata;
+import org.jboss.encore.shell.cli.OptionMetadata;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class NamedBooleanOptionParser implements CommandParser
+{
+
+   @Override
+   public void parse(final CommandMetadata command, final Map<OptionMetadata, Object> valueMap,
+            final Queue<String> tokens)
+   {
+      String currentToken = tokens.peek();
+      if (currentToken.startsWith("--"))
+      {
+         currentToken = currentToken.substring(2);
+         OptionMetadata option = command.getNamedOption(currentToken);
+
+         if (option.isBoolean())
+         {
+            tokens.remove();
+            String value = "true";
+            if (!tokens.isEmpty())
+            {
+               String nextToken = tokens.peek();
+               if (nextToken.matches("true|false"))
+               {
+                  value = nextToken;
+                  tokens.remove(); // increment the chain of tokens
+               }
+            }
+            valueMap.put(option, value); // add the value, should we return this as a tuple instead?
+         }
+      }
+   }
+
+}

Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/NamedValueOptionParser.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/NamedValueOptionParser.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/NamedValueOptionParser.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli.parser;
+
+import java.util.Map;
+import java.util.Queue;
+
+import org.jboss.encore.shell.cli.CommandMetadata;
+import org.jboss.encore.shell.cli.OptionMetadata;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class NamedValueOptionParser implements CommandParser
+{
+
+   @Override
+   public void parse(final CommandMetadata command, final Map<OptionMetadata, Object> valueMap,
+            final Queue<String> tokens)
+   {
+      String currentToken = tokens.peek();
+      if (currentToken.startsWith("--"))
+      {
+         currentToken = currentToken.substring(2);
+         OptionMetadata option = command.getNamedOption(currentToken);
+         tokens.remove();
+
+         if (!option.isBoolean())
+         {
+            String value = null;
+            if (!tokens.isEmpty())
+            {
+               String nextToken = tokens.peek();
+               if (!nextToken.startsWith("--"))
+               {
+                  value = nextToken;
+                  tokens.remove(); // increment the chain of tokens
+               }
+            }
+            valueMap.put(option, value); // add the value, should we return this as a tuple instead?
+         }
+      }
+   }
+
+}

Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/NamedValueVarargsOptionParser.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/NamedValueVarargsOptionParser.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/NamedValueVarargsOptionParser.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+
+import org.jboss.encore.shell.cli.CommandMetadata;
+import org.jboss.encore.shell.cli.OptionMetadata;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class NamedValueVarargsOptionParser implements CommandParser
+{
+
+   @Override
+   public void parse(final CommandMetadata command, final Map<OptionMetadata, Object> valueMap,
+            final Queue<String> tokens)
+   {
+      String currentToken = tokens.peek();
+      if (currentToken.startsWith("--"))
+      {
+         currentToken = currentToken.substring(2);
+         OptionMetadata option = command.getNamedOption(currentToken);
+         if (option.isVarargs())
+         {
+            tokens.remove();
+            List<String> args = new ArrayList<String>();
+            while (!tokens.peek().startsWith("--"))
+            {
+               args.add(tokens.remove());
+            }
+            valueMap.put(option, args.toArray()); // add the value, should we return this as a tuple instead?
+         }
+      }
+   }
+
+   /**
+    * Return a count of how many ordered params have already been parsed.
+    */
+   private int getNumberOrderedParamsIn(final Map<OptionMetadata, Object> valueMap)
+   {
+      int result = 0;
+      for (OptionMetadata option : valueMap.keySet())
+      {
+         if (!option.isNamed())
+         {
+            result++;
+         }
+      }
+      return result;
+   }
+
+}

Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/OrderedValueOptionParser.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/OrderedValueOptionParser.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/OrderedValueOptionParser.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli.parser;
+
+import java.util.Map;
+import java.util.Queue;
+
+import org.jboss.encore.shell.cli.CommandMetadata;
+import org.jboss.encore.shell.cli.OptionMetadata;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class OrderedValueOptionParser implements CommandParser
+{
+
+   @Override
+   public void parse(final CommandMetadata command, final Map<OptionMetadata, Object> valueMap,
+            final Queue<String> tokens)
+   {
+      String currentToken = tokens.peek();
+      if (!currentToken.startsWith("--"))
+      {
+         OptionMetadata option = command.getOrderedOptionByIndex(getNumberOrderedParamsIn(valueMap));
+         if (!option.isVarargs())
+         {
+            valueMap.put(option, currentToken); // add the value, should we return this as a tuple instead?
+            tokens.remove();
+         }
+      }
+   }
+
+   /**
+    * Return a count of how many ordered params have already been parsed.
+    */
+   private int getNumberOrderedParamsIn(final Map<OptionMetadata, Object> valueMap)
+   {
+      int result = 0;
+      for (OptionMetadata option : valueMap.keySet())
+      {
+         if (!option.isNamed())
+         {
+            result++;
+         }
+      }
+      return result;
+   }
+
+}

Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/OrderedValueVarargsOptionParser.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/OrderedValueVarargsOptionParser.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/OrderedValueVarargsOptionParser.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli.parser;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+
+import org.jboss.encore.shell.cli.CommandMetadata;
+import org.jboss.encore.shell.cli.OptionMetadata;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class OrderedValueVarargsOptionParser implements CommandParser
+{
+
+   @Override
+   public void parse(final CommandMetadata command, final Map<OptionMetadata, Object> valueMap,
+            final Queue<String> tokens)
+   {
+      String currentToken = tokens.peek();
+      if (!currentToken.startsWith("--"))
+      {
+         OptionMetadata option = command.getOrderedOptionByIndex(getNumberOrderedParamsIn(valueMap));
+         if (option.isVarargs())
+         {
+            List<String> args = new ArrayList<String>();
+            while (!tokens.isEmpty() && !tokens.peek().startsWith("--"))
+            {
+               args.add(tokens.remove());
+            }
+            valueMap.put(option, args.toArray(new String[0])); // add the value, should we return this as a tuple
+                                                               // instead?
+         }
+      }
+   }
+
+   /**
+    * Return a count of how many ordered params have already been parsed.
+    */
+   private int getNumberOrderedParamsIn(final Map<OptionMetadata, Object> valueMap)
+   {
+      int result = 0;
+      for (OptionMetadata option : valueMap.keySet())
+      {
+         if (!option.isNamed())
+         {
+            result++;
+         }
+      }
+      return result;
+   }
+
+}

Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/ParseErrorParser.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/ParseErrorParser.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/parser/ParseErrorParser.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli.parser;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Queue;
+
+import org.jboss.encore.shell.cli.CommandMetadata;
+import org.jboss.encore.shell.cli.OptionMetadata;
+
+/**
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+public class ParseErrorParser implements CommandParser
+{
+
+   @Override
+   public void parse(final CommandMetadata command, final Map<OptionMetadata, Object> valueMap,
+            final Queue<String> tokens)
+   {
+      String token = tokens.peek();
+      String commandNames = Arrays.deepToString(command.getNames().toArray());
+      throw new IllegalStateException("Error parsing token [" + token + "] for command: " + commandNames);
+   }
+
+}

Copied: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/BuiltIn.java (from rev 13360, sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/BuiltIn.java)
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/BuiltIn.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/BuiltIn.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.plugins;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+
+/**
+ * Defines a #{@link Plugin} as built in, thus, commands will be accessible without providing a plugin name;
+ * 
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+ at Target({ TYPE, METHOD, PARAMETER, FIELD })
+ at Retention(RUNTIME)
+ at Documented
+public @interface BuiltIn
+{
+
+}

Copied: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Command.java (from rev 13360, sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Command.java)
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Command.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Command.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.plugins;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * Represents a single command to be run on a Shell.
+ * 
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+ at Qualifier
+ at Target({ METHOD, PARAMETER, TYPE, FIELD })
+ at Retention(RUNTIME)
+ at Documented
+public @interface Command
+{
+   /**
+    * One or more names for this command.
+    */
+   String[] value() default {};
+
+   /**
+    * Help text for this command.
+    */
+   String help() default "";
+}

Copied: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Option.java (from rev 13360, sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Option.java)
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Option.java	                        (rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Option.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.encore.shell.plugins;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * A command option.
+ * 
+ * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
+ * 
+ */
+ at Qualifier
+ at Target({ METHOD, PARAMETER })
+ at Retention(RUNTIME)
+ at Documented
+public @interface Option
+{
+   /**
+    * The name of this option;
+    */
+   String value() default "";
+
+   /**
+    * Specify whether or not this option is required.
+    */
+   boolean required() default false;
+
+   /**
+    * The default value for this option, if not provided in user input.
+    */
+   String defaultValue() default "";
+
+   /**
+    * Help text for this option.
+    */
+   String help() default "";
+}

Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Plugin.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Plugin.java	2010-07-11 01:16:28 UTC (rev 13360)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Plugin.java	2010-07-12 22:29:39 UTC (rev 13361)
@@ -21,9 +21,15 @@
  */
 package org.jboss.encore.shell.plugins;
 
+
 /**
+ * A custom {@link Plugin} must implement this interface in order to be detected and installed at framework boot-time.
+ * In order to create plugin shell-commands, one must create a method annotated with @{@link Command}. Any command
+ * method parameters to be provided as input through the shell must be individually annotated with the @{@link Option}
+ * annotation; other (non-annotated) command parameters are ignored.
+ * 
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
- *
+ * 
  */
 public interface Plugin
 {



More information about the seam-commits mailing list