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
46 additions
and
8 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,11 +66,17 @@ public class ApplicationsListCommand extends AbstractShellCommand { | ... | @@ -59,11 +66,17 @@ 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) { |
62 | - print(FMT, isActive ? "*" : " ", | 69 | + if (shortOnly) { |
63 | - app.id().id(), app.id().name(), app.version(), app.origin(), | 70 | + print(SHORT_FMT, isActive ? "*" : " ", |
64 | - app.description(), app.features(), | 71 | + app.id().id(), app.id().name(), app.version(), |
65 | - app.featuresRepo().isPresent() ? app.featuresRepo().get().toString() : "", | 72 | + app.origin(), app.description()); |
66 | - app.permissions()); | 73 | + } else { |
74 | + print(FMT, isActive ? "*" : " ", | ||
75 | + app.id().id(), app.id().name(), app.version(), app.origin(), | ||
76 | + app.description(), app.features(), | ||
77 | + app.featuresRepo().isPresent() ? app.featuresRepo().get().toString() : "", | ||
78 | + app.permissions()); | ||
79 | + } | ||
67 | } | 80 | } |
68 | } | 81 | } |
69 | } | 82 | } | ... | ... |
... | @@ -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); |
90 | - props.forEach(p -> print(FMT, p.name(), p.type().toString().toLowerCase(), | 98 | + if (shortOnly) { |
91 | - p.value(), p.defaultValue(), p.description())); | 99 | + props.forEach(p -> print(SHORT_FMT, p.name(), p.value())); |
100 | + } else { | ||
101 | + props.forEach(p -> print(FMT, p.name(), p.type().toString().toLowerCase(), | ||
102 | + p.value(), p.defaultValue(), p.description())); | ||
103 | + } | ||
92 | } | 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