Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/org/jboss/aesh/console/AeshConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jboss.aesh.console.command.registry.CommandRegistry;
import org.jboss.aesh.console.export.ExportManager;
import org.jboss.aesh.console.helper.ManProvider;
import org.jboss.aesh.history.History;
import org.jboss.aesh.terminal.Shell;

/**
Expand Down Expand Up @@ -115,4 +116,6 @@ void registerCommandInvocationProvider(String name,
boolean isEchoing();

void setEcho(boolean echo);

History getHistory();
}
10 changes: 10 additions & 0 deletions src/main/java/org/jboss/aesh/console/AeshConsoleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.jboss.aesh.console.man.Man;
import org.jboss.aesh.console.settings.CommandNotFoundHandler;
import org.jboss.aesh.console.settings.Settings;
import org.jboss.aesh.history.History;
import org.jboss.aesh.parser.AeshLine;
import org.jboss.aesh.parser.Parser;
import org.jboss.aesh.terminal.Shell;
Expand Down Expand Up @@ -309,6 +310,10 @@ public ConsoleCallback getConsoleCallback() {
return console.getConsoleCallback();
}

public InvocationProviders getInvocationProviders() {
return invocationProviders;
}

class AeshCompletion implements Completion {

@Override
Expand Down Expand Up @@ -425,4 +430,9 @@ else if (output != null) {
}
}
}

@Override
public History getHistory() {
return console.getHistory();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@
*/
package org.jboss.aesh.console.command.invocation;

import org.jboss.aesh.cl.CommandLine;
import org.jboss.aesh.cl.parser.CommandLineParserException;
import org.jboss.aesh.cl.validator.OptionValidatorException;
import org.jboss.aesh.console.AeshConsoleImpl;
import org.jboss.aesh.console.AeshContext;
import org.jboss.aesh.console.ConsoleCallback;
import org.jboss.aesh.console.Prompt;
import org.jboss.aesh.console.command.Command;
import org.jboss.aesh.console.command.CommandException;
import org.jboss.aesh.console.command.CommandNotFoundException;
import org.jboss.aesh.console.command.CommandOperation;
import org.jboss.aesh.console.command.container.CommandContainer;
import org.jboss.aesh.console.command.registry.CommandRegistry;
import org.jboss.aesh.console.operator.ControlOperator;
import org.jboss.aesh.parser.AeshLine;
import org.jboss.aesh.parser.Parser;
import org.jboss.aesh.terminal.Shell;

/**
Expand Down Expand Up @@ -135,4 +144,30 @@ public void setEcho(boolean echo) {
aeshConsole.setEcho(echo);
}

@Override
public Command getPopulatedCommand(String commandLine) throws CommandNotFoundException,
CommandException, CommandLineParserException, OptionValidatorException {
if (commandLine == null || commandLine.isEmpty()) {
return null;
}

AeshLine aeshLine = Parser.findAllWords(commandLine);
if (aeshLine.getWords().isEmpty()) {
return null;
}
String opName = aeshLine.getWords().get(0);
CommandContainer<Command> container = aeshConsole.getCommandRegistry().
getCommand(opName, commandLine);
if (container == null) {
throw new CommandNotFoundException("No command handler for '" + opName + "'.");
}
CommandLine line = container.getParser().parse(commandLine, false);
if (line == null) {
throw new CommandException("Invalid Command " + commandLine);
}
line.getParser().getCommandPopulator().populateObject(line,
aeshConsole.getInvocationProviders(), getAeshContext(), true);
return line.getParser().getCommand();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
*/
package org.jboss.aesh.console.command.invocation;

import org.jboss.aesh.cl.parser.CommandLineParserException;
import org.jboss.aesh.cl.validator.OptionValidatorException;
import org.jboss.aesh.console.AeshContext;
import org.jboss.aesh.console.Prompt;
import org.jboss.aesh.console.command.Command;
import org.jboss.aesh.console.command.CommandException;
import org.jboss.aesh.console.command.CommandNotFoundException;
import org.jboss.aesh.console.command.CommandOperation;
import org.jboss.aesh.console.command.registry.CommandRegistry;
import org.jboss.aesh.console.operator.ControlOperator;
Expand Down Expand Up @@ -143,4 +148,21 @@ public interface CommandInvocation {
* @param echo state
*/
void setEcho(boolean echo);

/**
* Retrieve the command from a command line. The arguments in the command
* line are injected into the Command fields.
*
* @param commandLine The input command.
* @return The command or null if the string was not mapping onto a Command.
* @throws org.jboss.aesh.console.command.CommandNotFoundException If the
* command is not found in the registry.
* @throws org.jboss.aesh.console.command.CommandException If the Command is
* not properly structured.
* @throws org.jboss.aesh.cl.parser.CommandLineParserException If the line
* parsing fails.
* @throws org.jboss.aesh.cl.validator.OptionValidatorException
*/
Command getPopulatedCommand(String commandLine) throws CommandNotFoundException,
CommandException, CommandLineParserException, OptionValidatorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import org.jboss.aesh.cl.parser.CommandLineParserException;
import org.jboss.aesh.cl.validator.OptionValidatorException;
import org.jboss.aesh.console.command.CommandException;
import org.jboss.aesh.console.command.CommandNotFoundException;

import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -209,6 +212,12 @@ public void setEcho(boolean interactive) {
public String getFoo() {
return "FOO";
}

@Override
public Command getPopulatedCommand(String commandLine) throws CommandNotFoundException,
CommandException, CommandLineParserException, OptionValidatorException {
return commandInvocation.getPopulatedCommand(commandLine);
}
}

class FooCommandInvocationProvider implements CommandInvocationProvider<FooCommandInvocation> {
Expand Down