super("command", true);
this.cmdRegistry = cmdRegistry;
action.addCantAppearAfter(helpArg);
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(!ctx.isDomainMode()) {
return false;
}
final String actionName = action.getValue(ctx.getParsedArguments());
if(actionName == null || !"add".equals(actionName)) {
return false;
}
return super.canAppearNext(ctx);
}
};
profile.addCantAppearAfter(helpArg);
nodePath = new ArgumentWithValue(this, new CommandLineCompleter(){
@Override
public int complete(CommandContext ctx, String buffer, int cursor, List<String> candidates) {
int offset = 0;
if(ctx.isDomainMode()) {
final String profileName = profile.getValue(ctx.getParsedArguments());
if(profileName == null) {
return -1;
}
StringBuilder buf = new StringBuilder();
buf.append("profile=").append(profileName).append('/');
offset = buf.length();
buf.append(buffer);
buffer = buf.toString();
}
return OperationRequestCompleter.INSTANCE.complete(ctx, buffer, cursor + offset, candidates) - offset;
}}, "--node-type") {
@Override
public boolean canAppearNext(CommandContext ctx) throws CommandFormatException {
if(ctx.isDomainMode() && !profile.isPresent(ctx.getParsedArguments())) {
return false;
}
return "add".equals(action.getValue(ctx.getParsedArguments())) && super.canAppearNext(ctx);
}
};
idProperty = new ArgumentWithValue(this, new DefaultCompleter(new CandidatesProvider(){
@Override
public List<String> getAllCandidates(CommandContext ctx) {
List<Property> props = getNodeProperties(ctx);
if(props.isEmpty()) {
return Collections.emptyList();
}
final List<String> candidates = new ArrayList<String>();
for(Property prop : props) {
final ModelNode value = prop.getValue();
if(value.has("access-type") && "read-only".equals(value.get("access-type").asString())) {
candidates.add(prop.getName());
}
}
return candidates;
}}), "--property-id");
idProperty.addRequiredPreceding(nodePath);
commandName = new ArgumentWithValue(this, new DefaultCompleter(new CandidatesProvider(){
@Override
public List<String> getAllCandidates(CommandContext ctx) {
final String actionName = action.getValue(ctx.getParsedArguments());
if(actionName == null) {