public CommandMetadata apply(Class<?> commandType) { return loadCommand(commandType); } }));
public CommandGroupMetadata apply(GroupBuilder<C> group) { CommandMetadata groupDefault = MetadataLoader.loadCommand(group.defaultCommand); List<CommandMetadata> groupCommands = MetadataLoader.loadCommands(group.commands); // currentlly the default command is required to be in the commands list. If that changes, we'll need to add it here and add checks for existence allCommands.addAll(groupCommands); return MetadataLoader.loadCommandGroup(group.name, group.description, groupDefault, groupCommands); } }));
defaultCommandMetadata = MetadataLoader.loadCommand(defaultCommand);
if(null == defaultCommand) defaultCommand = loadCommand(defaultCommandClass); newCommands.add(defaultCommand); if(null == groupCommand) groupCommand = loadCommand(commandClass); newCommands.add(groupCommand); groupCommands.add(groupCommand);
public C parse(C commandInstance, String... args) { Preconditions.checkNotNull(args, "args is null"); Parser parser = new Parser(metadata); ParseState state = parser.parse(args); CommandMetadata command = MetadataLoader.loadCommand(commandInstance.getClass()); state = state.withCommand(command); validate(state); ImmutableMap.Builder<Class<?>, Object> bindings = ImmutableMap.<Class<?>, Object>builder().put(GlobalMetadata.class, metadata); if (state.getGroup() != null) { bindings.put(CommandGroupMetadata.class, state.getGroup()); } bindings.put(CommandMetadata.class, command); C c = (C) ParserUtil.injectOptions(commandInstance, command.getAllOptions(), state.getParsedOptions(), command.getArguments(), state.getParsedArguments(), command.getMetadataInjections(), bindings.build()); return c; }