Search in sources :

Example 1 with Resource

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);
    }
}
Also used : Connection(org.infinispan.cli.connection.Connection) Resource(org.infinispan.cli.resources.Resource) IOException(java.io.IOException) CommandException(org.aesh.command.CommandException)

Example 2 with Resource

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());
        }
    }
}
Also used : Context(org.infinispan.cli.Context) RootResource(org.infinispan.cli.resources.RootResource) Resource(org.infinispan.cli.resources.Resource) RootResource(org.infinispan.cli.resources.RootResource) IOException(java.io.IOException)

Example 3 with Resource

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);
    }
}
Also used : CacheKeyResource(org.infinispan.cli.resources.CacheKeyResource) CacheKeyResource(org.infinispan.cli.resources.CacheKeyResource) FileResource(org.aesh.io.FileResource) Resource(org.infinispan.cli.resources.Resource) IOException(java.io.IOException) CommandException(org.aesh.command.CommandException)

Aggregations

IOException (java.io.IOException)3 Resource (org.infinispan.cli.resources.Resource)3 CommandException (org.aesh.command.CommandException)2 FileResource (org.aesh.io.FileResource)1 Context (org.infinispan.cli.Context)1 Connection (org.infinispan.cli.connection.Connection)1 CacheKeyResource (org.infinispan.cli.resources.CacheKeyResource)1 RootResource (org.infinispan.cli.resources.RootResource)1