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/09/18 20:22:35 UTC
svn commit: r696750 - in /geronimo/gshell/trunk:
gshell-api/src/main/java/org/apache/geronimo/gshell/command/
gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/
gshell-commands/gshell-builtins/src/main/resources...
Author: jdillon
Date: Thu Sep 18 11:22:34 2008
New Revision: 696750
URL: http://svn.apache.org/viewvc?rev=696750&view=rev
Log:
Add CommandRegistration and expose it from CommandRegistry muck
Got the help command back up and functional to display terse help for a set of commands and the verbose manuals for specific commands
Added:
geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistration.java
- copied, changed from r696697, geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java
Modified:
geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java
geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/HelpCommand.properties
geronimo/gshell/trunk/gshell-commands/gshell-repository/src/main/java/org/apache/geronimo/gshell/commands/repository/ResolveCommand.java
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandManager.java
geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandRegisteredEvent.java
Copied: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistration.java (from r696697, geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java)
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistration.java?p2=geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistration.java&p1=geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java&r1=696697&r2=696750&rev=696750&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java (original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistration.java Thu Sep 18 11:22:34 2008
@@ -20,20 +20,11 @@
package org.apache.geronimo.gshell.command;
/**
- * Provides registration facilities for {@link Command} instances.
+ * ???
*
* @version $Rev$ $Date$
*/
-public interface CommandRegistry
+public interface CommandRegistration
{
- /**
- * Registers a command.
- *
- * @param command The command to register; must not be null.
- */
- void register(Command command);
-
- //
- // TODO: Expose registration details for help command support
- //
+ Command getCommand();
}
\ No newline at end of file
Modified: geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java?rev=696750&r1=696749&r2=696750&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java (original)
+++ geronimo/gshell/trunk/gshell-api/src/main/java/org/apache/geronimo/gshell/command/CommandRegistry.java Thu Sep 18 11:22:34 2008
@@ -19,6 +19,8 @@
package org.apache.geronimo.gshell.command;
+import java.util.List;
+
/**
* Provides registration facilities for {@link Command} instances.
*
@@ -26,14 +28,7 @@
*/
public interface CommandRegistry
{
- /**
- * Registers a command.
- *
- * @param command The command to register; must not be null.
- */
- void register(Command command);
+ CommandRegistration register(Command command);
- //
- // TODO: Expose registration details for help command support
- //
+ List<CommandRegistration> getRegistrations();
}
\ No newline at end of file
Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java?rev=696750&r1=696749&r2=696750&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/java/org/apache/geronimo/gshell/commands/builtins/HelpCommand.java Thu Sep 18 11:22:34 2008
@@ -19,14 +19,25 @@
package org.apache.geronimo.gshell.commands.builtins;
+import org.apache.geronimo.gshell.ansi.Code;
+import org.apache.geronimo.gshell.ansi.Renderer;
import org.apache.geronimo.gshell.clp.Argument;
import org.apache.geronimo.gshell.command.CommandAction;
import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.command.CommandRegistry;
+import org.apache.geronimo.gshell.command.CommandRegistration;
+import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.command.CommandDocumenter;
+import org.apache.geronimo.gshell.io.IO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.util.List;
/**
- * Display help
+ * Display command help.
*
* @version $Rev$ $Date$
*/
@@ -35,12 +46,70 @@
{
private final Logger log = LoggerFactory.getLogger(getClass());
- @Argument(metaVar="COMMAND", required=true)
- private String command;
+ @Autowired
+ private CommandRegistry commandRegistry;
+
+ @Argument(metaVar="COMMAND")
+ private String commandName;
+
+ private Renderer renderer = new Renderer();
public Object execute(final CommandContext context) throws Exception {
assert context != null;
+ IO io = context.getIo();
+
+ assert commandRegistry != null;
+ List<CommandRegistration> registrations = commandRegistry.getRegistrations();
+
+ if (commandName != null) {
+ log.debug("Displaying help manual for command: {}", commandName);
+
+ // FIXME: Should resolve the commandName/commandPath
+
+ for (CommandRegistration registration : registrations) {
+ Command command = registration.getCommand();
+ CommandDocumenter doc = command.getDocumenter();
+
+ if (doc.getName().equals(commandName)) {
+ doc.renderManual(io.out);
+
+ return Result.SUCCESS;
+ }
+ }
+
+ io.out.println("Command " + Renderer.encode(commandName, Code.BOLD) + " not found.");
+ io.out.println("Try " + Renderer.encode("help", Code.BOLD) + " for a list of available commands.");
+
+ return Result.FAILURE;
+ }
+ else {
+ log.debug("Listing brief help for commands");
+
+ // FIXME: Figure this out dynamically
+ int maxNameLen = 20;
+
+ io.out.println("Available commands:");
+
+ for (CommandRegistration registration : registrations) {
+ Command command = registration.getCommand();
+ CommandDocumenter doc = command.getDocumenter();
+
+ String name = StringUtils.rightPad(doc.getName(), maxNameLen);
+ String desc = doc.getDescription();
+
+ io.out.print(" ");
+ io.out.print(renderer.render(Renderer.encode(name, Code.BOLD)));
+
+ if (desc != null) {
+ io.out.print(" ");
+ io.out.println(desc);
+ }
+ else {
+ io.out.println();
+ }
+ }
+ }
- throw new Error("Not implemented");
+ return Result.SUCCESS;
}
}
Modified: geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/HelpCommand.properties
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/HelpCommand.properties?rev=696750&r1=696749&r2=696750&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/HelpCommand.properties (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-builtins/src/main/resources/org/apache/geronimo/gshell/commands/builtins/HelpCommand.properties Thu Sep 18 11:22:34 2008
@@ -25,7 +25,7 @@
command.description=Display help for the current context.
-command.argument.command=Display help for COMMAND
+command.argument.commandName=Display help for COMMAND
command.manual=\
TODO: help manual
\ No newline at end of file
Modified: geronimo/gshell/trunk/gshell-commands/gshell-repository/src/main/java/org/apache/geronimo/gshell/commands/repository/ResolveCommand.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-repository/src/main/java/org/apache/geronimo/gshell/commands/repository/ResolveCommand.java?rev=696750&r1=696749&r2=696750&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-repository/src/main/java/org/apache/geronimo/gshell/commands/repository/ResolveCommand.java (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-repository/src/main/java/org/apache/geronimo/gshell/commands/repository/ResolveCommand.java Thu Sep 18 11:22:34 2008
@@ -65,6 +65,10 @@
@Option(name="-t", aliases={"--type"}, argumentRequired=true, metaVar="TYPE")
private String type = "jar";
+ //
+ // TODO: Add classifier
+ //
+
@Option(name="-s", aliases={"--scope"}, argumentRequired=true, metaVar="SCOPE")
private String scope;
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandManager.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandManager.java?rev=696750&r1=696749&r2=696750&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandManager.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandManager.java Thu Sep 18 11:22:34 2008
@@ -25,6 +25,7 @@
import org.apache.geronimo.gshell.command.CommandException;
import org.apache.geronimo.gshell.command.CommandNotFoundException;
import org.apache.geronimo.gshell.command.Variables;
+import org.apache.geronimo.gshell.command.CommandRegistration;
import org.apache.geronimo.gshell.event.EventPublisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,6 +33,8 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
/**
* Provides management of {@link Command} instances.
@@ -46,22 +49,34 @@
@Autowired
private EventPublisher eventPublisher;
- private Map<String, Command> registrations = new HashMap<String, Command>();
+ private List<CommandRegistration> registrations = new ArrayList<CommandRegistration>();
//
// CommandRegistry
//
- public void register(final Command command) {
+ public CommandRegistration register(final Command command) {
assert command != null;
String id = command.getId();
log.debug("Registering command: {}", id);
-
- registrations.put(id, command);
- eventPublisher.publish(new CommandRegisteredEvent(command));
+ CommandRegistration registration = new CommandRegistration() {
+ public Command getCommand() {
+ return command;
+ }
+ };
+
+ registrations.add(registration);
+
+ eventPublisher.publish(new CommandRegisteredEvent(registration));
+
+ return registration;
+ }
+
+ public List<CommandRegistration> getRegistrations() {
+ return registrations;
}
//
@@ -75,9 +90,9 @@
log.debug("Resolving command for path: {}", path);
// HACK: For now, there is no nested muck, just use the name
- for (Command command : registrations.values()) {
- if (path.equals(command.getDocumenter().getName())) {
- return command;
+ for (CommandRegistration registration : registrations) {
+ if (path.equals(registration.getCommand().getDocumenter().getName())) {
+ return registration.getCommand();
}
}
Modified: geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandRegisteredEvent.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandRegisteredEvent.java?rev=696750&r1=696749&r2=696750&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandRegisteredEvent.java (original)
+++ geronimo/gshell/trunk/gshell-wisdom/gshell-wisdom-core/src/main/java/org/apache/geronimo/gshell/wisdom/command/CommandRegisteredEvent.java Thu Sep 18 11:22:34 2008
@@ -19,7 +19,7 @@
package org.apache.geronimo.gshell.wisdom.command;
-import org.apache.geronimo.gshell.command.Command;
+import org.apache.geronimo.gshell.command.CommandRegistration;
import org.apache.geronimo.gshell.event.Event;
/**
@@ -30,15 +30,15 @@
public class CommandRegisteredEvent
implements Event
{
- private final Command command;
+ private final CommandRegistration registration;
- public CommandRegisteredEvent(final Command command) {
- assert command != null;
+ public CommandRegisteredEvent(final CommandRegistration registration) {
+ assert registration != null;
- this.command = command;
+ this.registration = registration;
}
- public Command getCommand() {
- return command;
+ public CommandRegistration getRegistration() {
+ return registration;
}
}
\ No newline at end of file