use of org.jboss.galleon.cli.path.FeatureContainerPathConsumer in project galleon by wildfly.
the class AbstractPathCompleter method getItems.
List<String> getItems(PmCompleterInvocation completerInvocation) {
PmSession session = completerInvocation.getPmSession();
try {
FeatureContainer container = getContainer(completerInvocation);
if (container == null) {
return Collections.emptyList();
}
if (session.getCurrentPath() == null && completerInvocation.getGivenCompleteValue().isEmpty()) {
return Arrays.asList("" + PathParser.PATH_SEPARATOR);
}
String buffer = completerInvocation.getGivenCompleteValue();
if (!buffer.startsWith("" + PathParser.PATH_SEPARATOR)) {
String currentPath = getCurrentPath(completerInvocation);
if (currentPath != null) {
boolean completePath = currentPath.endsWith("" + PathParser.PATH_SEPARATOR);
buffer = currentPath + (completePath ? "" : "" + PathParser.PATH_SEPARATOR) + buffer;
}
}
FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(container, true);
PathParser.parse(buffer, consumer);
List<String> candidates = consumer.getCandidates(buffer);
filterCandidates(consumer, candidates);
return candidates;
} catch (Exception ex) {
CliLogging.log.errorf("Exception while completing: {0}", ex.getLocalizedMessage());
}
return Collections.emptyList();
}
use of org.jboss.galleon.cli.path.FeatureContainerPathConsumer in project galleon by wildfly.
the class StateInfoUtil method printContentPath.
public static void printContentPath(PmCommandInvocation session, FeatureContainer fp, String path) throws ProvisioningException, PathParserException, PathConsumerException, IOException {
FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(fp, false);
PathParser.parse(path, consumer);
Group grp = consumer.getCurrentNode(path);
if (grp != null) {
// entered some content
if (grp.getFeature() != null) {
displayFeature(session, grp);
} else if (grp.getSpec() != null) {
displayFeatureSpec(session, grp);
} else if (grp.getPackage() != null) {
displayPackage(session, grp);
} else if (!grp.getGroups().isEmpty()) {
displayContainmentGroup(session, grp);
}
}
}
use of org.jboss.galleon.cli.path.FeatureContainerPathConsumer in project galleon by wildfly.
the class StateCdCommand method cdFp.
private void cdFp(PmCommandInvocation session) throws CommandExecutionException, PathParserException, PathConsumerException {
PmSession pm = session.getPmSession();
String currentPath = pm.getCurrentPath();
FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(pm.getContainer(), true);
if (path.startsWith("" + PathParser.PATH_SEPARATOR)) {
pm.setCurrentPath(null);
} else if (path.equals("..")) {
if (currentPath == null) {
throw new CommandExecutionException("No path entered");
}
if (currentPath.equals("" + PathParser.PATH_SEPARATOR)) {
return;
}
currentPath = currentPath.substring(0, currentPath.length() - 1);
int i = currentPath.lastIndexOf("" + PathParser.PATH_SEPARATOR);
if (i < 0) {
path = "" + PathParser.PATH_SEPARATOR;
} else {
path = currentPath.substring(0, i);
}
if (path.isEmpty()) {
path = "" + PathParser.PATH_SEPARATOR;
}
pm.setCurrentPath(null);
} else {
path = currentPath + path;
}
PathParser.parse(path, consumer);
Group grp = consumer.getCurrentNode(path);
if (grp == null) {
return;
} else {
if (!path.endsWith("" + PathParser.PATH_SEPARATOR)) {
path += PathParser.PATH_SEPARATOR;
}
pm.setCurrentPath(path);
}
String prompt;
if (FeatureContainerPathConsumer.ROOT.equals(grp.getIdentity().getName())) {
prompt = "" + PathParser.PATH_SEPARATOR;
} else {
prompt = grp.getIdentity().getName() + PathParser.PATH_SEPARATOR;
}
session.setPrompt(session.getPmSession().buildPrompt(prompt));
}
use of org.jboss.galleon.cli.path.FeatureContainerPathConsumer in project galleon by wildfly.
the class StateSearchCommand method getPackage.
private PackageInfo getPackage(FeatureContainer container, String id) throws PathParserException, PathConsumerException, ProvisioningException {
String path = FeatureContainerPathConsumer.PACKAGES_PATH + id;
FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(container, false);
PathParser.parse(path, consumer);
Group grp = consumer.getCurrentNode(path);
if (grp == null) {
throw new ProvisioningException("Invalid path");
}
if (grp.getPackage() == null) {
throw new ProvisioningException("Path is not a package");
}
return grp.getPackage();
}
use of org.jboss.galleon.cli.path.FeatureContainerPathConsumer in project galleon by wildfly.
the class ConfigurationUtil method getConfig.
private static ConfigInfo getConfig(PmSession session, FPID fpid, String configuration) throws ProvisioningException, IOException, PathParserException, PathConsumerException {
String path = FeatureContainerPathConsumer.FINAL_CONFIGS_PATH + configuration + PathParser.PATH_SEPARATOR;
FeatureContainer full = FeatureContainers.fromFeaturePackId(session, fpid, null);
ConfigInfo ci = null;
try {
FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(full, false);
PathParser.parse(path, consumer);
ci = consumer.getConfig();
} catch (PathParserException | PathConsumerException ex) {
// XXX OK, return null
}
return ci;
}
Aggregations