public SimpleDataSourceOperationHandler(final String dsType) {
super("data-source", true);
this.dsType = dsType;
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;
}
return super.canAppearNext(ctx);
}
};
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();
}
final String profileArg;
if (!ctx.isDomainMode()) {
profileArg = null;
} else {
profileArg = profile.getValue(ctx.getParsedArguments());
if (profileArg == null) {
return Collections.emptyList();
}
}
return Util.getDatasources(ctx.getModelControllerClient(), profileArg, dsType);
}
}), 0, "--name") {
@Override
public boolean canAppearNext(CommandContext ctx) throws CommandFormatException {
if(ctx.isDomainMode() && !profile.isPresent(ctx.getParsedArguments())) {
return false;
}
return super.canAppearNext(ctx);
}
};
operation = new ArgumentWithValue(this, new CommandLineCompleter(){
@Override
public int complete(CommandContext ctx, String buffer, int cursor, List<String> candidates) {
final StringBuilder buf = new StringBuilder();
if(ctx.isDomainMode()) {
final String profileName = profile.getValue(ctx.getParsedArguments());