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:
@@ -25,6 +25,10 @@ OPTIONS
|
|||||||
operating system, and other details about the environment
|
operating system, and other details about the environment
|
||||||
that Gerrit Code Review is running in.
|
that Gerrit Code Review is running in.
|
||||||
|
|
||||||
|
--width::
|
||||||
|
-w::
|
||||||
|
Width of the output table.
|
||||||
|
|
||||||
ACCESS
|
ACCESS
|
||||||
------
|
------
|
||||||
Caller must be a member of the privileged 'Administrators' group,
|
Caller must be a member of the privileged 'Administrators' group,
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ OPTIONS
|
|||||||
-n::
|
-n::
|
||||||
Show client hostnames as IP addresses instead of DNS hostname.
|
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
|
DISPLAY
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,13 @@ SCRIPTING
|
|||||||
---------
|
---------
|
||||||
Intended for interactive use only.
|
Intended for interactive use only.
|
||||||
|
|
||||||
|
OPTIONS
|
||||||
|
-------
|
||||||
|
--wide::
|
||||||
|
-w::
|
||||||
|
Do not format the output to the terminal width (default of
|
||||||
|
80 columns).
|
||||||
|
|
||||||
DISPLAY
|
DISPLAY
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,11 @@ import com.google.inject.Inject;
|
|||||||
|
|
||||||
import org.apache.mina.core.service.IoAcceptor;
|
import org.apache.mina.core.service.IoAcceptor;
|
||||||
import org.apache.mina.core.session.IoSession;
|
import org.apache.mina.core.session.IoSession;
|
||||||
|
import org.apache.sshd.server.Environment;
|
||||||
import org.apache.sshd.server.session.ServerSession;
|
import org.apache.sshd.server.session.ServerSession;
|
||||||
import org.kohsuke.args4j.Option;
|
import org.kohsuke.args4j.Option;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
@@ -47,9 +49,28 @@ final class ShowConnections extends SshCommand {
|
|||||||
@Option(name = "--numeric", aliases = {"-n"}, usage = "don't resolve names")
|
@Option(name = "--numeric", aliases = {"-n"}, usage = "don't resolve names")
|
||||||
private boolean numeric;
|
private boolean numeric;
|
||||||
|
|
||||||
|
@Option(name = "--wide", aliases = {"-w"}, usage = "display without line width truncation")
|
||||||
|
private boolean wide;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private SshDaemon daemon;
|
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
|
@Override
|
||||||
protected void run() throws Failure {
|
protected void run() throws Failure {
|
||||||
final IoAcceptor acceptor = daemon.getIoAcceptor();
|
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();
|
final long now = System.currentTimeMillis();
|
||||||
stdout.print(String.format("%-8s %8s %8s %-15s %s\n", //
|
stdout.print(String.format("%-8s %8s %8s %-15s %s\n", //
|
||||||
"Session", "Start", "Idle", "User", "Remote Host"));
|
"Session", "Start", "Idle", "User", "Remote Host"));
|
||||||
@@ -83,7 +106,7 @@ final class ShowConnections extends SshCommand {
|
|||||||
final long start = io.getCreationTime();
|
final long start = io.getCreationTime();
|
||||||
final long idle = now - io.getLastIoTime();
|
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), //
|
id(sd), //
|
||||||
time(now, start), //
|
time(now, start), //
|
||||||
age(idle), //
|
age(idle), //
|
||||||
@@ -160,6 +183,11 @@ final class ShowConnections extends SshCommand {
|
|||||||
if (host == null) {
|
if (host == null) {
|
||||||
host = remoteAddress.toString();
|
host = remoteAddress.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (host.length() > hostNameWidth) {
|
||||||
|
return host.substring(0, hostNameWidth);
|
||||||
|
}
|
||||||
|
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@AdminHighPriorityCommand
|
@AdminHighPriorityCommand
|
||||||
@CommandMetaData(name = "show-queue", descr = "Display the background work queues, including replication")
|
@CommandMetaData(name = "show-queue", descr = "Display the background work queues, including replication")
|
||||||
final class ShowQueue extends SshCommand {
|
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;
|
private boolean wide;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|||||||
Reference in New Issue
Block a user