SHL-6 support help command

This commit is contained in:
Jarred Li
2012-04-07 13:23:12 +08:00
parent 8d0adc1651
commit 070da47f5b
2 changed files with 37 additions and 17 deletions

View File

@@ -79,13 +79,8 @@ public class Bootstrap {
createApplicationContext(applicationContextLocation);
Map<String, JLineShellComponent> shells = ctx.getBeansOfType(JLineShellComponent.class);
//Assert.isTrue(shells.size() == 1, "Exactly one Shell was required, but " + shells.size() + " found");
//shell = shells.values().iterator().next();
shell = new JLineShellComponent();
//shell = new JLineShellComponent();
shell = ctx.getBean("shell", JLineShellComponent.class);
Map<String, CommandMarker> commands = ctx.getBeansOfType(CommandMarker.class);
@@ -142,6 +137,8 @@ public class Bootstrap {
createAndRegisterBeanDefinition(annctx, org.springframework.roo.shell.converters.LongConverter.class);
createAndRegisterBeanDefinition(annctx, org.springframework.roo.shell.converters.ShortConverter.class);
createAndRegisterBeanDefinition(annctx, org.springframework.roo.shell.converters.StaticFieldConverterImpl.class);
createAndRegisterBeanDefinition(annctx, org.springframework.shell.JLineShellComponent.class, "shell");
createAndRegisterBeanDefinition(annctx, org.springframework.shell.converters.SimpleFileConverter.class);
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
PluginConfigurationReader configReader = new PluginConfigurationReader(resourcePatternResolver);
@@ -165,10 +162,19 @@ public class Bootstrap {
ctx = annctx;
}
protected void createAndRegisterBeanDefinition(AnnotationConfigApplicationContext annctx, Class clazz) {
protected void createAndRegisterBeanDefinition(AnnotationConfigApplicationContext annctx, Class clazz){
createAndRegisterBeanDefinition(annctx,clazz,null);
}
protected void createAndRegisterBeanDefinition(AnnotationConfigApplicationContext annctx, Class clazz,String name) {
RootBeanDefinition rbd = new RootBeanDefinition();
rbd.setBeanClass(clazz);
annctx.registerBeanDefinition(clazz.getSimpleName(), rbd);
if(name != null){
annctx.registerBeanDefinition(name, rbd);
}
else{
annctx.registerBeanDefinition(clazz.getSimpleName(), rbd);
}
}
protected ExitShellRequest run(String[] executeThenQuit) {

View File

@@ -1,9 +1,13 @@
package org.springframework.shell.commands;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.roo.shell.CliCommand;
import org.springframework.roo.shell.CliOption;
import org.springframework.roo.shell.CommandMarker;
import org.springframework.roo.shell.SimpleParser;
import org.springframework.shell.JLineShellComponent;
import org.springframework.stereotype.Component;
/**
@@ -11,17 +15,27 @@ import org.springframework.stereotype.Component;
*
* @author Ben Alex
* @author Mark Pollack
* @author Jarred Li
*
*/
@Component
public class HelpCommands extends SimpleParser implements CommandMarker {
public class HelpCommands implements CommandMarker, ApplicationContextAware {
private ApplicationContext ctx;
@CliCommand(value = "help", help = "list all commands usage")
public void obtainHelp(@CliOption(key = { "", "command" }, optionContext = "availableCommands", help = "Command name to provide help for") String buffer) {
JLineShellComponent shell = ctx.getBean("shell", JLineShellComponent.class);
SimpleParser parser = shell.getSimpleParser();
parser.obtainHelp(buffer);
}
/* (non-Javadoc)
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
*/
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.ctx = applicationContext;
// Taken from SimpleParserComponent in the Roo code base
@Override
@CliCommand(value = "help", help = "Shows system help")
public void obtainHelp(
@CliOption(key = { "", "command" }, optionContext = "availableCommands", help = "Command name to provide help for") final String buffer) {
super.obtainHelp(buffer);
}
}