You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2008/06/20 16:52:30 UTC
svn commit: r669926 - in /geronimo/gshell/trunk:
gshell-api/src/main/java/org/apache/geronimo/gshell/command/
gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/
gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/
Author: jdillon
Date: Fri Jun 20 07:52:30 2008
New Revision: 669926
URL: http://svn.apache.org/viewvc?rev=669926&view=rev
Log:
Hook up the CommandDocumenter for --help rendering
Modified:
geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandCompleter.java
geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandDocumenter.java
geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandCompleterDescriptor.java
geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandDocumenterDescriptor.java
geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommand.java
geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandCompleter.java
geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandDocumenter.java
geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandFactory.java
Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandCompleter.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandCompleter.java?rev=669926&r1=669925&r2=669926&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandCompleter.java (original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandCompleter.java Fri Jun 20 07:52:30 2008
@@ -32,5 +32,5 @@
// TODO: Not really sure this is what we want to do, but for now...
//
- Completor createCompletor();
+ Completor createCompletor(CommandInfo info);
}
\ No newline at end of file
Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandDocumenter.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandDocumenter.java?rev=669926&r1=669925&r2=669926&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandDocumenter.java (original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandDocumenter.java Fri Jun 20 07:52:30 2008
@@ -33,26 +33,30 @@
*
* @return The configured name of the command.
*/
- String getName();
+ String getName(CommandInfo info);
/**
* Get the terse description of the command.
*
* @return The configured description of hte command.
*/
- String getDescription();
+ String getDescription(CommandInfo info);
/**
* Render the command-line usage, as expected from <tt>--help</tt>.
*
* @param out Write the usage to this writer.
*/
- void renderUsage(PrintWriter out);
+ void renderUsage(CommandInfo info, PrintWriter out);
/**
* Render the full command manual.
*
* @param out Write the manual to this writer.
*/
- void renderManual(PrintWriter out);
+ void renderManual(CommandInfo info, PrintWriter out);
+
+ //
+ // TODO: Consider making this a factory, returning a CommandDocumentation for a CommandInfo
+ //
}
\ No newline at end of file
Modified: geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandCompleterDescriptor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandCompleterDescriptor.java?rev=669926&r1=669925&r2=669926&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandCompleterDescriptor.java (original)
+++ geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandCompleterDescriptor.java Fri Jun 20 07:52:30 2008
@@ -44,10 +44,6 @@
setVersion(model.getVersion());
setIsolatedRealm(false);
setInstantiationStrategy("singleton");
-
- XmlPlexusConfiguration config = new XmlPlexusConfiguration("configuration");
- config.addChild(new XmlPlexusConfiguration("commandId", model.getId()));
- setConfiguration(config);
}
public CommandModel getCommand() {
Modified: geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandDocumenterDescriptor.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandDocumenterDescriptor.java?rev=669926&r1=669925&r2=669926&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandDocumenterDescriptor.java (original)
+++ geronimo/gshell/trunk/gshell-plugin/src/main/java/org/apache/geronimo/gshell/plugin/descriptor/CommandDocumenterDescriptor.java Fri Jun 20 07:52:30 2008
@@ -44,10 +44,6 @@
setVersion(model.getVersion());
setIsolatedRealm(false);
setInstantiationStrategy("singleton");
-
- XmlPlexusConfiguration config = new XmlPlexusConfiguration("configuration");
- config.addChild(new XmlPlexusConfiguration("commandId", model.getId()));
- setConfiguration(config);
}
public CommandModel getCommand() {
Modified: geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommand.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommand.java?rev=669926&r1=669925&r2=669926&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommand.java (original)
+++ geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommand.java Fri Jun 20 07:52:30 2008
@@ -158,6 +158,16 @@
return result;
}
+ /**
+ * Process command-line arguments for the action.
+ *
+ * @param context The command context.
+ * @param action The action being executed.
+ * @param args The arguments to the action.
+ * @return True if --help was detetected, else execute the action.
+ *
+ * @throws ProcessingException A failure occured while processing the command-line.
+ */
private boolean processArguments(final CommandContext context, final CommandAction action, final Object[] args) throws ProcessingException {
assert context != null;
assert args != null;
@@ -166,41 +176,29 @@
clp.addBean(action);
// Attach some help context
+ CommandDocumenter documenter = getDocumenter();
HelpSupport help = new HelpSupport();
clp.addBean(help);
+ clp.addBean(documenter);
// Process the arguments
clp.process(Arguments.toStringArray(args));
- // Display help if option detected
+ // Render command-line usage
if (help.displayHelp) {
- help.display(context, clp);
+ documenter.renderUsage(context.getInfo(), context.getIo().out);
return true;
}
-
+
return false;
}
- private static class HelpSupport
+ /**
+ * Helper to inject <tt>--help<tt> support. Package access to allow DefaultCommandDocumentor access.
+ */
+ static class HelpSupport
{
@Option(name="-h", aliases={"--help"}, description="Display this help message", requireOverride=true)
public boolean displayHelp;
-
- protected void display(final CommandContext context, final CommandLineProcessor clp) {
- assert context != null;
- assert clp != null;
-
- // Use the alias if we have one, else use the command name
- CommandInfo info = context.getInfo();
- String name = info.getAlias();
- if (name == null) {
- name = info.getName();
- }
-
- IO io = context.getIo();
- Printer printer = new Printer(clp);
- printer.printUsage(io.out, name);
- io.out.println();
- }
}
}
\ No newline at end of file
Modified: geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandCompleter.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandCompleter.java?rev=669926&r1=669925&r2=669926&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandCompleter.java (original)
+++ geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandCompleter.java Fri Jun 20 07:52:30 2008
@@ -19,29 +19,28 @@
package org.apache.geronimo.gshell.rapture;
+import jline.Completor;
import org.apache.geronimo.gshell.command.CommandCompleter;
import org.apache.geronimo.gshell.command.CommandDocumenter;
+import org.apache.geronimo.gshell.command.CommandInfo;
import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import jline.Completor;
/**
- * The default {@link org.apache.geronimo.gshell.command.CommandCompleter} component.
+ * The default {@link CommandCompleter} component.
*
* @version $Rev$ $Date$
*/
-@Component(role= CommandDocumenter.class)
+@Component(role=CommandDocumenter.class)
public class DefaultCommandCompleter
implements CommandCompleter
{
private final Logger log = LoggerFactory.getLogger(getClass());
- @Configuration("")
- private String commandId;
+ public Completor createCompletor(final CommandInfo info) {
+ assert info != null;
- public Completor createCompletor() {
// TODO:
throw new Error();
Modified: geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandDocumenter.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandDocumenter.java?rev=669926&r1=669925&r2=669926&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandDocumenter.java (original)
+++ geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandDocumenter.java Fri Jun 20 07:52:30 2008
@@ -19,45 +19,125 @@
package org.apache.geronimo.gshell.rapture;
+import org.apache.geronimo.gshell.clp.CommandLineProcessor;
+import org.apache.geronimo.gshell.clp.Printer;
+import org.apache.geronimo.gshell.command.CommandAction;
import org.apache.geronimo.gshell.command.CommandDocumenter;
+import org.apache.geronimo.gshell.command.CommandInfo;
+import org.apache.geronimo.gshell.command.annotation.CommandComponent;
+import org.apache.geronimo.gshell.plexus.GShellPlexusContainer;
+import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Configuration;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.PrintWriter;
/**
- * The default {@link org.apache.geronimo.gshell.command.CommandDocumenter} component.
+ * The default {@link CommandDocumenter} component.
*
* @version $Rev$ $Date$
*/
-@Component(role= CommandDocumenter.class)
+@Component(role=CommandDocumenter.class)
public class DefaultCommandDocumenter
- implements CommandDocumenter
+ implements CommandDocumenter, Contextualizable
{
private final Logger log = LoggerFactory.getLogger(getClass());
- @Configuration("") // Just to mark what this is used for, since we have to configure a default value
- private String commandId;
+ private GShellPlexusContainer container;
- public String getName() {
- return null;
+ // Contextualizable
+
+ public void contextualize(final Context context) throws ContextException {
+ assert context != null;
+
+ container = (GShellPlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
+ assert container != null;
+
+ log.debug("Container: {}", container);
+ }
+
+ // CommandDocumenter
+
+ public String getName(final CommandInfo info) {
+ assert info != null;
+
+ // Use the alias if we have one, else use the command name
+ String name = info.getAlias();
+ if (name == null) {
+ name = info.getName();
+ }
+
+ return name;
+ }
+
+ public String getDescription(final CommandInfo info) {
+ assert info != null;
+
+ //
+ // HACK: This needs to chagne, doing this for now to make it work
+ //
+
+ CommandAction action = getAction(info);
+ CommandComponent cmd = action.getClass().getAnnotation(CommandComponent.class);
+ if (cmd == null) {
+ throw new IllegalStateException("Command description not found");
+ }
+
+ return cmd.description();
}
- public String getDescription() {
- return null;
+ /**
+ * Get the action instance for the given command context.
+ */
+ private CommandAction getAction(final CommandInfo info) {
+ assert info != null;
+ assert container != null;
+
+ try {
+ return container.lookupComponent(CommandAction.class, info.getId());
+ }
+ catch (ComponentLookupException e) {
+ throw new RuntimeException(e);
+ }
}
- public void renderUsage(final PrintWriter out) {
+ public void renderUsage(final CommandInfo info, final PrintWriter out) {
+ assert info != null;
assert out != null;
- // TODO:
+ CommandLineProcessor clp = new CommandLineProcessor();
+
+ // Attach our helper to inject --help
+ DefaultCommand.HelpSupport help = new DefaultCommand.HelpSupport();
+ clp.addBean(help);
+
+ // And then the beans options
+ CommandAction action = getAction(info);
+ clp.addBean(action);
+
+ // Fetch the details
+ String name = getName(info);
+ String desc = getDescription(info);
+
+ // Render the help
+ out.println(desc);
+ out.println();
+
+ Printer printer = new Printer(clp);
+ printer.printUsage(out, name);
+
+ out.println();
}
- public void renderManual(final PrintWriter out) {
+ public void renderManual(final CommandInfo info, final PrintWriter out) {
+ assert info != null;
assert out != null;
- // TODO:
+ // TODO: Render a more complete manual for the command, maybe using simple APT-like syntax.
}
}
\ No newline at end of file
Modified: geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandFactory.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandFactory.java?rev=669926&r1=669925&r2=669926&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandFactory.java (original)
+++ geronimo/gshell/trunk/gshell-rapture/src/main/java/org/apache/geronimo/gshell/rapture/DefaultCommandFactory.java Fri Jun 20 07:52:30 2008
@@ -37,7 +37,7 @@
*
* @version $Rev$ $Date$
*/
-@Component(role= CommandFactory.class)
+@Component(role=CommandFactory.class)
public class DefaultCommandFactory
implements CommandFactory, Contextualizable
{