private final ArgumentWithoutValue verbose;
public ReadAttributeHandler(CommandContext ctx) {
super(ctx, "read-attribute", true);
node = new ArgumentWithValue(this, OperationRequestCompleter.ARG_VALUE_COMPLETER, "--node");
name = new ArgumentWithValue(this, new DefaultCompleter(new DefaultCompleter.CandidatesProvider() {
@Override
public List<String> getAllCandidates(CommandContext ctx) {
try {
final OperationRequestAddress address = getAddress(ctx);
final ModelNode req = new ModelNode();
if(address.isEmpty()) {
req.get(Util.ADDRESS).setEmptyList();
} else {
if(address.endsOnType()) {
return Collections.emptyList();
}
final ModelNode addrNode = req.get(Util.ADDRESS);
for(OperationRequestAddress.Node node : address) {
addrNode.add(node.getType(), node.getName());
}
}
req.get(Util.OPERATION).set(Util.READ_RESOURCE_DESCRIPTION);
try {
final ModelNode response = ctx.getModelControllerClient().execute(req);
if(Util.isSuccess(response)) {
if(response.hasDefined(Util.RESULT)) {
final ModelNode result = response.get(Util.RESULT);
if(result.hasDefined(Util.ATTRIBUTES)) {
Set<String> attributes = result.get(Util.ATTRIBUTES).keys();
if(attributes.isEmpty()) {
return Collections.emptyList();
}
final List<String> candidates = new ArrayList<String>(attributes.size());
candidates.addAll(attributes);
return candidates;
} else {
return Collections.emptyList();
}
} else {
return Collections.emptyList();
}
} else {
return Collections.emptyList();
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (CommandFormatException e) {
return Collections.emptyList();
}
return Collections.emptyList();
}}), 0, "--name");
includeDefaults = new ArgumentWithValue(this, SimpleTabCompleter.BOOLEAN, "--include-defaults");
verbose = new ArgumentWithoutValue(this, "--verbose", "-v");
}