l = new ArgumentWithoutValue(this, "-l");
l.setExclusive(true);
final FilenameTabCompleter pathCompleter = Util.isWindows() ? new WindowsFilenameTabCompleter(ctx) : new DefaultFilenameTabCompleter(ctx);
path = new ArgumentWithValue(this, pathCompleter, 0, "--path") {
@Override
public String getValue(ParsedCommandLine args) {
String value = super.getValue(args);
if(value != null) {
if(value.length() >= 0 && value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') {
value = value.substring(1, value.length() - 1);
}
value = pathCompleter.translatePath(value);
}
return value;
}
};
path.addCantAppearAfter(l);
force = new ArgumentWithoutValue(this, "--force", "-f");
force.addRequiredPreceding(path);
name = new ArgumentWithValue(this, new CommandLineCompleter() {
@Override
public int complete(CommandContext ctx, String buffer, int cursor, List<String> candidates) {
ParsedCommandLine args = ctx.getParsedCommandLine();
try {
if(path.isPresent(args)) {
return -1;
}
} catch (CommandFormatException e) {
return -1;
}
int nextCharIndex = 0;
while (nextCharIndex < buffer.length()) {
if (!Character.isWhitespace(buffer.charAt(nextCharIndex))) {
break;
}
++nextCharIndex;
}
if(ctx.getModelControllerClient() != null) {
List<String> deployments = Util.getDeployments(ctx.getModelControllerClient());
if(deployments.isEmpty()) {
return -1;
}
String opBuffer = buffer.substring(nextCharIndex).trim();
if (opBuffer.isEmpty()) {
candidates.addAll(deployments);
} else {
for(String name : deployments) {
if(name.startsWith(opBuffer)) {
candidates.add(name);
}
}
Collections.sort(candidates);
}
return nextCharIndex;
} else {
return -1;
}
}}, "--name");
name.addCantAppearAfter(l);
path.addCantAppearAfter(name);
rtName = new ArgumentWithValue(this, "--runtime-name");
rtName.addRequiredPreceding(path);
allServerGroups = new ArgumentWithoutValue(this, "--all-server-groups") {
@Override
public boolean canAppearNext(CommandContext ctx) throws CommandFormatException {
if(!ctx.isDomainMode()) {
return false;
}
return super.canAppearNext(ctx);
}
};
allServerGroups.addRequiredPreceding(path);
allServerGroups.addRequiredPreceding(name);
allServerGroups.addCantAppearAfter(force);
force.addCantAppearAfter(allServerGroups);
serverGroups = new ArgumentWithValue(this, new CommandLineCompleter() {
@Override
public int complete(CommandContext ctx, String buffer, int cursor, List<String> candidates) {
List<String> allGroups = Util.getServerGroups(ctx.getModelControllerClient());
if(buffer.isEmpty()) {
candidates.addAll(allGroups);
Collections.sort(candidates);
return 0;
}
final String[] groups = buffer.split(",+");
final String chunk;
final int lastGroupIndex;
if(buffer.charAt(buffer.length() - 1) == ',') {
lastGroupIndex = groups.length;
chunk = null;
} else {
lastGroupIndex = groups.length - 1;
chunk = groups[groups.length - 1];
}
for(int i = 0; i < lastGroupIndex; ++i) {
allGroups.remove(groups[i]);
}
final int result;
if(chunk == null) {
candidates.addAll(allGroups);
result = buffer.length();
} else {
for(String group : allGroups) {
if(group.startsWith(chunk)) {
candidates.add(group);
}
}
result = buffer.lastIndexOf(',') + 1;
}
Collections.sort(candidates);
return result;
}}, "--server-groups") {
@Override
public boolean canAppearNext(CommandContext ctx) throws CommandFormatException {
if(!ctx.isDomainMode()) {
return false;
}
return super.canAppearNext(ctx);
}
};
serverGroups.addRequiredPreceding(path);
serverGroups.addRequiredPreceding(name);
serverGroups.addCantAppearAfter(force);
force.addCantAppearAfter(serverGroups);
serverGroups.addCantAppearAfter(allServerGroups);
allServerGroups.addCantAppearAfter(serverGroups);
disabled = new ArgumentWithoutValue(this, "--disabled");
disabled.addRequiredPreceding(path);
disabled.addCantAppearAfter(serverGroups);
disabled.addCantAppearAfter(allServerGroups);
disabled.addCantAppearAfter(force);
force.addCantAppearAfter(disabled);
unmanaged = new ArgumentWithoutValue(this, "--unmanaged");
unmanaged.addRequiredPreceding(path);
script = new ArgumentWithValue(this, "--script");
script.addRequiredPreceding(path);
}