use of org.infinispan.cli.resources.Resource in project infinispan by infinispan.
the class Ls method exec.
@Override
public CommandResult exec(ContextAwareCommandInvocation invocation) throws CommandException {
try {
Connection connection = invocation.getContext().getConnection();
connection.refreshServerInfo();
Resource resource = connection.getActiveResource().getResource(path);
for (String item : resource.getChildrenNames()) {
invocation.println(item);
}
return CommandResult.SUCCESS;
} catch (IOException e) {
throw new CommandException(e);
}
}
use of org.infinispan.cli.resources.Resource in project infinispan by infinispan.
the class CdContextCompleter method complete.
@Override
public void complete(CompleterInvocation invocation) {
Context context = ((ContextAwareCompleterInvocation) invocation).context;
Resource resource = context.getConnection().getActiveResource();
String v = invocation.getGivenCompleteValue();
if (v == null || v.length() == 0) {
// no completions yet, add all of the local resource children
invocation.addAllCompleterValues(getChildrenNames(resource));
invocation.setAppendSpace(resource.isLeaf());
} else {
String[] parts = v.split("/");
if (parts.length == 0) {
resource = resource.findAncestor(RootResource.class);
invocation.addAllCompleterValues(getChildrenNames(resource));
invocation.setAppendSpace(resource.isLeaf());
} else {
int offset;
String last;
String prefix;
if (v.endsWith("/")) {
offset = 0;
last = "";
prefix = v;
} else {
offset = 1;
last = parts[parts.length - 1];
int lastSlash = v.lastIndexOf('/');
prefix = lastSlash < 0 ? "" : v.substring(0, lastSlash + 1);
}
for (int i = 0; i < parts.length - offset; i++) {
if (parts[i].isEmpty()) {
resource = resource.findAncestor(RootResource.class);
} else {
try {
resource = resource.getChild(parts[i]);
} catch (IOException e) {
// Ignore
}
}
}
Iterable<String> all = getChildrenNames(resource);
for (String item : all) {
if (item.startsWith(last)) {
invocation.addCompleterValue(prefix + item);
}
}
invocation.setAppendSpace(resource.isLeaf());
}
}
}
use of org.infinispan.cli.resources.Resource in project infinispan by infinispan.
the class ContextImpl method changeResource.
@Override
public CommandResult changeResource(Class<? extends Resource> fromResource, String resourceType, String name) throws CommandException {
try {
Resource resource;
if (fromResource != null) {
resource = connection.getActiveResource().findAncestor(fromResource).getChild(resourceType, name);
} else {
resource = connection.getActiveResource().getResource(name);
}
if (!(resource instanceof CacheKeyResource)) {
connection.setActiveResource(resource);
}
refreshPrompt();
return CommandResult.SUCCESS;
} catch (IOException e) {
throw new CommandException(e);
}
}
Aggregations