in apm-agent-attach-cli/src/main/java/co/elastic/apm/attach/AgentAttacher.java [394:513]
static Arguments parse(String... args) {
DiscoveryRules rules = new DiscoveryRules();
Set<String> includePids = new HashSet<>();
Map<String, String> config = new LinkedHashMap<>();
String argsProvider = null;
boolean help = args.length == 0;
boolean list = false;
boolean listVmArgs = false;
boolean continuous = false;
boolean noFork = false;
String currentArg = "";
Level logLevel = Level.INFO;
String logFile = null;
String agentJar = null;
String downloadedAgentVersion = null;
for (String arg : normalize(args)) {
if (arg.startsWith("-")) {
currentArg = arg;
switch (arg) {
case "-h":
case "--help":
help = true;
break;
case "-l":
case "--list":
list = true;
break;
case "-v":
case "--list-vmargs":
listVmArgs = true;
break;
case "-c":
case "--continuous":
continuous = true;
break;
case "--no-fork":
noFork = true;
break;
case "--include-all":
rules.includeAll();
case "-C":
case "--config":
case "-A":
case "--args-provider":
case "--include-pid":
case "--include-main":
case "--exclude-main":
case "--include-user":
case "--exclude-user":
case "--include-vmarg":
case "--include-vmargs":
case "--exclude-vmarg":
case "--exclude-vmargs":
case "-g":
case "--log-level":
case "--log-file":
case "--agent-jar":
case "--download-agent-version":
break;
default:
throw new IllegalArgumentException("Illegal argument: " + arg);
}
} else {
switch (currentArg) {
case "--include-main":
rules.includeMain(arg);
break;
case "--exclude-main":
rules.excludeMain(arg);
break;
case "--include-vmarg":
case "--include-vmargs":
rules.includeVmArgs(arg);
break;
case "--exclude-vmarg":
case "--exclude-vmargs":
rules.excludeVmArgs(arg);
break;
case "--include-user":
rules.includeUser(arg);
break;
case "--exclude-user":
rules.excludeUser(arg);
break;
case "--include-pid":
// "include-pid" rules do not require discovery, however we add them to the discovery rules because
// theoretically they may be used AFTER other exclusion rules, in which case we need to make sure we only
// match against them in the correct order
rules.includePid(arg);
includePids.add(Objects.requireNonNull(arg));
break;
case "-C":
case "--config":
config.put(arg.substring(0, arg.indexOf('=')), arg.substring(arg.indexOf('=') + 1));
break;
case "-A":
case "--args-provider":
argsProvider = arg;
break;
case "-g":
case "--log-level":
logLevel = Level.valueOf(arg);
break;
case "--log-file":
logFile = arg;
break;
case "--agent-jar":
agentJar = arg;
break;
case "--download-agent-version":
downloadedAgentVersion = arg;
break;
default:
throw new IllegalArgumentException("Illegal argument: " + arg);
}
}
}
return new Arguments(rules, includePids, config, argsProvider, help, list, listVmArgs, continuous, noFork, logLevel, logFile,
agentJar, downloadedAgentVersion);
}