Search in sources :

Example 6 with ParamModel

use of org.glassfish.api.admin.CommandModel.ParamModel in project Payara by payara.

the class CreateDomainCommand method usageOptions.

/**
 * Add --adminport and --instanceport options with proper default values.
 * (Can't set default values above because it conflicts with --portbase
 * option processing.)
 */
@Override
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;
}
Also used : ParamModel(org.glassfish.api.admin.CommandModel.ParamModel) ParamModelData(com.sun.enterprise.admin.util.CommandModelData.ParamModelData)

Example 7 with ParamModel

use of org.glassfish.api.admin.CommandModel.ParamModel in project Payara by payara.

the class LocalOSGiShellCommand method usageOptions.

/**
 * In the usage message modify the --printprompt option to have a
 * default based on the --interactive option.
 */
@Override
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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ParamModel(org.glassfish.api.admin.CommandModel.ParamModel)

Example 8 with ParamModel

use of org.glassfish.api.admin.CommandModel.ParamModel in project Payara by payara.

the class CLICommand method echoCommand.

/**
 * Return a string representing the command line used with this command.
 */
private String echoCommand() {
    StringBuilder sb = new StringBuilder();
    // first, the program options
    sb.append(programOpts.getCommandName());
    sb.append(' ');
    sb.append(programOpts.toString()).append(' ');
    // now the subcommand options and operands
    sb.append(name).append(' ');
    // have we parsed any options yet?
    if (options != null && operands != null) {
        for (ParamModel opt : commandModel.getParameters()) {
            if (opt.getParam().password())
                // don't print passwords
                continue;
            if (opt.getParam().primary())
                continue;
            // and every option that has a default value
            if (opt.getParam().multiple()) {
                List<String> paramValues = getOptions(opt.getName());
                for (String v : paramValues) {
                    appendEchoOption(sb, opt, v);
                }
            } else {
                String value = getOption(opt.getName());
                if (value != null) {
                    appendEchoOption(sb, opt, value);
                }
            }
        }
        for (String o : operands) sb.append(quote(o)).append(' ');
    } else if (argv != null) {
        // haven't parsed any options, include raw arguments, if any
        for (String arg : argv) sb.append(quote(arg)).append(' ');
    }
    // strip trailing space
    sb.setLength(sb.length() - 1);
    return sb.toString();
}
Also used : ParamModel(org.glassfish.api.admin.CommandModel.ParamModel)

Example 9 with ParamModel

use of org.glassfish.api.admin.CommandModel.ParamModel in project Payara by payara.

the class CLICommand method processProgramOptions.

/**
 * If the program options haven't already been set, parse them
 * on the command line and remove them from the command line.
 * Subclasses should call this method in their prepare method
 * after initializing commandOpts (so usage is available on failure)
 * if they want to allow program options after the command name.
 * Currently RemoteCommand does this, as well as the local commands
 * that also need to talk to the server.
 */
protected void processProgramOptions() throws CommandException {
    /*
         * asadmin options and command options are intermixed.
         * Parse the entire command line for asadmin options,
         * removing them from the command line, and ignoring
         * unknown options.
         */
    Collection<ParamModel> model = ProgramOptions.getValidOptions();
    if (programOpts.isOptionsSet()) {
        model = ProgramOptions.getHelpOption();
    }
    Parser rcp = new Parser(argv, 0, model, true);
    ParameterMap params = rcp.getOptions();
    List<String> oprds = rcp.getOperands();
    argv = oprds.toArray(new String[oprds.size()]);
    if (params.size() > 0) {
        // at least one program option specified after command name
        logger.finer("Update program options");
        programOpts.updateOptions(params);
        initializeLogger();
        initializePasswords();
        if (!programOpts.isTerse() && !(params.size() == 1 && params.get("help") != null)) {
            // warn about deprecated use of program options
            // (except --help)
            // XXX - a lot of work for a nice message...
            Collection<ParamModel> programOptions = ProgramOptions.getValidOptions();
            StringBuilder sb = new StringBuilder();
            sb.append(programOpts.getCommandName());
            for (Map.Entry<String, List<String>> p : params.entrySet()) {
                // find the corresponding ParamModel
                ParamModel opt = null;
                for (ParamModel vo : programOptions) {
                    if (vo.getName().equalsIgnoreCase(p.getKey())) {
                        opt = vo;
                        break;
                    }
                }
                if (opt == null) {
                    continue;
                }
                // format the option appropriately
                sb.append(" --").append(p.getKey());
                List<String> pl = p.getValue();
                // XXX - won't handle multi-values
                if (opt.getType() == Boolean.class || opt.getType() == boolean.class) {
                    if (!pl.get(0).equalsIgnoreCase("true")) {
                        sb.append("=false");
                    }
                } else if (pl != null && pl.size() > 0) {
                    sb.append(" ").append(pl.get(0));
                }
            }
            sb.append(" ").append(name).append(" [options] ...");
            logger.info(strings.get("DeprecatedSyntax"));
            logger.info(sb.toString());
        }
    }
}
Also used : ParamModel(org.glassfish.api.admin.CommandModel.ParamModel)

Example 10 with ParamModel

use of org.glassfish.api.admin.CommandModel.ParamModel in project Payara by payara.

the class MultimodeCommand method usageOptions.

/**
 * 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;
}
Also used : ParamModel(org.glassfish.api.admin.CommandModel.ParamModel)

Aggregations

ParamModel (org.glassfish.api.admin.CommandModel.ParamModel)15 SmartFile (com.sun.enterprise.universal.io.SmartFile)4 ParamModelData (com.sun.enterprise.admin.util.CommandModelData.ParamModelData)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 CommandException (org.glassfish.api.admin.CommandException)2 InvalidCommandException (org.glassfish.api.admin.InvalidCommandException)2 ParameterMap (org.glassfish.api.admin.ParameterMap)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 NodeList (org.w3c.dom.NodeList)2 RemoteCLICommand (com.sun.enterprise.admin.cli.remote.RemoteCLICommand)1 RemoteCommand (com.sun.enterprise.admin.cli.remote.RemoteCommand)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 Singleton (javax.inject.Singleton)1 Param (org.glassfish.api.Param)1