diff --git a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java index 332fd916a..218faa647 100644 --- a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java +++ b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java @@ -43,6 +43,8 @@ public class Bootstrap { private static final int DEFAULT_HTTP_PORT = 8563; private static final String DEFAULT_TARGET_IP = "127.0.0.1"; + private boolean help = false; + private int pid = -1; private String targetIp = DEFAULT_TARGET_IP; private int telnetPort = DEFAULT_TELNET_PORT; @@ -83,6 +85,12 @@ public class Bootstrap { this.pid = pid; } + @Option(shortName = "h", longName = "help", flag = true) + @Description("Print usage") + public void setHelp(boolean help) { + this.help = help; + } + @Option(longName = "target-ip") @Description("The target jvm listen ip, default 127.0.0.1") public void setTargetIp(String targetIp) { @@ -125,7 +133,7 @@ public class Bootstrap { this.useHttps = useHttps; } - @Option(longName = "attach-only") + @Option(longName = "attach-only", flag = true) @Description("attach target process only, do not connect") public void setAttachOnly(boolean attachOnly) { this.attachOnly = attachOnly; @@ -167,6 +175,11 @@ public class Bootstrap { System.exit(1); } + if (bootStrap.isHelp()) { + System.out.println(usage(cli)); + System.exit(0); + } + // check telnet/http port int telnetPortPid = -1; int httpPortPid = -1; @@ -280,6 +293,10 @@ public class Bootstrap { logger.info("Attach process {} success.", pid); + if (bootStrap.isAttachOnly()) { + System.exit(0); + } + // start java telnet client // find arthas-client.jar URLClassLoader classLoader = new URLClassLoader( @@ -385,4 +402,8 @@ public class Bootstrap { public int getPid() { return pid; } + + public boolean isHelp() { + return help; + } }