SHL-70 Add a command to clear the console

Move some of the built-in commands out of AbstractShell so they can more easily be excluded via filters in classpath scanning
This commit is contained in:
mpollack
2013-07-25 17:57:27 -04:00
parent f7afbca250
commit d03c4b97a2
8 changed files with 160 additions and 61 deletions

View File

@@ -86,7 +86,7 @@ public class Bootstrap {
configureApplicationContext(ctx);
//built-in commands and converters
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
scanner.scan("org.springframework.shell.commands", "org.springframework.shell.converters", "org.springframework.shell.plugin.support");
scanner.scan("org.springframework.shell.commands", "org.springframework.shell.converters", "org.springframework.shell.plugin.support");
//user contributed commands
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) ctx);
reader.loadBeanDefinitions(contextPath);

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2011-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.commands;
import jline.ANSIBuffer;
import org.springframework.shell.core.CommandMarker;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.stereotype.Component;
/**
* Commands related to the manipulation of the jline console
*
* @author Mark Pollack
*
*/
@Component
public class ConsoleCommands implements CommandMarker {
@CliCommand(value = {"cls", "clear"}, help = "Clears the console")
public void clear() {
System.out.print(ANSIBuffer.ANSICodes.clrscr());
System.out.print(ANSIBuffer.ANSICodes.gotoxy(0, 0));
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright 2011-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.commands;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import org.springframework.shell.core.CommandMarker;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.stereotype.Component;
/**
* Commands related to the dates
*
*/
@Component
public class DateCommands implements CommandMarker {
@CliCommand(value = { "date" }, help = "Displays the local date and time")
public String date() {
return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,Locale.US)
.format(new Date());
}
}

View File

@@ -20,8 +20,12 @@ import org.springframework.shell.core.ExitShellRequest;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.stereotype.Component;
/**
* Commands related to exiting the shell
*
*/
@Component
public class EssentialCommands implements CommandMarker {
public class ExitCommands implements CommandMarker {
@CliCommand(value={"exit", "quit"}, help="Exits the shell")
public ExitShellRequest quit() {

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2011-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.commands;
import org.springframework.shell.core.CommandMarker;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.stereotype.Component;
@Component
public class InlineCommentCommands implements CommandMarker {
@CliCommand(value = { "//", ";" }, help = "Inline comment markers (start of line only)")
public void inlineComment() {}
}

View File

@@ -25,8 +25,7 @@ import org.springframework.shell.support.logging.HandlerUtils;
import org.springframework.stereotype.Component;
/**
* Command type to allow execution of native OS commands from the Spring Roo
* shell.
* Command type to allow execution of native OS commands from the Spring Shell.
*
* @author Stefan Schmidt
* @since 1.2.0

View File

@@ -0,0 +1,46 @@
/*
* Copyright 2011-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.shell.commands;
import static org.springframework.shell.support.util.OsUtils.LINE_SEPARATOR;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import org.springframework.shell.core.CommandMarker;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
/**
* Commands related to system properties
*
*/
@Component
public class SystemPropertyCommands implements CommandMarker {
@CliCommand(value = { "system properties" }, help = "Shows the shell's properties")
public String props() {
final Set<String> data = new TreeSet<String>(); // For repeatability
for (final Entry<Object, Object> entry : System.getProperties().entrySet()) {
data.add(entry.getKey() + " = " + entry.getValue());
}
return StringUtils.collectionToDelimitedString(data, LINE_SEPARATOR) + LINE_SEPARATOR;
}
}

View File

@@ -313,8 +313,7 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme
return exitShellRequest;
}
@CliCommand(value = { "//", ";" }, help = "Inline comment markers (start of line only)")
public void inlineComment() {}
@CliCommand(value = { "/*" }, help = "Start of block comment")
public void blockCommentBegin() {
@@ -328,22 +327,6 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme
inBlockComment = false;
}
@CliCommand(value = { "system properties" }, help = "Shows the shell's properties")
public String props() {
final Set<String> data = new TreeSet<String>(); // For repeatability
for (final Entry<Object, Object> entry : System.getProperties().entrySet()) {
data.add(entry.getKey() + " = " + entry.getValue());
}
return StringUtils.collectionToDelimitedString(data, LINE_SEPARATOR) + LINE_SEPARATOR;
}
@CliCommand(value = { "date" }, help = "Displays the local date and time")
public String date() {
return DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,Locale.US)
.format(new Date());
}
//@CliCommand(value = { "flash test" }, help = "Tests message flashing")
public void flashCustom() throws Exception {
flash(Level.FINE, "Hello world", "a");
@@ -369,45 +352,6 @@ public abstract class AbstractShell extends AbstractShellStatusPublisher impleme
flash(Level.FINE, "", "b");
}
//@CliCommand(value = { "version" }, help = "Displays shell version")
public String version(@CliOption(key = "", help = "Special version flags") final String extra) {
StringBuilder sb = new StringBuilder();
if ("jaime".equals(extra)) {
sb.append(" /\\ /l").append(LINE_SEPARATOR);
sb.append(" ((.Y(!").append(LINE_SEPARATOR);
sb.append(" \\ |/").append(LINE_SEPARATOR);
sb.append(" / 6~6,").append(LINE_SEPARATOR);
sb.append(" \\ _ +-.").append(LINE_SEPARATOR);
sb.append(" \\`-=--^-' \\").append(LINE_SEPARATOR);
sb.append(" \\ \\ |\\--------------------------+").append(LINE_SEPARATOR);
sb.append(" _/ \\ | Thanks for loading Roo! |").append(LINE_SEPARATOR);
sb.append(" ( . Y +---------------------------+").append(LINE_SEPARATOR);
sb.append(" /\"\\ `---^--v---.").append(LINE_SEPARATOR);
sb.append(" / _ `---\"T~~\\/~\\/").append(LINE_SEPARATOR);
sb.append(" / \" ~\\. !").append(LINE_SEPARATOR);
sb.append(" _ Y Y.~~~ /'").append(LINE_SEPARATOR);
sb.append(" Y^| | | Roo 7").append(LINE_SEPARATOR);
sb.append(" | l | / . /'").append(LINE_SEPARATOR);
sb.append(" | `L | Y .^/ ~T").append(LINE_SEPARATOR);
sb.append(" | l ! | |/ | | ____ ____ ____").append(LINE_SEPARATOR);
sb.append(" | .`\\/' | Y | ! / __ \\/ __ \\/ __ \\").append(LINE_SEPARATOR);
sb.append(" l \"~ j l j L______ / /_/ / / / / / / /").append(LINE_SEPARATOR);
sb.append(" \\,____{ __\"\" ~ __ ,\\_,\\_ / _, _/ /_/ / /_/ /").append(LINE_SEPARATOR);
sb.append(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~ /_/ |_|\\____/\\____/").append(" ").append(versionInfo()).append(LINE_SEPARATOR);
return sb.toString();
}
sb.append(" ____ ____ ____ ").append(LINE_SEPARATOR);
sb.append(" / __ \\/ __ \\/ __ \\ ").append(LINE_SEPARATOR);
sb.append(" / /_/ / / / / / / / ").append(LINE_SEPARATOR);
sb.append(" / _, _/ /_/ / /_/ / ").append(LINE_SEPARATOR);
sb.append("/_/ |_|\\____/\\____/ ").append(" ").append(versionInfo()).append(LINE_SEPARATOR);
sb.append(LINE_SEPARATOR);
return sb.toString();
}
public String versionInfo(){
return VersionUtils.versionInfo();
}