提交 a4412a93 编写于 作者: K kohsuke

added the help command.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@17606 71c3de6d-444a-0410-be80-ed276b4c234a
上级 bb4ccdad
......@@ -123,6 +123,12 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
return name.replaceAll("([a-z0-9])([A-Z])","$1-$2").toLowerCase(Locale.ENGLISH);
}
/**
* Gets the quick summary of what this command does.
* Used by the help command to generate the list of commands.
*/
public abstract String getShortDescription();
public int main(List<String> args, InputStream stdin, PrintStream stdout, PrintStream stderr) {
this.stdin = new BufferedInputStream(stdin);
this.stdout = stdout;
......
......@@ -20,6 +20,11 @@ import jline.Terminal;
*/
@Extension
public class GroovyshCommand extends CLICommand {
@Override
public String getShortDescription() {
return "Runs an interactive groovy shell";
}
@Override
public int main(List<String> args, InputStream stdin, PrintStream stdout, PrintStream stderr) {
// this allows the caller to manipulate the JVM state, so require the admin privilege.
......
package hudson.cli;
import hudson.Extension;
/**
* Show the list of all commands.
*
* @author Kohsuke Kawaguchi
*/
@Extension
public class HelpCommand extends CLICommand {
@Override
public String getShortDescription() {
return "Lists all the available commands";
}
protected int run() {
for (CLICommand c : CLICommand.all()) {
stderr.println(" "+c.getName());
stderr.println(" "+c.getShortDescription());
}
return 0;
}
}
......@@ -33,6 +33,11 @@ import hudson.model.Hudson;
*/
@Extension
public class VersionCommand extends CLICommand {
@Override
public String getShortDescription() {
return "Shows the Hudson version";
}
protected int run() {
stdout.println(Hudson.VERSION);
return 0;
......
......@@ -46,6 +46,7 @@ import hudson.DescriptorExtensionList;
import hudson.ExtensionListView;
import hudson.cli.CliEntryPoint;
import hudson.cli.CLICommand;
import hudson.cli.HelpCommand;
import hudson.logging.LogRecorderManager;
import hudson.lifecycle.Lifecycle;
import hudson.model.Descriptor.FormException;
......@@ -2671,6 +2672,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
}
public int main(List<String> args, Locale locale, InputStream stdin, OutputStream stdout, OutputStream stderr) {
PrintStream out = new PrintStream(stdout);
PrintStream err = new PrintStream(stderr);
String subCmd = args.get(0);
......@@ -2680,16 +2682,14 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
SecurityContextHolder.getContext().setAuthentication(auth);
try {
// execute the command, do so with the originator of the request as the principal
return cmd.main(args.subList(1,args.size()),
stdin, new PrintStream(stdout), err);
return cmd.main(args.subList(1,args.size()),stdin, out, err);
} finally {
SecurityContextHolder.getContext().setAuthentication(old);
}
}
err.println("No such command: "+subCmd);
for (CLICommand c : CLICommand.all())
err.println(" "+c.getName());
new HelpCommand().main(Collections.<String>emptyList(), stdin, out, err);
return -1;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册