Thomas Vachuska
Committed by Gerrit Code Review

Added support for -s|--short option when listing apps.

Added support for -s|--short option when listing configs.

Change-Id: I9235cc5eec34826ff90feb5642981080fcfa1524
......@@ -42,6 +42,13 @@ public class ApplicationsListCommand extends AbstractShellCommand {
"%s id=%d, name=%s, version=%s, origin=%s, description=%s, " +
"features=%s, featuresRepo=%s, permissions=%s";
private static final String SHORT_FMT =
"%s %3d %-28s %-8s %-16s %s";
@Option(name = "-s", aliases = "--short", description = "Show short output only",
required = false, multiValued = false)
private boolean shortOnly = false;
@Option(name = "-a", aliases = "--active", description = "Show active only",
required = false, multiValued = false)
private boolean activeOnly = false;
......@@ -59,6 +66,11 @@ public class ApplicationsListCommand extends AbstractShellCommand {
for (Application app : apps) {
boolean isActive = service.getState(app.id()) == ACTIVE;
if (activeOnly && isActive || !activeOnly) {
if (shortOnly) {
print(SHORT_FMT, isActive ? "*" : " ",
app.id().id(), app.id().name(), app.version(),
app.origin(), app.description());
} else {
print(FMT, isActive ? "*" : " ",
app.id().id(), app.id().name(), app.version(), app.origin(),
app.description(), app.features(),
......@@ -68,6 +80,7 @@ public class ApplicationsListCommand extends AbstractShellCommand {
}
}
}
}
private JsonNode json(ApplicationService service, List<Application> apps) {
ObjectMapper mapper = new ObjectMapper();
......
......@@ -17,10 +17,12 @@ package org.onosproject.cli.cfg;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.cfg.ConfigProperty;
import org.onosproject.cli.AbstractShellCommand;
import java.util.Optional;
import java.util.Set;
import static com.google.common.base.Strings.isNullOrEmpty;
......@@ -36,6 +38,12 @@ public class ComponentConfigCommand extends AbstractShellCommand {
static final String SET = "set";
private static final String FMT = " name=%s, type=%s, value=%s, defaultValue=%s, description=%s";
private static final String SHORT_FMT = " %s=%s";
@Option(name = "-s", aliases = "--short", description = "Show short output only",
required = false, multiValued = false)
private boolean shortOnly = false;
@Argument(index = 0, name = "command",
description = "Command name (activate|deactivate|uninstall)",
......@@ -87,12 +95,29 @@ public class ComponentConfigCommand extends AbstractShellCommand {
private void listComponentProperties(String component) {
Set<ConfigProperty> props = service.getProperties(component);
print("%s", component);
if (shortOnly) {
props.forEach(p -> print(SHORT_FMT, p.name(), p.value()));
} else {
props.forEach(p -> print(FMT, p.name(), p.type().toString().toLowerCase(),
p.value(), p.defaultValue(), p.description()));
}
}
private void listComponentProperty(String component, String name) {
// FIXME: implement after getProperty is defined and implemented
Set<ConfigProperty> props = service.getProperties(component);
Optional<ConfigProperty> property = props.stream()
.filter(p -> p.name().equals(name)).findFirst();
if (!property.isPresent()) {
System.err.println("Property " + name + " for component " + component + " not found");
return;
}
ConfigProperty p = property.get();
if (shortOnly) {
print(SHORT_FMT, p.name(), p.value());
} else {
print(FMT, p.name(), p.type().toString().toLowerCase(), p.value(),
p.defaultValue(), p.description());
}
}
}
......