private void appendEchoOption(StringBuilder sb, ParamModel opt, String value) { sb.append("--").append(lc(opt.getName())); if (opt.getType() == Boolean.class || opt.getType() == boolean.class) { sb.append("=").append(Boolean.toString(Boolean.parseBoolean(value))); } else { // STRING or FILE sb.append(" ").append(quote(value)); } sb.append(' '); }
@Override public void postConstruct() { super.postConstruct(); listing = targetMethod.getAnnotation(Listing.class); resolverType = listing.resolver(); try { // we pass false for "useAnnotations" as the @Param declarations on // the target type are not used for the List method parameters. cmdModel = new GenericCommandModel(targetType, false, null, listing.i18n(), new LocalStringManagerImpl(targetType), habitat.<DomDocument>getService(DomDocument.class), commandName, false, listing.resolver(), GenericListCommand.class); targetModel = habitat.<DomDocument>getService(DomDocument.class).buildModel(targetType); if (logger.isLoggable(level)) { for (String paramName : cmdModel.getParametersNames()) { CommandModel.ParamModel param = cmdModel.getModelFor(paramName); logger.log(Level.FINE, "I take {0} parameters", param.getName()); } } } catch(Exception e) { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.command_model_exception", "Exception while creating the command model for the generic command {0} : {1}", commandName, e.getMessage()); LogHelper.log(logger, Level.SEVERE,ConfigApiLoggerInfo.GENERIC_CREATE_CMD_FAILED, e, commandName); throw new RuntimeException(msg, e); } }
@Override public void postConstruct() { super.postConstruct(); create = getAnnotation(targetMethod, Create.class); resolverType = create.resolver(); try { model = new GenericCommandModel(targetType, true, create.cluster(), create.i18n(), new LocalStringManagerImpl(targetType), habitat.<DomDocument>getService(DomDocument.class), commandName, AnnotationUtil.presentTransitive(ManagedJob.class, create.decorator()), create.resolver(), create.decorator()); if (logger.isLoggable(level)) { for (String paramName : model.getParametersNames()) { CommandModel.ParamModel param = model.getModelFor(paramName); logger.log(Level.FINE, "I take {0} parameters", param.getName()); } } } catch(Exception e) { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.command_model_exception", "Exception while creating the command model for the generic command {0} : {1}", commandName, e.getMessage()); logger.log(Level.SEVERE, ConfigApiLoggerInfo.GENERIC_CREATE_CMD_FAILED, commandName); throw new RuntimeException(msg, e); } }
/** * Get ParamModel for long option name. */ private ParamModel lookupLongOption(String s) { if (s == null || s.length() == 0) return null; // XXX - for now, fake it if no options if (options == null) { // no valid options specified so everything is valid return new ParamModelData(s, String.class, true, null); } for (ParamModel od : options) { if (od.getParam().primary()) continue; if (s.equalsIgnoreCase(od.getName())) return od; if (s.equalsIgnoreCase(od.getParam().alias())) return od; } return null; }
public void postConstruct() { super.postConstruct(); create = getAnnotation(targetMethod, Create.class); resolverType = create.resolver(); try { model = new GenericCommandModel(targetType, true, create.cluster(), create.i18n(), new LocalStringManagerImpl(targetType), habitat.getComponent(DomDocument.class), commandName, create.resolver(), create.decorator()); if (logger.isLoggable(level)) { for (String paramName : model.getParametersNames()) { CommandModel.ParamModel param = model.getModelFor(paramName); logger.fine("I take " + param.getName() + " parameters"); } } } catch(Exception e) { String msg = localStrings.getLocalString(GenericCrudCommand.class, "GenericCreateCommand.command_model_exception", "Exception while creating the command model for the generic command {0} : {1}", commandName, e.getMessage()); logger.severe(msg); throw new ComponentException(msg, e); } }
/** * Add --adminport and --instanceport options with * proper default values. (Can't set default values above * because it conflicts with --portbase option processing.) */ protected Collection<ParamModel> usageOptions() { Collection<ParamModel> opts = commandModel.getParameters(); Set<ParamModel> uopts = new LinkedHashSet<ParamModel>(); ParamModel aPort = new ParamModelData(ADMIN_PORT, String.class, true, Integer.toString(CLIConstants.DEFAULT_ADMIN_PORT)); ParamModel iPort = new ParamModelData(INSTANCE_PORT, String.class, true, Integer.toString(DEFAULT_INSTANCE_PORT)); for (ParamModel pm : opts) { if (pm.getName().equals(ADMIN_PORT)) uopts.add(aPort); else if (pm.getName().equals(INSTANCE_PORT)) uopts.add(iPort); else uopts.add(pm); } return uopts; }
/** * Get ParamModel for long option name. */ private ParamModel lookupLongOption(String s) { if (s == null || s.length() == 0) return null; // XXX - for now, fake it if no options if (options == null) { // no valid options specified so everything is valid return new ParamModelData(s, String.class, true, null); } for (ParamModel od : options) { if (od.getParam().primary()) continue; if (s.equalsIgnoreCase(od.getName())) return od; if (s.equalsIgnoreCase(od.getParam().alias())) return od; } return null; }
/** * In the usage message modify the --printprompt option to have a * default based on the --interactive option. */ protected Collection<ParamModel> usageOptions() { Collection<ParamModel> opts = commandModel.getParameters(); Set<ParamModel> uopts = new LinkedHashSet<ParamModel>(); ParamModel p = new CommandModelData.ParamModelData("printprompt", boolean.class, true, Boolean.toString(programOpts.isInteractive())); for (ParamModel pm : opts) { if (pm.getName().equals("printprompt")) uopts.add(p); else uopts.add(pm); } return uopts; }
/** * In the usage message modify the --printprompt option to have a default * based on the --interactive option. */ protected Collection<ParamModel> usageOptions() { Collection<ParamModel> opts = commandModel.getParameters(); Set<ParamModel> uopts = new LinkedHashSet<ParamModel>(); ParamModel p = new CommandModelData.ParamModelData("printprompt", boolean.class, true, Boolean.toString(programOpts.isInteractive())); for (ParamModel pm : opts) { if (pm.getName().equals("printprompt")) uopts.add(p); else uopts.add(pm); } return uopts; }
private String passwordName(ParamModel opt) { return Environment.getPrefix() + opt.getName().toUpperCase(Locale.ENGLISH); }
public void validatePassword(String password, ParamModel pwdOpt) throws CommandValidationException { // XXX - hack alert! the description is stored in the default value String description = pwdOpt.getParam().defaultValue(); if (!ok(description)) description = pwdOpt.getName(); if (password == null) throw new CommandValidationException( strings.get("PasswordMissing", description)); }