Add options to filter by active flag in ls-users command
Change-Id: I94f53718d18da3a66a2ca555b207ff70d4f02a92
diff --git a/src/main/java/com/googlesource/gerrit/plugins/adminconsole/ListUsersCommand.java b/src/main/java/com/googlesource/gerrit/plugins/adminconsole/ListUsersCommand.java
index 12c3b97..af0af26 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/adminconsole/ListUsersCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/adminconsole/ListUsersCommand.java
@@ -25,11 +25,19 @@
import com.google.gwtorm.server.ResultSet;
import com.google.inject.Inject;
+import org.kohsuke.args4j.Option;
+
@RequiresCapability(value=GlobalCapability.ADMINISTRATE_SERVER, scope=CapabilityScope.CORE)
@CommandMetaData(name = "ls-users", description = "List users")
public final class ListUsersCommand extends SshCommand {
private ReviewDb db;
+ @Option(name = "--active-only", usage = "show only active users")
+ private boolean activeOnly = false;
+
+ @Option(name = "--inactive-only", usage = "show only inactive users")
+ private boolean inactiveOnly = false;
+
@Inject
ListUsersCommand(ReviewDb db) {
this.db = db;
@@ -39,6 +47,12 @@
protected void run() throws UnloggedFailure, Failure, Exception {
ResultSet<Account> accounts = db.accounts().all();
for (Account account : accounts) {
+ if (activeOnly && !account.isActive()) {
+ continue;
+ }
+ if (inactiveOnly && account.isActive()) {
+ continue;
+ }
String out = new StringBuilder()
.append(account.getId().toString())
.append(" |")
diff --git a/src/main/resources/Documentation/cmd-ls-users.md b/src/main/resources/Documentation/cmd-ls-users.md
index 5c8ddad..db4aa9b 100644
--- a/src/main/resources/Documentation/cmd-ls-users.md
+++ b/src/main/resources/Documentation/cmd-ls-users.md
@@ -15,6 +15,11 @@
OPTIONS
-------
+`--active-only`
+> Show only active users
+
+`--inactive-only`
+> Show only inactive users
`--help, -h`
> Display usage information.