Add --wide option to show-connections

This adds the --wide (-w) option to show-connections, and also makes
it so both --wide and -w are acceptable for show-queue.  In addition,
the options for show-caches, show-connections, and show-queue have
all been documented accordingly (though, show-caches is a little
different in its behavior).

Change-Id: I6adee795763bda9533c3700216695945d8bb7af8
This commit is contained in:
Doug Kelly
2013-06-11 01:36:31 -05:00
parent bc5e786653
commit 6599d77eeb
5 changed files with 46 additions and 2 deletions

View File

@@ -25,6 +25,10 @@ OPTIONS
operating system, and other details about the environment
that Gerrit Code Review is running in.
--width::
-w::
Width of the output table.
ACCESS
------
Caller must be a member of the privileged 'Administrators' group,

View File

@@ -32,6 +32,11 @@ OPTIONS
-n::
Show client hostnames as IP addresses instead of DNS hostname.
--wide::
-w::
Do not format the output to the terminal width (default of
80 columns).
DISPLAY
-------

View File

@@ -37,6 +37,13 @@ SCRIPTING
---------
Intended for interactive use only.
OPTIONS
-------
--wide::
-w::
Do not format the output to the terminal width (default of
80 columns).
DISPLAY
-------

View File

@@ -27,9 +27,11 @@ import com.google.inject.Inject;
import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IoSession;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.session.ServerSession;
import org.kohsuke.args4j.Option;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
@@ -47,9 +49,28 @@ final class ShowConnections extends SshCommand {
@Option(name = "--numeric", aliases = {"-n"}, usage = "don't resolve names")
private boolean numeric;
@Option(name = "--wide", aliases = {"-w"}, usage = "display without line width truncation")
private boolean wide;
@Inject
private SshDaemon daemon;
private int hostNameWidth;
private int columns = 80;
@Override
public void start(final Environment env) throws IOException {
String s = env.getEnv().get(Environment.ENV_COLUMNS);
if (s != null && !s.isEmpty()) {
try {
columns = Integer.parseInt(s);
} catch (NumberFormatException err) {
columns = 80;
}
}
super.start(env);
}
@Override
protected void run() throws Failure {
final IoAcceptor acceptor = daemon.getIoAcceptor();
@@ -71,6 +92,8 @@ final class ShowConnections extends SshCommand {
}
});
hostNameWidth = wide ? Integer.MAX_VALUE : columns - 9 - 9 - 10 - 32;
final long now = System.currentTimeMillis();
stdout.print(String.format("%-8s %8s %8s %-15s %s\n", //
"Session", "Start", "Idle", "User", "Remote Host"));
@@ -83,7 +106,7 @@ final class ShowConnections extends SshCommand {
final long start = io.getCreationTime();
final long idle = now - io.getLastIoTime();
stdout.print(String.format("%8s %8s %8s %-15.15s %.30s\n", //
stdout.print(String.format("%8s %8s %8s %-15.15s %s\n", //
id(sd), //
time(now, start), //
age(idle), //
@@ -160,6 +183,11 @@ final class ShowConnections extends SshCommand {
if (host == null) {
host = remoteAddress.toString();
}
if (host.length() > hostNameWidth) {
return host.substring(0, hostNameWidth);
}
return host;
}
}

View File

@@ -42,7 +42,7 @@ import java.util.concurrent.TimeUnit;
@AdminHighPriorityCommand
@CommandMetaData(name = "show-queue", descr = "Display the background work queues, including replication")
final class ShowQueue extends SshCommand {
@Option(name = "-w", usage = "display without line width truncation")
@Option(name = "--wide", aliases = {"-w"}, usage = "display without line width truncation")
private boolean wide;
@Inject