EngineHub / Intake

IoC-oriented Java command parsing library
GNU Lesser General Public License v3.0
98 stars 21 forks source link

InvalidUsageException getSimpleUsageString message bug #12

Closed nikosgram closed 9 years ago

nikosgram commented 9 years ago

I'm using the method getSimpleUsageString to get the Usage from the command and the output message is the bellow:

2015-07-13_22 06 55

Usage code:

try {
    return dispatcher.call(command.getName() + ' ' + Joiner.on(' ').join(args), namespace, ImmutableList.of());
} catch (InvalidUsageException e) {
    sender.sendMessage(ChatColor.GRAY + "Usage: " + ChatColor.RED + e.getSimpleUsageString("/"));
    return true;
} catch (InvocationCommandException e) {
    sender.sendMessage(ChatColor.RED + e.getLocalizedMessage());
    e.printStackTrace();
} catch (CommandException e) {
    sender.sendMessage(ChatColor.RED + e.getLocalizedMessage());
    return true;
} catch (AuthorizationException e) {
    sender.sendMessage(command.getPermissionMessage());
    return true;
}

Installing code:

Injector injector = Intake.createInjector();
injector.install(new PrimitivesModule());
injector.install(new BukkitModule());
injector.install(new StoreModule());

ParametricBuilder builder = new ParametricBuilder(injector);
builder.setAuthorizer(new BukkitAuthorizer());

dispatcher = new CommandGraph()
    .builder(builder)
    .commands()
    .group("store")
    .registerMethods(this)
    .parent()
    .graph()
    .getDispatcher();

Registered Method:

@Command(aliases = "version", desc = "Show the version!")
public void version(CommandSender sender) {
    sender.sendMessage("&e" + getDescription().getName() + " " + getDescription().getVersion());
}

Intake Version: 4.0-SNAPSHOT

onbjerg commented 9 years ago

You need to define usage in the Command annotation (at least until this is fixed), e.g.:

@Command(aliases = "version", desc = "Show the version", usage = "/store version")