Skip to content

Commit

Permalink
Script execution: added builtin options -? and -v.
Browse files Browse the repository at this point in the history
+ fixes and improvements
  • Loading branch information
mattirn committed Jan 18, 2020
1 parent 9546e89 commit 4276a8b
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 64 deletions.
13 changes: 13 additions & 0 deletions builtins/src/main/java/org/jline/builtins/Builtins.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ private List<Completer> ttopCompleter(String name) {

public static class CommandInput{
String[] args;
Object[] xargs;
InputStream in;
PrintStream out;
PrintStream err;
Expand All @@ -511,6 +512,14 @@ public CommandInput(String[] args) {
this(args, null, null, null);
}

public CommandInput(Object[] xargs, boolean dumb) {
this.xargs = xargs;
this.args = new String[xargs.length];
for (int i = 0; i < xargs.length; i++) {
args[i] = xargs[i].toString();
}
}

public CommandInput(String[] args, InputStream in, PrintStream out, PrintStream err) {
this.args = args;
this.in = in;
Expand All @@ -522,6 +531,10 @@ public String[] args() {
return args;
}

public Object[] xargs() {
return xargs;
}

public InputStream in() {
return in;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ static Completers.SystemCompleter compileCompleters(CommandRegistry ... commandR
Widgets.CmdDesc commandDescription(String command);

/**
* Execute a command entered interactively or via JLine script. Implementation of the method is required when aggregating
* command registries using systemRegistry.
* Execute a command that have only string parameters and options. Implementation of the method is required
* when aggregating command registries using SystemRegistry.
* @param command
* @param args
* @return result
Expand All @@ -98,8 +98,8 @@ default Object execute(String command, String[] args) throws Exception {
}

/**
* Execute a command inside a code block or script engine script. If command has other than string arguments custom
* implementation is required.
* Execute a command. If command has other than string parameters a custom implementation is required.
* This method will be called only when we have ConsoleEngine in SystemRegistry.
* @param command
* @param args
* @return result
Expand Down
8 changes: 8 additions & 0 deletions builtins/src/main/java/org/jline/builtins/ConsoleEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public interface ConsoleEngine extends CommandRegistry {
*/
void setSystemRegistry(SystemRegistry systemRegistry);

/**
* Substituting args references with their values.
* @param args
* @return Substituted args
* @throws Exception
*/
Object[] expandParameters(String[] args) throws Exception;

/**
* Executes parsed line that does not contain known command by the system registry.
* If parsed line is neither JLine or ScriptEngine script it will be evaluated
Expand Down

0 comments on commit 4276a8b

Please sign in to comment.