From f76fee63ed9cb3a30d3c0c092d860b1cb93a481b Mon Sep 17 00:00:00 2001
From: Gerard Smyth <gerard.smyth@gmail.com>
Date: Thu, 08 May 2014 13:09:30 -0400
Subject: [PATCH] Updated the SyndicationServlet to provide an additional option to return details of the tags in the repository instead of the commits. This uses a new 'ot' request parameter to indicate the object type of the content to return, which can be ither TAG or COMMIT. If this is not provided, then COMMIT is assumed to maintain backwards compatability. If tags are returned, then the paging parameters, 'l' and 'pg' are still supported, but searching options are currently ignored.
---
src/main/java/com/gitblit/transport/ssh/commands/ListCommand.java | 31 +++++++++++++++++++++++++------
1 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/src/main/java/com/gitblit/transport/ssh/commands/ListCommand.java b/src/main/java/com/gitblit/transport/ssh/commands/ListCommand.java
index 4513626..8d4ddc3 100644
--- a/src/main/java/com/gitblit/transport/ssh/commands/ListCommand.java
+++ b/src/main/java/com/gitblit/transport/ssh/commands/ListCommand.java
@@ -22,9 +22,11 @@
import org.kohsuke.args4j.Option;
+import com.gitblit.utils.JsonUtils;
+
/**
* Parent class of a list command.
- *
+ *
* @author James Moger
*
* @param <T>
@@ -34,27 +36,40 @@
@Option(name = "--verbose", aliases = { "-v" }, usage = "verbose")
protected boolean verbose;
- @Option(name = "--tabbed", aliases = { "-t" }, usage = "as tabbed output")
+ @Option(name = "--tabbed", usage = "generate tabbed-text output")
protected boolean tabbed;
+
+ @Option(name = "--json", usage = "generate JSON output")
+ protected boolean json;
private DateFormat df;
protected abstract List<T> getItems() throws UnloggedFailure;
-
+
+ protected void validateOutputFormat() throws UnloggedFailure {
+ if (tabbed && json) {
+ throw new UnloggedFailure(1, "Please specify --tabbed OR --json, not both!");
+ }
+ }
+
@Override
public void run() throws UnloggedFailure {
+ validateOutputFormat();
+
List<T> list = getItems();
if (tabbed) {
asTabbed(list);
+ } else if (json) {
+ asJSON(list);
} else {
asTable(list);
}
}
protected abstract void asTable(List<T> list);
-
+
protected abstract void asTabbed(List<T> list);
-
+
protected void outTabbed(Object... values) {
StringBuilder pattern = new StringBuilder();
for (int i = 0; i < values.length; i++) {
@@ -63,7 +78,11 @@
pattern.setLength(pattern.length() - 1);
stdout.println(String.format(pattern.toString(), values));
}
-
+
+ protected void asJSON(List<T> list) {
+ stdout.println(JsonUtils.toJsonString(list));
+ }
+
protected String formatDate(Date date) {
if (df == null) {
df = new SimpleDateFormat("yyyy-MM-dd");
--
Gitblit v1.9.1