Skip to content

Commit

Permalink
CommandRegistry interface: removed method commandDescription(command),
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Jun 6, 2020
1 parent add2924 commit de55886
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 24 deletions.
14 changes: 2 additions & 12 deletions console/src/main/java/org/jline/console/CommandRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,11 @@ default String name() {
/**
* Returns a command description for use in the JLine Widgets framework.
* Default method must be overridden to return sub command descriptions.
* @param args command line arguments
* @param args command (args[0]) and its arguments
* @return command description for JLine TailTipWidgets to be displayed
* in the terminal status bar.
*/
default CmdDesc commandDescription(List<String> args) {
return !args.isEmpty() ? commandDescription(args.get(0)) : commandDescription("");
}

/**
* Returns a command description for use in the JLine Widgets framework.
* @param command the name of the command whose description to return
* @return command description for JLine TailTipWidgets to be displayed
* in the terminal status bar.
*/
CmdDesc commandDescription(String command);
CmdDesc commandDescription(List<String> args);

/**
* Execute a command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.jline.builtins.Options.HelpException;
import org.jline.console.ArgDesc;
import org.jline.console.CmdDesc;
import org.jline.console.CommandRegistry;
import org.jline.console.CommandRegistry.CommandSession;
import org.jline.reader.Completer;
import org.jline.reader.impl.completer.ArgumentCompleter;
import org.jline.reader.impl.completer.NullCompleter;
Expand Down Expand Up @@ -53,7 +51,8 @@ public List<String> commandInfo(String command) {
+ this.getClass().getCanonicalName());
}

public CmdDesc commandDescription(String command) {
public CmdDesc commandDescription(List<String> args) {
String command = args != null && !args.isEmpty() ? args.get(0) : "";
try {
invoke(new CommandSession(), command, new Object[] {"--help"});
} catch (HelpException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,6 @@ private CmdDesc localCommandDescription(String command) {
return null;
}

@Override
public CmdDesc commandDescription(String command) {
return commandDescription(Arrays.asList(command));
}

@Override
public CmdDesc commandDescription(List<String> args) {
CmdDesc out = new CmdDesc(false);
Expand All @@ -313,7 +308,7 @@ public CmdDesc commandDescription(List<String> args) {
if (id > -1) {
out = commandRegistries[id].commandDescription(args);
} else if (scriptStore.hasScript(command)) {
out = consoleEngine().commandDescription(command);
out = consoleEngine().commandDescription(args);
} else if (isLocalCommand(command)) {
out = localCommandDescription(command);
}
Expand Down Expand Up @@ -347,7 +342,7 @@ public CmdDesc commandDescription(CmdLine line) {
if (c != null && c.equals("help")) {
out = null;
} else if (c != null) {
out = subcommands.get(cmd).commandDescription(c);
out = subcommands.get(cmd).commandDescription(Arrays.asList(c));
} else {
out = commandDescription(subcommands.get(cmd));
}
Expand Down
2 changes: 1 addition & 1 deletion console/src/test/java/org/jline/example/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public Object invoke(CommandSession session, String command, Object... args) thr
return out;
}

public CmdDesc commandDescription(String command) {
public CmdDesc commandDescription(List<String> args) {
// TODO
return new CmdDesc(false);
}
Expand Down
3 changes: 2 additions & 1 deletion groovy/src/main/java/org/jline/script/GroovyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public List<String> commandInfo(String command) {
}

@Override
public CmdDesc commandDescription(String command) {
public CmdDesc commandDescription(List<String> args) {
String command = args != null && !args.isEmpty() ? args.get(0) : "";
Command cmd = (Command)registeredCommand(command);
return commandDescs.get(cmd);
}
Expand Down

0 comments on commit de55886

Please sign in to comment.