package com.gitblit.transport.ssh.gitblit;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.List;
+import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
+import org.parboiled.common.StringUtils;
import com.gitblit.manager.IGitblit;
import com.gitblit.models.ProjectModel;
+import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.transport.ssh.commands.CommandMetaData;
import com.gitblit.transport.ssh.commands.DispatchCommand;
@Option(name = "--tabbed", aliases = { "-t" }, usage = "as tabbed output")
private boolean tabbed;
+ @Argument(index = 0, metaVar = "REGEX", usage = "regex filter expression")
+ protected String regexFilter;
+
@Override
public void run() {
IGitblit gitblit = getContext().getGitblit();
UserModel user = getContext().getClient().getUser();
List<ProjectModel> projects = gitblit.getProjectModels(user, false);
+ List<ProjectModel> filtered;
+ if (StringUtils.isEmpty(regexFilter)) {
+ // no regex filter
+ filtered = projects;
+ } else {
+ // regex filter the list
+ filtered = new ArrayList<ProjectModel>();
+ for (ProjectModel p : projects) {
+ if (p.name.matches(regexFilter)) {
+ filtered.add(p);
+ }
+ }
+ }
if (tabbed) {
- asTabbed(projects);
+ asTabbed(filtered);
} else {
- asTable(projects);
+ asTable(filtered);
}
}
package com.gitblit.transport.ssh.gitblit;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.List;
+import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
+import org.parboiled.common.StringUtils;
import com.gitblit.manager.IGitblit;
import com.gitblit.models.RepositoryModel;
@Option(name = "--tabbed", aliases = { "-t" }, usage = "as tabbed output")
private boolean tabbed;
+ @Argument(index = 0, metaVar = "REGEX", usage = "regex filter expression")
+ protected String regexFilter;
+
@Override
public void run() {
IGitblit gitblit = getContext().getGitblit();
UserModel user = getContext().getClient().getUser();
List<RepositoryModel> repositories = gitblit.getRepositoryModels(user);
+ List<RepositoryModel> filtered;
+ if (StringUtils.isEmpty(regexFilter)) {
+ // no regex filter
+ filtered = repositories;
+ } else {
+ // regex filter the list
+ filtered = new ArrayList<RepositoryModel>();
+ for (RepositoryModel r : repositories) {
+ if (r.name.matches(regexFilter)) {
+ filtered.add(r);
+ }
+ }
+ }
+
if (tabbed) {
- asTabbed(repositories);
+ asTabbed(filtered);
} else {
- asTable(repositories);
+ asTable(filtered);
}
}
*/
package com.gitblit.transport.ssh.gitblit;
+import java.util.ArrayList;
import java.util.List;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
+import org.parboiled.common.StringUtils;
import com.gitblit.manager.IGitblit;
import com.gitblit.models.RegistrantAccessPermission;
+import com.gitblit.models.RepositoryModel;
import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
import com.gitblit.transport.ssh.commands.CommandMetaData;
@Option(name = "--tabbed", aliases = { "-t" }, usage = "as tabbed output")
private boolean tabbed;
+ @Argument(index = 0, metaVar = "REGEX", usage = "regex filter expression")
+ protected String regexFilter;
+
@Override
public void run() {
IGitblit gitblit = getContext().getGitblit();
List<UserModel> users = gitblit.getAllUsers();
+ List<UserModel> filtered;
+ if (StringUtils.isEmpty(regexFilter)) {
+ // no regex filter
+ filtered = users;
+ } else {
+ // regex filter the list
+ filtered = new ArrayList<UserModel>();
+ for (UserModel u : users) {
+ if (u.username.matches(regexFilter)) {
+ filtered.add(u);
+ }
+ }
+ }
+
if (tabbed) {
- asTabbed(users);
+ asTabbed(filtered);
} else {
- asTable(users);
+ asTable(filtered);
}
}