dependsOnProfile = nodeType.contains("/subsystem=") || nodeType.startsWith("subsystem=");
}
helpArg = new ArgumentWithoutValue(this, "--help", "-h");
nodePath = new DefaultOperationRequestAddress();
CommandLineParser.CallbackHandler handler = new DefaultCallbackHandler(nodePath);
try {
ParserUtil.parseOperationRequest(nodeType, handler);
} catch (CommandFormatException e) {
throw new IllegalArgumentException("Failed to parse nodeType: " + e.getMessage());
}
if(!nodePath.endsOnType()) {
throw new IllegalArgumentException("The node path doesn't end on a type: '" + nodeType + "'");
}
this.type = nodePath.getNodeType();
nodePath.toParentNode();
addRequiredPath(nodePath);
this.commandName = type;
this.idProperty = idProperty;
this.excludeOps = excludeOperations;
profile = new ArgumentWithValue(this, new DefaultCompleter(new CandidatesProvider(){
@Override
public List<String> getAllCandidates(CommandContext ctx) {
return Util.getNodeNames(ctx.getModelControllerClient(), null, "profile");
}}), "--profile") {
@Override
public boolean canAppearNext(CommandContext ctx) throws CommandFormatException {
if(!dependsOnProfile) {
return false;
}
if(!ctx.isDomainMode()) {
return false;
}
return super.canAppearNext(ctx);
}
};
//profile.addCantAppearAfter(helpArg);
operation = new ArgumentWithValue(this, new DefaultCompleter(new CandidatesProvider(){
@Override
public Collection<String> getAllCandidates(CommandContext ctx) {
DefaultOperationRequestAddress address = new DefaultOperationRequestAddress();
if(dependsOnProfile && ctx.isDomainMode()) {
final String profileName = profile.getValue(ctx.getParsedCommandLine());
if(profileName == null) {
return Collections.emptyList();
}
address.toNode("profile", profileName);
}
for(OperationRequestAddress.Node node : nodePath) {
address.toNode(node.getType(), node.getName());
}
address.toNode(type, "?");
Collection<String> ops = ctx.getOperationCandidatesProvider().getOperationNames(ctx, address);
ops.removeAll(excludeOps);
return ops;
}}), 0, "--operation") {
@Override
public boolean canAppearNext(CommandContext ctx) throws CommandFormatException {
if(dependsOnProfile && ctx.isDomainMode() && !profile.isValueComplete(ctx.getParsedCommandLine())) {
return false;
}
return super.canAppearNext(ctx);
}
};
operation.addCantAppearAfter(helpArg);
name = new ArgumentWithValue(this, new DefaultCompleter(new DefaultCompleter.CandidatesProvider() {
@Override
public List<String> getAllCandidates(CommandContext ctx) {
ModelControllerClient client = ctx.getModelControllerClient();
if (client == null) {
return Collections.emptyList();
}
DefaultOperationRequestAddress address = new DefaultOperationRequestAddress();
if(dependsOnProfile && ctx.isDomainMode()) {
final String profileName = profile.getValue(ctx.getParsedCommandLine());
if(profile == null) {
return Collections.emptyList();
}
address.toNode("profile", profileName);
}
for(OperationRequestAddress.Node node : nodePath) {
address.toNode(node.getType(), node.getName());
}
return Util.getNodeNames(ctx.getModelControllerClient(), address, type);
}
}), (idProperty == null ? "--name" : "--" + idProperty)) {
@Override