use of org.apache.karaf.shell.api.console.Command in project karaf by apache.
the class ShellHelpProvider 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 ConsoleSessionImpl method resolveCommand.
@Override
public String resolveCommand(String name) {
// TODO: optimize
if (!name.contains(":")) {
String[] scopes = ((String) get(Session.SCOPE)).split(":");
List<Command> commands = registry.getCommands();
for (String scope : scopes) {
for (Command command : commands) {
if ((Session.SCOPE_GLOBAL.equals(scope) || command.getScope().equals(scope)) && command.getName().equals(name)) {
return command.getScope() + ":" + name;
}
}
}
}
return name;
}
use of org.apache.karaf.shell.api.console.Command in project karaf by apache.
the class HeadlessSessionImpl method resolveCommand.
@Override
public String resolveCommand(String name) {
// TODO: optimize
if (!name.contains(":")) {
String[] scopes = ((String) get(Session.SCOPE)).split(":");
List<Command> commands = registry.getCommands();
for (String scope : scopes) {
for (Command command : commands) {
if ((Session.SCOPE_GLOBAL.equals(scope) || command.getScope().equals(scope)) && command.getName().equals(name)) {
return command.getScope() + ":" + name;
}
}
}
}
return name;
}
use of org.apache.karaf.shell.api.console.Command in project karaf by apache.
the class RegistryImpl method unregister.
@Override
public void unregister(Object service) {
synchronized (services) {
services.remove(service);
if (service instanceof Command) {
Command cmd = (Command) service;
String key = cmd.getScope() + ":" + cmd.getName();
List<Command> cmds = commands.get(key);
if (cmds != null) {
cmds.remove(cmd);
if (cmds.isEmpty()) {
commands.remove(key);
}
}
}
}
}
use of org.apache.karaf.shell.api.console.Command in project karaf by apache.
the class RegistryImpl method register.
@Override
public void register(Object service) {
synchronized (services) {
services.put(service, service);
if (service instanceof Command) {
Command cmd = (Command) service;
String key = cmd.getScope() + ":" + cmd.getName();
commands.computeIfAbsent(key, k -> new ArrayList<>()).add(cmd);
}
}
}
Aggregations