Search in sources :

Example 1 with ArgumentValueConverter

use of org.jboss.as.cli.ArgumentValueConverter 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 2 with ArgumentValueConverter

use of org.jboss.as.cli.ArgumentValueConverter 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)

Aggregations

ArgumentValueConverter (org.jboss.as.cli.ArgumentValueConverter)2 CommandLineCompleter (org.jboss.as.cli.CommandLineCompleter)2 ArgumentWithValue (org.jboss.as.cli.impl.ArgumentWithValue)2 ModelNode (org.jboss.dmr.ModelNode)2 ModelType (org.jboss.dmr.ModelType)2 Property (org.jboss.dmr.Property)2 CommandArgument (org.jboss.as.cli.CommandArgument)1 OperationCommand (org.jboss.as.cli.OperationCommand)1