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
Showing
2 changed files
with
39 additions
and
1 deletions
| ... | @@ -42,6 +42,13 @@ public class ApplicationsListCommand extends AbstractShellCommand { | ... | @@ -42,6 +42,13 @@ public class ApplicationsListCommand extends AbstractShellCommand { |
| 42 | "%s id=%d, name=%s, version=%s, origin=%s, description=%s, " + | 42 | "%s id=%d, name=%s, version=%s, origin=%s, description=%s, " + |
| 43 | "features=%s, featuresRepo=%s, permissions=%s"; | 43 | "features=%s, featuresRepo=%s, permissions=%s"; |
| 44 | 44 | ||
| 45 | + private static final String SHORT_FMT = | ||
| 46 | + "%s %3d %-28s %-8s %-16s %s"; | ||
| 47 | + | ||
| 48 | + @Option(name = "-s", aliases = "--short", description = "Show short output only", | ||
| 49 | + required = false, multiValued = false) | ||
| 50 | + private boolean shortOnly = false; | ||
| 51 | + | ||
| 45 | @Option(name = "-a", aliases = "--active", description = "Show active only", | 52 | @Option(name = "-a", aliases = "--active", description = "Show active only", |
| 46 | required = false, multiValued = false) | 53 | required = false, multiValued = false) |
| 47 | private boolean activeOnly = false; | 54 | private boolean activeOnly = false; |
| ... | @@ -59,6 +66,11 @@ public class ApplicationsListCommand extends AbstractShellCommand { | ... | @@ -59,6 +66,11 @@ public class ApplicationsListCommand extends AbstractShellCommand { |
| 59 | for (Application app : apps) { | 66 | for (Application app : apps) { |
| 60 | boolean isActive = service.getState(app.id()) == ACTIVE; | 67 | boolean isActive = service.getState(app.id()) == ACTIVE; |
| 61 | if (activeOnly && isActive || !activeOnly) { | 68 | if (activeOnly && isActive || !activeOnly) { |
| 69 | + if (shortOnly) { | ||
| 70 | + print(SHORT_FMT, isActive ? "*" : " ", | ||
| 71 | + app.id().id(), app.id().name(), app.version(), | ||
| 72 | + app.origin(), app.description()); | ||
| 73 | + } else { | ||
| 62 | print(FMT, isActive ? "*" : " ", | 74 | print(FMT, isActive ? "*" : " ", |
| 63 | app.id().id(), app.id().name(), app.version(), app.origin(), | 75 | app.id().id(), app.id().name(), app.version(), app.origin(), |
| 64 | app.description(), app.features(), | 76 | app.description(), app.features(), |
| ... | @@ -68,6 +80,7 @@ public class ApplicationsListCommand extends AbstractShellCommand { | ... | @@ -68,6 +80,7 @@ public class ApplicationsListCommand extends AbstractShellCommand { |
| 68 | } | 80 | } |
| 69 | } | 81 | } |
| 70 | } | 82 | } |
| 83 | + } | ||
| 71 | 84 | ||
| 72 | private JsonNode json(ApplicationService service, List<Application> apps) { | 85 | private JsonNode json(ApplicationService service, List<Application> apps) { |
| 73 | ObjectMapper mapper = new ObjectMapper(); | 86 | ObjectMapper mapper = new ObjectMapper(); | ... | ... |
| ... | @@ -17,10 +17,12 @@ package org.onosproject.cli.cfg; | ... | @@ -17,10 +17,12 @@ package org.onosproject.cli.cfg; |
| 17 | 17 | ||
| 18 | import org.apache.karaf.shell.commands.Argument; | 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; | 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | +import org.apache.karaf.shell.commands.Option; | ||
| 20 | import org.onosproject.cfg.ComponentConfigService; | 21 | import org.onosproject.cfg.ComponentConfigService; |
| 21 | import org.onosproject.cfg.ConfigProperty; | 22 | import org.onosproject.cfg.ConfigProperty; |
| 22 | import org.onosproject.cli.AbstractShellCommand; | 23 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | 24 | ||
| 25 | +import java.util.Optional; | ||
| 24 | import java.util.Set; | 26 | import java.util.Set; |
| 25 | 27 | ||
| 26 | import static com.google.common.base.Strings.isNullOrEmpty; | 28 | import static com.google.common.base.Strings.isNullOrEmpty; |
| ... | @@ -36,6 +38,12 @@ public class ComponentConfigCommand extends AbstractShellCommand { | ... | @@ -36,6 +38,12 @@ public class ComponentConfigCommand extends AbstractShellCommand { |
| 36 | static final String SET = "set"; | 38 | static final String SET = "set"; |
| 37 | 39 | ||
| 38 | private static final String FMT = " name=%s, type=%s, value=%s, defaultValue=%s, description=%s"; | 40 | private static final String FMT = " name=%s, type=%s, value=%s, defaultValue=%s, description=%s"; |
| 41 | + private static final String SHORT_FMT = " %s=%s"; | ||
| 42 | + | ||
| 43 | + @Option(name = "-s", aliases = "--short", description = "Show short output only", | ||
| 44 | + required = false, multiValued = false) | ||
| 45 | + private boolean shortOnly = false; | ||
| 46 | + | ||
| 39 | 47 | ||
| 40 | @Argument(index = 0, name = "command", | 48 | @Argument(index = 0, name = "command", |
| 41 | description = "Command name (activate|deactivate|uninstall)", | 49 | description = "Command name (activate|deactivate|uninstall)", |
| ... | @@ -87,12 +95,29 @@ public class ComponentConfigCommand extends AbstractShellCommand { | ... | @@ -87,12 +95,29 @@ public class ComponentConfigCommand extends AbstractShellCommand { |
| 87 | private void listComponentProperties(String component) { | 95 | private void listComponentProperties(String component) { |
| 88 | Set<ConfigProperty> props = service.getProperties(component); | 96 | Set<ConfigProperty> props = service.getProperties(component); |
| 89 | print("%s", component); | 97 | print("%s", component); |
| 98 | + if (shortOnly) { | ||
| 99 | + props.forEach(p -> print(SHORT_FMT, p.name(), p.value())); | ||
| 100 | + } else { | ||
| 90 | props.forEach(p -> print(FMT, p.name(), p.type().toString().toLowerCase(), | 101 | props.forEach(p -> print(FMT, p.name(), p.type().toString().toLowerCase(), |
| 91 | p.value(), p.defaultValue(), p.description())); | 102 | p.value(), p.defaultValue(), p.description())); |
| 92 | } | 103 | } |
| 104 | + } | ||
| 93 | 105 | ||
| 94 | private void listComponentProperty(String component, String name) { | 106 | private void listComponentProperty(String component, String name) { |
| 95 | - // FIXME: implement after getProperty is defined and implemented | 107 | + Set<ConfigProperty> props = service.getProperties(component); |
| 108 | + Optional<ConfigProperty> property = props.stream() | ||
| 109 | + .filter(p -> p.name().equals(name)).findFirst(); | ||
| 110 | + if (!property.isPresent()) { | ||
| 111 | + System.err.println("Property " + name + " for component " + component + " not found"); | ||
| 112 | + return; | ||
| 113 | + } | ||
| 114 | + ConfigProperty p = property.get(); | ||
| 115 | + if (shortOnly) { | ||
| 116 | + print(SHORT_FMT, p.name(), p.value()); | ||
| 117 | + } else { | ||
| 118 | + print(FMT, p.name(), p.type().toString().toLowerCase(), p.value(), | ||
| 119 | + p.defaultValue(), p.description()); | ||
| 120 | + } | ||
| 96 | } | 121 | } |
| 97 | 122 | ||
| 98 | } | 123 | } | ... | ... |
-
Please register or login to post a comment