} catch (Throwable ex) {
throw new CompletionException("Problem creating a command instance", ex);
}
// Get the command's argument bundle and syntax
ArgumentBundle bundle = (command == null)
? ci.getArgumentBundle()
: command.getArgumentBundle();
SyntaxBundle syntaxes = ci.getSyntaxBundle();
if (syntaxes == null) {
syntaxes = shell.getSyntaxManager().getSyntaxBundle(cmd);
}
if (bundle == null) {
// We're missing the argument bundle. We assume this is a 'classic' Java application
// that does its own argument parsing and completion like a UNIX shell; i.e.
// completing each argument as a pathname.
Syntax syntax = new RepeatSyntax(new ArgumentSyntax("argument"));
syntaxes = new SyntaxBundle(cmd, syntax);
bundle = new ArgumentBundle(
new FileArgument("argument", Argument.MULTIPLE));
} else if (syntaxes == null) {
// We're missing the syntax, but we do have an argument bundle. Generate
// a default syntax from the bundle.
syntaxes = new SyntaxBundle(cmd, bundle.createDefaultSyntax());
}
try {
bundle.complete(this, syntaxes, completions);
} catch (CommandSyntaxException ex) {
throw new CompletionException("Command syntax problem", ex);
}
} else {
// We haven't got a command name yet, so complete the partial command name string