Revert "ListPlugins: Remove deprecated --format option"
Removing the --format option from the REST API had the side effect of
also removing it from the 'plugin ls' ssh command.
Removing the option from the 'plugin ls' is a breaking change for some
users, so put it back.
This reverts commit 3bbd3c313f.
Change-Id: I2f4af48f16273f4875b28349e5afd707f2103bec
This commit is contained in:
@@ -40,6 +40,10 @@ import java.util.TreeMap;
|
|||||||
public class ListPlugins implements RestReadView<TopLevelResource> {
|
public class ListPlugins implements RestReadView<TopLevelResource> {
|
||||||
private final PluginLoader pluginLoader;
|
private final PluginLoader pluginLoader;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@Option(name = "--format", usage = "(deprecated) output format")
|
||||||
|
private OutputFormat format = OutputFormat.TEXT;
|
||||||
|
|
||||||
@Option(name = "--all", aliases = {"-a"}, usage = "List all plugins, including disabled plugins")
|
@Option(name = "--all", aliases = {"-a"}, usage = "List all plugins, including disabled plugins")
|
||||||
private boolean all;
|
private boolean all;
|
||||||
|
|
||||||
@@ -48,12 +52,23 @@ public class ListPlugins implements RestReadView<TopLevelResource> {
|
|||||||
this.pluginLoader = pluginLoader;
|
this.pluginLoader = pluginLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OutputFormat getFormat() {
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListPlugins setFormat(OutputFormat fmt) {
|
||||||
|
this.format = fmt;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object apply(TopLevelResource resource) {
|
public Object apply(TopLevelResource resource) {
|
||||||
|
format = OutputFormat.JSON;
|
||||||
return display(null);
|
return display(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonElement display(PrintWriter stdout) {
|
public JsonElement display(PrintWriter stdout) {
|
||||||
|
Map<String, PluginInfo> output = new TreeMap<>();
|
||||||
List<Plugin> plugins = Lists.newArrayList(pluginLoader.getPlugins(all));
|
List<Plugin> plugins = Lists.newArrayList(pluginLoader.getPlugins(all));
|
||||||
Collections.sort(plugins, new Comparator<Plugin>() {
|
Collections.sort(plugins, new Comparator<Plugin>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -62,24 +77,30 @@ public class ListPlugins implements RestReadView<TopLevelResource> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (stdout == null) {
|
if (!format.isJson()) {
|
||||||
Map<String, PluginInfo> output = new TreeMap<>();
|
stdout.format("%-30s %-10s %-8s %s\n", "Name", "Version", "Status", "File");
|
||||||
for (Plugin p : plugins) {
|
stdout.print("-------------------------------------------------------------------------------\n");
|
||||||
PluginInfo info = new PluginInfo(p);
|
}
|
||||||
|
|
||||||
|
for (Plugin p : plugins) {
|
||||||
|
PluginInfo info = new PluginInfo(p);
|
||||||
|
if (format.isJson()) {
|
||||||
output.put(p.getName(), info);
|
output.put(p.getName(), info);
|
||||||
|
} else {
|
||||||
|
stdout.format("%-30s %-10s %-8s %s\n", p.getName(),
|
||||||
|
Strings.nullToEmpty(info.version),
|
||||||
|
p.isDisabled() ? "DISABLED" : "ENABLED",
|
||||||
|
p.getSrcFile().getFileName());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stdout == null) {
|
||||||
return OutputFormat.JSON.newGson().toJsonTree(
|
return OutputFormat.JSON.newGson().toJsonTree(
|
||||||
output,
|
output,
|
||||||
new TypeToken<Map<String, Object>>() {}.getType());
|
new TypeToken<Map<String, Object>>() {}.getType());
|
||||||
}
|
} else if (format.isJson()) {
|
||||||
stdout.format("%-30s %-10s %-8s %s\n", "Name", "Version", "Status", "File");
|
format.newGson().toJson(output,
|
||||||
stdout.print("-------------------------------------------------------------------------------\n");
|
new TypeToken<Map<String, PluginInfo>>() {}.getType(), stdout);
|
||||||
for (Plugin p : plugins) {
|
|
||||||
PluginInfo info = new PluginInfo(p);
|
|
||||||
stdout.format("%-30s %-10s %-8s %s\n", p.getName(),
|
|
||||||
Strings.nullToEmpty(info.version),
|
|
||||||
p.isDisabled() ? "DISABLED" : "ENABLED",
|
|
||||||
p.getSrcFile().getFileName());
|
|
||||||
stdout.print('\n');
|
stdout.print('\n');
|
||||||
}
|
}
|
||||||
stdout.flush();
|
stdout.flush();
|
||||||
|
|||||||
Reference in New Issue
Block a user