use of org.apache.karaf.shell.api.console.Command in project karaf by apache.
the class CommandsHelpProvider method getCommands.
private Set<Command> getCommands(Session session, String path) {
// TODO: this is not really clean
List<Command> commands = session.getRegistry().getCommands();
String subshell = (String) session.get(Session.SUBSHELL);
String completionMode = (String) session.get(Session.COMPLETION_MODE);
Set<Command> matchingCommands = new HashSet<>();
for (Command command : commands) {
String name = command.getScope() + ":" + command.getName();
if (command != null && !name.startsWith(path)) {
continue;
}
if (completionMode != null && completionMode.equalsIgnoreCase(Session.COMPLETION_MODE_SUBSHELL)) {
// filter the help only for "global" commands
if (subshell == null || subshell.trim().isEmpty()) {
if (!name.startsWith(Session.SCOPE_GLOBAL)) {
continue;
}
}
}
if (completionMode != null && (completionMode.equalsIgnoreCase(Session.COMPLETION_MODE_SUBSHELL) || completionMode.equalsIgnoreCase(Session.COMPLETION_MODE_FIRST))) {
// filter the help only for commands local to the subshell
if (!name.startsWith(subshell)) {
continue;
}
}
matchingCommands.add(command);
}
return matchingCommands;
}
use of org.apache.karaf.shell.api.console.Command in project karaf by apache.
the class CommandWrapper method execute.
@Override
public Object execute(final CommandSession commandSession, List<Object> arguments) throws Exception {
// TODO: remove the hack for .session
Session session = (Session) commandSession.get(".session");
// When need to translate closures to a compatible type for the command
for (int i = 0; i < arguments.size(); i++) {
Object v = arguments.get(i);
if (v instanceof Closure) {
final Closure closure = (Closure) v;
arguments.set(i, (org.apache.karaf.shell.api.console.Function) (s, a) -> closure.execute(commandSession, a));
}
}
return command.execute(session, arguments);
}
Aggregations