Skip to content

Commit

Permalink
Refactoring Builtins.CommandInput
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Apr 4, 2020
1 parent 3cac1ad commit 664eef8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
21 changes: 8 additions & 13 deletions builtins/src/main/java/org/jline/builtins/Builtins.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,28 +505,23 @@ public static class CommandInput {
PrintStream out;
PrintStream err;

public CommandInput(String command, String[] args, CommandRegistry.CommandSession session) {
this(command, args, null, session);
}

public CommandInput(String command, String[] args, Object[] xargs, CommandRegistry.CommandSession session) {
this(command, args, session.terminal(), session.in(), session.out(), session.err());
public CommandInput(String command, Object[] xargs, CommandRegistry.CommandSession session) {
if (xargs != null) {
this.xargs = xargs;
this.args = new String[xargs.length];
for (int i = 0; i < xargs.length; i++) {
this.args[i] = xargs[i] != null ? xargs[i].toString() : null;
}
}
this.command = command;
this.terminal = session.terminal();
this.in = session.in();
this.out = session.out();
this.err = session.err();
}

public CommandInput(String command, String[] args, Terminal terminal, InputStream in, PrintStream out, PrintStream err) {
this.command = command;
this.args = args;
this.terminal = terminal;
this.in = in;
this.out = out;
this.err = err;
public CommandInput(String command, Object[] args, Terminal terminal, InputStream in, PrintStream out, PrintStream err) {
this(command, args, new CommandRegistry.CommandSession(terminal, in, out, err));
}

public String command() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ public Object invoke(CommandRegistry.CommandSession session, String command, Obj
exception = null;
Object out = null;
if (hasCommand(command)) {
out = commandExecute.get(command(command)).executeFunction().apply(new Builtins.CommandInput(command, null, args, session));
out = commandExecute.get(command(command)).executeFunction().apply(new Builtins.CommandInput(command, args, session));
} else {
String[] _args = new String[args.length];
for (int i = 0; i < args.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public Object localExecute(String command, Object[] args) throws Exception {
throw new IllegalArgumentException();
}
Object out = commandExecute.get(command).executeFunction()
.apply(new Builtins.CommandInput(command, null, args, commandSession()));
.apply(new Builtins.CommandInput(command, args, commandSession()));
if (exception != null) {
throw exception;
}
Expand Down
3 changes: 1 addition & 2 deletions demo/src/main/java/org/jline/demo/Repl.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.jline.builtins.Completers.SystemCompleter;
import org.jline.builtins.Options.HelpException;
import org.jline.builtins.SystemRegistryImpl;
import org.jline.builtins.Widgets;
import org.jline.builtins.Widgets.TailTipWidgets;
import org.jline.builtins.Widgets.TailTipWidgets.TipType;
import org.jline.keymap.KeyMap;
Expand Down Expand Up @@ -80,7 +79,7 @@ public ObjectCommand() {

public Object invoke(CommandRegistry.CommandSession session, String command, Object... args) throws Exception {
exception = null;
Object out = commandExecute.get(command(command)).executeFunction().apply(new Builtins.CommandInput(command, null, args, session));
Object out = commandExecute.get(command(command)).executeFunction().apply(new Builtins.CommandInput(command, args, session));
if (exception != null) {
throw exception;
}
Expand Down

0 comments on commit 664eef8

Please sign in to comment.