From d500429a1d7a47da3bcd22880b53dce806ba9300 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 10 Apr 2014 18:58:10 -0400
Subject: [PATCH] Refactored regex list command into a subclass

---
 src/main/java/com/gitblit/transport/ssh/commands/ListCommand.java |   55 +++++++++++++++++++++++++++----------------------------
 1 files changed, 27 insertions(+), 28 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 3953433..4513626 100644
--- a/src/main/java/com/gitblit/transport/ssh/commands/ListCommand.java
+++ b/src/main/java/com/gitblit/transport/ssh/commands/ListCommand.java
@@ -1,54 +1,53 @@
+/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package com.gitblit.transport.ssh.commands;
 
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
-import org.kohsuke.args4j.Argument;
 import org.kohsuke.args4j.Option;
 
-import com.gitblit.utils.StringUtils;
-
+/**
+ * Parent class of a list command.
+ * 
+ * @author James Moger
+ *
+ * @param <T>
+ */
 public abstract class ListCommand<T> extends SshCommand {
 
 	@Option(name = "--verbose", aliases = { "-v" }, usage = "verbose")
 	protected boolean verbose;
 
 	@Option(name = "--tabbed", aliases = { "-t" }, usage = "as tabbed output")
-	private boolean tabbed;
+	protected boolean tabbed;
 
-	@Argument(index = 0, metaVar = "REGEX", usage = "regex filter expression")
-	protected String regexFilter;
-	
 	private DateFormat df;
 
-	protected abstract List<T> getItems();
-	
-	protected abstract boolean matches(T t);
+	protected abstract List<T> getItems() throws UnloggedFailure;
 	
 	@Override
-	public void run() {
+	public void run() throws UnloggedFailure {
 		List<T> list = getItems();
-		List<T> filtered;
-		if (StringUtils.isEmpty(regexFilter)) {
-			// no regex filter 
-			filtered = list;
-		} else {
-			// regex filter the list
-			filtered = new ArrayList<T>();
-			for (T t : list) {
-				if (matches(t)) {
-					filtered.add(t);
-				}
-			}
-		}
-
 		if (tabbed) {
-			asTabbed(filtered);
+			asTabbed(list);
 		} else {
-			asTable(filtered);
+			asTable(list);
 		}
 	}
 

--
Gitblit v1.9.1