protected ManagedCommand addCommand(Map<String, ManagedCommand> commandMap, ManagedCommand managedCommand) { Command command = managedCommand.getCommand(); String name = command.getMetadata().getName(); return commandMap.put(name, managedCommand); }
protected void addCommandNoOverride(Map<String, ManagedCommand> commandMap, ManagedCommand managedCommand) { ManagedCommand existing = addCommand(commandMap, managedCommand); // complain on dupes if (existing != null && existing.getCommand() != managedCommand.getCommand()) { String c1 = existing.getCommand().getClass().getName(); String c2 = managedCommand.getCommand().getClass().getName(); String message = String.format("More than one DI command named '%s'. Conflicting types: %s, %s.", managedCommand.getCommand().getMetadata().getName(), c1, c2); throw new BootiqueException(1, message); } } }
protected void mergeOverrides(Map<String, ManagedCommand> commandMap) { if (commandOverrides != null) { commandOverrides.forEach(co -> { ManagedCommand.Builder builder = ManagedCommand.builder(co); // check existing command prior to overriding... preserve existing "help" and "default" flags ManagedCommand existing = commandMap.get(co.getMetadata().getName()); if (existing != null) { // preserve existing flags... if (existing.isHelp()) { builder.asHelp(); } if (existing.isDefault()) { builder.asDefault(); } // log override String i1 = existing.getCommand().getClass().getName(); String i2 = co.getClass().getName(); bootLogger.trace(() -> String.format("Overriding command '%s' (old command: %s, new command: %s)", co.getMetadata().getName(), i1, i2)); } addCommand(commandMap, builder.build()); }); } }
/** * Returns an option representation of this command, that may be used in help generation or exposing the command * in a CLI parser. * * @return option representation of this command. * @since 0.21 */ public OptionMetadata asOption() { // TODO: cache the value? // using getters instead of vars ; some getters have logic return OptionMetadata.builder(getName()).shortName(getShortName()).description(getDescription()).build(); }
protected ManagedCommand addCommand(Map<String, ManagedCommand> commandMap, ManagedCommand managedCommand) { Command command = managedCommand.getCommand(); String name = command.getMetadata().getName(); return commandMap.put(name, managedCommand); }
protected void addCommandNoOverride(Map<String, ManagedCommand> commandMap, ManagedCommand managedCommand) { ManagedCommand existing = addCommand(commandMap, managedCommand); // complain on dupes if (existing != null && existing.getCommand() != managedCommand.getCommand()) { String c1 = existing.getCommand().getClass().getName(); String c2 = managedCommand.getCommand().getClass().getName(); String message = String.format("More than one DI command named '%s'. Conflicting types: %s, %s.", managedCommand.getCommand().getMetadata().getName(), c1, c2); throw new BootiqueException(1, message); } } }
protected void mergeOverrides(Map<String, ManagedCommand> commandMap) { if (commandOverrides != null) { commandOverrides.forEach(co -> { ManagedCommand.Builder builder = ManagedCommand.builder(co); // check existing command prior to overriding... preserve existing "help" and "default" flags ManagedCommand existing = commandMap.get(co.getMetadata().getName()); if (existing != null) { // preserve existing flags... if (existing.isHelp()) { builder.asHelp(); } if (existing.isDefault()) { builder.asDefault(); } // log override String i1 = existing.getCommand().getClass().getName(); String i2 = co.getClass().getName(); bootLogger.trace(() -> String.format("Overriding command '%s' (old command: %s, new command: %s)", co.getMetadata().getName(), i1, i2)); } addCommand(commandMap, builder.build()); }); } }
/** * Returns an option representation of this command, that may be used in help generation or exposing the command * in a CLI parser. * * @return option representation of this command. * @since 0.21 */ public OptionMetadata asOption() { // TODO: cache the value? // using getters instead of vars ; some getters have logic return OptionMetadata.builder(getName()).shortName(getShortName()).description(getDescription()).build(); }