Search in sources :

Example 1 with ArgumentWithValue

use of org.jboss.as.cli.impl.ArgumentWithValue in project wildfly-core by wildfly.

the class EmbedHostControllerHandler method create.

static EmbedHostControllerHandler create(final AtomicReference<EmbeddedProcessLaunch> hostControllerReference, final CommandContext ctx, final boolean modular) {
    EmbedHostControllerHandler result = new EmbedHostControllerHandler(hostControllerReference);
    final FilenameTabCompleter pathCompleter = FilenameTabCompleter.newCompleter(ctx);
    if (!modular) {
        result.jbossHome = new FileSystemPathArgument(result, pathCompleter, "--jboss-home");
    }
    result.stdOutHandling = new ArgumentWithValue(result, new SimpleTabCompleter(new String[] { ECHO, DISCARD_STDOUT }), "--std-out");
    result.domainConfig = new ArgumentWithValue(result, DOMAIN_CONFIG);
    result.hostConfig = new ArgumentWithValue(result, HOST_CONFIG);
    result.dashC = new ArgumentWithValue(result, "-c");
    result.dashC.addCantAppearAfter(result.domainConfig);
    result.domainConfig.addCantAppearAfter(result.dashC);
    result.timeout = new ArgumentWithValue(result, "--timeout");
    result.emptyDomainConfig = new ArgumentWithoutValue(result, EMPTY_DOMAIN_CONFIG);
    result.removeExistingDomainConfig = new ArgumentWithoutValue(result, REMOVE_EXISTING_DOMAIN_CONFIG);
    result.emptyHostConfig = new ArgumentWithoutValue(result, EMPTY_HOST_CONFIG);
    result.removeExistingHostConfig = new ArgumentWithoutValue(result, REMOVE_EXISTING_HOST_CONFIG);
    return result;
}
Also used : SimpleTabCompleter(org.jboss.as.cli.handlers.SimpleTabCompleter) FileSystemPathArgument(org.jboss.as.cli.impl.FileSystemPathArgument) ArgumentWithValue(org.jboss.as.cli.impl.ArgumentWithValue) FilenameTabCompleter(org.jboss.as.cli.handlers.FilenameTabCompleter) ArgumentWithoutValue(org.jboss.as.cli.impl.ArgumentWithoutValue)

Example 2 with ArgumentWithValue

use of org.jboss.as.cli.impl.ArgumentWithValue in project wildfly-core by wildfly.

the class GenericTypeOperationHandler method getHandler.

private OperationCommand getHandler(CommandContext ctx, String op) throws CommandLineException {
    if (op == null) {
        if (writePropHandler == null) {
            writePropHandler = new WritePropertyHandler();
            Iterator<AttributeDescription> props = getNodeProperties(ctx);
            while (props.hasNext()) {
                final AttributeDescription prop = props.next();
                if (prop.isWriteAllowed()) {
                    CommandLineCompleter valueCompleter = null;
                    ArgumentValueConverter valueConverter = null;
                    if (propConverters != null) {
                        valueConverter = propConverters.get(prop.getName());
                    }
                    if (valueCompleters != null) {
                        valueCompleter = valueCompleters.get(prop.getName());
                    }
                    if (valueConverter == null) {
                        valueConverter = ArgumentValueConverter.DEFAULT;
                        final ModelType propType = prop.getType();
                        if (propType != null) {
                            if (ModelType.BOOLEAN == propType) {
                                if (valueCompleter == null) {
                                    valueCompleter = SimpleTabCompleter.BOOLEAN;
                                }
                            } else if (ModelType.STRING == propType) {
                                valueConverter = ArgumentValueConverter.NON_OBJECT;
                            } else if (prop.getName().endsWith("properties")) {
                                // TODO this is bad but can't rely on proper descriptions
                                valueConverter = ArgumentValueConverter.PROPERTIES;
                            } else if (ModelType.LIST == propType) {
                                if (asType(prop.getProperty(Util.VALUE_TYPE)) == ModelType.PROPERTY) {
                                    valueConverter = ArgumentValueConverter.PROPERTIES;
                                } else {
                                    valueConverter = ArgumentValueConverter.LIST;
                                }
                            }
                        }
                    }
                    final CommandArgument arg = new ArgumentWithValue(GenericTypeOperationHandler.this, valueCompleter, valueConverter, "--" + prop.getName());
                    writePropHandler.addArgument(arg);
                }
            }
        }
        return writePropHandler;
    } else {
        if (customHandlers != null && customHandlers.containsKey(op)) {
            final OperationCommand opHandler = customHandlers.get(op);
            if (opHandler != null) {
                return opHandler;
            }
        }
        if (opHandlers != null) {
            OperationCommand opHandler = opHandlers.get(op);
            if (opHandler != null) {
                return opHandler;
            }
        }
        final ModelNode descr = getOperationDescription(ctx, op);
        if (opHandlers == null) {
            opHandlers = new HashMap<String, OperationCommand>();
        }
        final OpHandler opHandler = new OpHandler(op);
        opHandlers.put(op, opHandler);
        opHandler.addArgument(this.headers);
        if (descr != null && descr.has(Util.REQUEST_PROPERTIES)) {
            final List<Property> propList = descr.get(Util.REQUEST_PROPERTIES).asPropertyList();
            for (Property prop : propList) {
                final ModelNode propDescr = prop.getValue();
                CommandLineCompleter valueCompleter = null;
                ArgumentValueConverter valueConverter = null;
                if (propConverters != null) {
                    valueConverter = propConverters.get(prop.getName());
                }
                if (valueCompleters != null) {
                    valueCompleter = valueCompleters.get(prop.getName());
                }
                if (valueConverter == null) {
                    valueConverter = ArgumentValueConverter.DEFAULT;
                    if (propDescr.has(Util.TYPE)) {
                        final ModelType type = propDescr.get(Util.TYPE).asType();
                        if (ModelType.BOOLEAN == type) {
                            if (valueCompleter == null) {
                                valueCompleter = SimpleTabCompleter.BOOLEAN;
                            }
                        } else if (ModelType.STRING == type) {
                            valueConverter = ArgumentValueConverter.NON_OBJECT;
                        } else if (prop.getName().endsWith("properties")) {
                            // TODO this is bad but can't rely on proper descriptions
                            valueConverter = ArgumentValueConverter.PROPERTIES;
                        } else if (ModelType.LIST == type) {
                            if (propDescr.hasDefined(Util.VALUE_TYPE) && asType(propDescr.get(Util.VALUE_TYPE)) == ModelType.PROPERTY) {
                                valueConverter = ArgumentValueConverter.PROPERTIES;
                            } else {
                                valueConverter = ArgumentValueConverter.LIST;
                            }
                        }
                    }
                }
                final CommandArgument arg = new ArgumentWithValue(GenericTypeOperationHandler.this, valueCompleter, valueConverter, "--" + prop.getName());
                opHandler.addArgument(arg);
            }
        }
        return opHandler;
    }
}
Also used : CommandArgument(org.jboss.as.cli.CommandArgument) CommandLineCompleter(org.jboss.as.cli.CommandLineCompleter) OperationCommand(org.jboss.as.cli.OperationCommand) ArgumentValueConverter(org.jboss.as.cli.ArgumentValueConverter) ArgumentWithValue(org.jboss.as.cli.impl.ArgumentWithValue) ModelType(org.jboss.dmr.ModelType) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 3 with ArgumentWithValue

use of org.jboss.as.cli.impl.ArgumentWithValue in project wildfly-core by wildfly.

the class ResourceCompositeOperationHandler method getOperationArguments.

protected Map<String, ArgumentWithValue> getOperationArguments(CommandContext ctx, String opName) throws CommandLineException {
    Map<String, ArgumentWithValue> args = opArgs.get(opName);
    if (args != null) {
        return args;
    }
    final ModelNode descr = getOperationDescription(ctx, opName);
    if (descr.has(Util.REQUEST_PROPERTIES)) {
        args = new HashMap<String, ArgumentWithValue>();
        final List<Property> propList = descr.get(Util.REQUEST_PROPERTIES).asPropertyList();
        for (Property prop : propList) {
            CommandLineCompleter valueCompleter = null;
            ArgumentValueConverter valueConverter = null;
            if (propConverters != null) {
                valueConverter = propConverters.get(prop.getName());
            }
            if (valueCompleters != null) {
                valueCompleter = valueCompleters.get(prop.getName());
            }
            if (valueConverter == null) {
                valueConverter = ArgumentValueConverter.DEFAULT;
                final ModelType propType = getType(prop.getValue());
                if (propType != null) {
                    if (ModelType.BOOLEAN == propType) {
                        if (valueCompleter == null) {
                            valueCompleter = SimpleTabCompleter.BOOLEAN;
                        }
                    } else if (ModelType.STRING == propType) {
                        valueConverter = ArgumentValueConverter.NON_OBJECT;
                    } else if (prop.getName().endsWith("properties")) {
                        // TODO this is bad but can't rely on proper descriptions
                        valueConverter = ArgumentValueConverter.PROPERTIES;
                    } else if (ModelType.LIST == propType) {
                        if (asType(descr.get(Util.VALUE_TYPE)) == ModelType.PROPERTY) {
                            valueConverter = ArgumentValueConverter.PROPERTIES;
                        } else {
                            valueConverter = ArgumentValueConverter.LIST;
                        }
                    }
                }
            }
            final ArgumentWithValue arg = new ArgumentWithValue(ResourceCompositeOperationHandler.this, valueCompleter, valueConverter, "--" + prop.getName());
            args.put(arg.getFullName(), arg);
        }
    } else {
        args = Collections.emptyMap();
    }
    opArgs.put(opName, args);
    return args;
}
Also used : ArgumentWithValue(org.jboss.as.cli.impl.ArgumentWithValue) ArgumentValueConverter(org.jboss.as.cli.ArgumentValueConverter) ModelType(org.jboss.dmr.ModelType) CommandLineCompleter(org.jboss.as.cli.CommandLineCompleter) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 4 with ArgumentWithValue

use of org.jboss.as.cli.impl.ArgumentWithValue in project wildfly-core by wildfly.

the class ResourceCompositeOperationHandler method buildRequestWithoutHeaders.

@Override
protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException {
    final ModelNode address = buildOperationAddress(ctx);
    final ModelNode composite = new ModelNode();
    composite.get(Util.OPERATION).set(Util.COMPOSITE);
    composite.get(Util.ADDRESS).setEmptyList();
    final ModelNode steps = composite.get(Util.STEPS);
    for (String opName : this.ops) {
        final ModelNode req = new ModelNode();
        req.get(Util.OPERATION).set(opName);
        req.get(Util.ADDRESS).set(address);
        Map<String, ArgumentWithValue> opArgs;
        try {
            opArgs = getOperationArguments(ctx, opName);
        } catch (CommandFormatException e) {
            throw e;
        } catch (CommandLineException e) {
            throw new CommandFormatException("Failed to read " + opName + " arguments.", e);
        }
        for (ArgumentWithValue arg : opArgs.values()) {
            final String argName = arg.getFullName();
            final String propName;
            if (argName.charAt(1) == '-') {
                propName = argName.substring(2);
            } else {
                propName = argName.substring(1);
            }
            // final String valueString = arg.getOriginalValue(parsedArgs, false);
            // if(valueString != null) {
            // ModelNode nodeValue = arg.getValueConverter().fromString(ctx, valueString);
            final ModelNode nodeValue = arg.toModelNode(ctx);
            if (nodeValue != null) {
                req.get(propName).set(nodeValue);
            }
        }
        steps.add(req);
    }
    return composite;
}
Also used : ArgumentWithValue(org.jboss.as.cli.impl.ArgumentWithValue) CommandFormatException(org.jboss.as.cli.CommandFormatException) ModelNode(org.jboss.dmr.ModelNode) CommandLineException(org.jboss.as.cli.CommandLineException)

Example 5 with ArgumentWithValue

use of org.jboss.as.cli.impl.ArgumentWithValue in project wildfly-core by wildfly.

the class EmbedServerHandler method create.

static EmbedServerHandler create(final AtomicReference<EmbeddedProcessLaunch> serverReference, CommandContext ctx, boolean modular) {
    EmbedServerHandler result = new EmbedServerHandler(serverReference);
    final FilenameTabCompleter pathCompleter = FilenameTabCompleter.newCompleter(ctx);
    if (!modular) {
        result.jbossHome = new FileSystemPathArgument(result, pathCompleter, "--jboss-home");
    }
    result.stdOutHandling = new ArgumentWithValue(result, new SimpleTabCompleter(new String[] { ECHO, DISCARD_STDOUT }), "--std-out");
    result.serverConfig = new ArgumentWithValue(result, "--server-config");
    result.dashC = new ArgumentWithValue(result, "-c");
    result.dashC.addCantAppearAfter(result.serverConfig);
    result.serverConfig.addCantAppearAfter(result.dashC);
    result.adminOnly = new ArgumentWithValue(result, SimpleTabCompleter.BOOLEAN, "--admin-only");
    result.emptyConfig = new ArgumentWithoutValue(result, "--empty-config");
    result.removeExisting = new ArgumentWithoutValue(result, "--remove-existing");
    result.removeExisting.addRequiredPreceding(result.emptyConfig);
    result.timeout = new ArgumentWithValue(result, "--timeout");
    return result;
}
Also used : SimpleTabCompleter(org.jboss.as.cli.handlers.SimpleTabCompleter) FileSystemPathArgument(org.jboss.as.cli.impl.FileSystemPathArgument) ArgumentWithValue(org.jboss.as.cli.impl.ArgumentWithValue) FilenameTabCompleter(org.jboss.as.cli.handlers.FilenameTabCompleter) ArgumentWithoutValue(org.jboss.as.cli.impl.ArgumentWithoutValue)

Aggregations

ArgumentWithValue (org.jboss.as.cli.impl.ArgumentWithValue)5 ModelNode (org.jboss.dmr.ModelNode)3 ArgumentValueConverter (org.jboss.as.cli.ArgumentValueConverter)2 CommandLineCompleter (org.jboss.as.cli.CommandLineCompleter)2 FilenameTabCompleter (org.jboss.as.cli.handlers.FilenameTabCompleter)2 SimpleTabCompleter (org.jboss.as.cli.handlers.SimpleTabCompleter)2 ArgumentWithoutValue (org.jboss.as.cli.impl.ArgumentWithoutValue)2 FileSystemPathArgument (org.jboss.as.cli.impl.FileSystemPathArgument)2 ModelType (org.jboss.dmr.ModelType)2 Property (org.jboss.dmr.Property)2 CommandArgument (org.jboss.as.cli.CommandArgument)1 CommandFormatException (org.jboss.as.cli.CommandFormatException)1 CommandLineException (org.jboss.as.cli.CommandLineException)1 OperationCommand (org.jboss.as.cli.OperationCommand)1