Skip to content

Commit

Permalink
feat: 支持通过arthas session data来添命令的附加参数,以减少不必要重复输入
Browse files Browse the repository at this point in the history
附加参数名称的格式为${arthas-cmd}-args
trace对应的是trace-args watch对应的watch-args

ie:
```
session -I 'trace-args=-n 3 -v'
```
这样以后的trace命令就不自动附加上述参数了

要清除可用:`session -I *`(清除所有) 或 `session -I 'trace-args= ``(清除指定的)
  • Loading branch information
qxo committed Oct 28, 2023
1 parent 19895b4 commit 1f8f17c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class SessionCommand extends AnnotatedCommand {

private boolean showSessionData = true;

private boolean showReservedNames = false;
private boolean showAll = false;

private List<String> customSesionData;

Expand All @@ -57,7 +57,7 @@ public void setHiddenSessionData(final boolean hiddenSessionData) {
@Option(shortName = "A", longName = "showAll", flag = true)
@Description("Show all session data")
public void setShowAll(final boolean showReservedNames) {
this.showReservedNames = showReservedNames;
this.showAll = showReservedNames;
}

@Option(shortName = "I", longName = "input")
Expand Down Expand Up @@ -102,7 +102,7 @@ public void process(CommandProcess process) {
}
if (showSessionData) {
final Map<String, Object> sessionData = session.cloneSessionData();
if (!this.showReservedNames) {
if (!this.showAll) {
final Iterator<Entry<String, Object>> iter = sessionData.entrySet().iterator();
while(iter.hasNext()) {
if (RESERVED_WORDS.contains(iter.next().getKey())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.taobao.arthas.core.shell.term.Tty;
import com.taobao.middleware.cli.CLIException;
import com.taobao.middleware.cli.CommandLine;

import io.termd.core.function.Function;

import java.lang.instrument.ClassFileTransformer;
Expand Down Expand Up @@ -344,10 +345,25 @@ public synchronized void run(boolean fg) {
args2.add(arg.value());
}
}

CommandLine cl = null;
try {
if (commandContext.cli() != null) {
final String appCmdArgs = commandContext.name() +"-args";
final Object cmdArgs = process.session().get(appCmdArgs);
if (cmdArgs != null) {
process.echoTips("appendCmdArgs: " + cmdArgs + "\n");
final String cmdArgs1 = cmdArgs.toString();
final String[] arr = cmdArgs1.contains("##") ? cmdArgs1.split("##")
: cmdArgs1.split("[; ,:#]+");
for (final String arg : arr) {
if (arg.isEmpty()) {
break;
}
args2.add(arg);
}
process.echoTips("appendCmdArgs done: " + args2 + "\n");
}

if (commandContext.cli().parse(args2, false).isAskingForHelp()) {
appendResult(new HelpCommand().createHelpDetailModel(commandContext));
terminate();
Expand Down

0 comments on commit 1f8f17c

Please sign in to comment.