Package io.airlift.airline.model

Examples of io.airlift.airline.model.CommandMetadata


     */
    @Test
    public void repeatedArgs()
    {
        Cli<Args1> parser = singleCommandParser(Args1.class);
        CommandMetadata command = find(parser.getMetadata().getDefaultGroupCommands(), compose(equalTo("Args1"), CommandMetadata.nameGetter()));
        assertEquals(command.getAllOptions().size(), 8);
    }
View Full Code Here


        if (state.getGroup() != null) {
            expectedCommands = state.getGroup().getCommands();
        }

        if (tokens.hasNext()) {
            CommandMetadata command = find(expectedCommands, compose(equalTo(tokens.peek()), CommandMetadata.nameGetter()), null);
            if (command == null) {
                while (tokens.hasNext()) {
                    state = state.withUnparsedInput(tokens.next());
                }
            }
            else {
                tokens.next();
                state = state.withCommand(command).pushContext(Context.COMMAND);

                while (tokens.hasNext()) {
                    state = parseOptions(tokens, state, command.getCommandOptions());

                    state = parseArgs(state, tokens, command.getArguments());
                }
            }
        }

        return state;
View Full Code Here

       
        Parser parser = new Parser();
        ParseState state = parser.parseCommand(commandMetadata, args);
        validate(state);

        CommandMetadata command = state.getCommand();

        return createInstance(command.getType(),
                command.getAllOptions(),
                state.getParsedOptions(),
                command.getArguments(),
                state.getParsedArguments(),
                command.getMetadataInjections(),
                ImmutableMap.<Class<?>, Object>of(CommandMetadata.class, commandMetadata));
    }
View Full Code Here

                ImmutableMap.<Class<?>, Object>of(CommandMetadata.class, commandMetadata));
    }
   
    private void validate(ParseState state)
    {
        CommandMetadata command = state.getCommand();
        if (command == null) {
            List<String> unparsedInput = state.getUnparsedInput();
            if (unparsedInput.isEmpty()) {
                throw new ParseCommandMissingException();
            }
            else {
                throw new ParseCommandUnrecognizedException(unparsedInput);
            }
        }

        ArgumentsMetadata arguments = command.getArguments();
        if (state.getParsedArguments().isEmpty() && arguments != null && arguments.isRequired()) {
            throw new ParseArgumentsMissingException(arguments.getTitle());
        }
       
        if (!state.getUnparsedInput().isEmpty()) {
            throw new ParseArgumentsUnexpectedException(state.getUnparsedInput());
        }

        if (state.getLocation() == Context.OPTION) {
            throw new ParseOptionMissingValueException(state.getCurrentOption().getTitle());
        }

        for (OptionMetadata option : command.getAllOptions()) {
            if (option.isRequired() && !state.getParsedOptions().containsKey(option)) {
                throw new ParseOptionMissingException(option.getOptions().iterator().next());
            }
        }
    }
View Full Code Here

            Iterable<GroupBuilder<C>> groups)
    {
        Preconditions.checkNotNull(name, "name is null");
        Preconditions.checkNotNull(typeConverter, "typeConverter is null");

        CommandMetadata defaultCommandMetadata = null;
        if (defaultCommand != null) {
            defaultCommandMetadata = MetadataLoader.loadCommand(defaultCommand);
        }

        List<CommandMetadata> defaultCommandGroup = MetadataLoader.loadCommands(defaultGroupCommands);
View Full Code Here

            }
        }

        validate(state);

        CommandMetadata command = state.getCommand();

        return createInstance(command.getType(),
                command.getAllOptions(),
                state.getParsedOptions(),
                command.getArguments(),
                state.getParsedArguments(),
                command.getMetadataInjections(),
                ImmutableMap.<Class<?>, Object>of(GlobalMetadata.class, metadata));
    }
View Full Code Here

                ImmutableMap.<Class<?>, Object>of(GlobalMetadata.class, metadata));
    }
   
    private void validate(ParseState state)
    {
        CommandMetadata command = state.getCommand();
        if (command == null) {
            List<String> unparsedInput = state.getUnparsedInput();
            if (unparsedInput.isEmpty()) {
                throw new ParseCommandMissingException();
            }
            else {
                throw new ParseCommandUnrecognizedException(unparsedInput);
            }
        }

        ArgumentsMetadata arguments = command.getArguments();
        if (state.getParsedArguments().isEmpty() && arguments != null && arguments.isRequired()) {
            throw new ParseArgumentsMissingException(arguments.getTitle());
        }
       
        if (!state.getUnparsedInput().isEmpty()) {
            throw new ParseArgumentsUnexpectedException(state.getUnparsedInput());
        }

        if (state.getLocation() == Context.OPTION) {
            throw new ParseOptionMissingValueException(state.getCurrentOption().getTitle());
        }

        for (OptionMetadata option : command.getAllOptions()) {
            if (option.isRequired() && !state.getParsedOptions().containsKey(option)) {
                throw new ParseOptionMissingException(option.getOptions().iterator().next());
            }
        }
    }
View Full Code Here

     */
    @Test
    public void repeatedArgs()
    {
        SingleCommand<Args1> parser = singleCommand(Args1.class);
        CommandMetadata command = find(ImmutableList.of(parser.getCommandMetadata()), compose(equalTo("Args1"), CommandMetadata.nameGetter()));
        assertEquals(command.getAllOptions().size(), 8);
    }
View Full Code Here

        List<CommandMetadata> commands = newArrayList(group.getCommands());
        Collections.sort(commands, commandComparator);

        if (group.getDefaultCommand() != null) {
            CommandMetadata command = group.getDefaultCommand();
            if (global != null) {
                synopsis.append(global.getName());
                if (!hideGlobalOptions) {
                    synopsis.appendWords(UsageHelper.toSynopsisUsage(command.getGlobalOptions()));
                }
            }
            synopsis.append(group.getName()).appendWords(UsageHelper.toSynopsisUsage(command.getGroupOptions()));
            synopsis.newline();
        }
        for (CommandMetadata command : commands) {
            if (global != null) {
                synopsis.append(global.getName());
                if (!hideGlobalOptions) {
                    synopsis.appendWords(UsageHelper.toSynopsisUsage(command.getGlobalOptions()));
                }
            }
            synopsis.append(group.getName()).appendWords(UsageHelper.toSynopsisUsage(command.getGroupOptions()));
            synopsis.append(command.getName()).appendWords(UsageHelper.toSynopsisUsage(command.getCommandOptions()));
            synopsis.newline();
        }
        synopsis.newline();

        //
        // OPTIONS
        //
        List<OptionMetadata> options = newArrayList();
        options.addAll(group.getOptions());
        if (global != null && !hideGlobalOptions) {
            options.addAll(global.getOptions());
        }
        if (options.size() > 0) {
            if (optionComparator != null) {
                Collections.sort(options, optionComparator);
            }

            out.append("OPTIONS").newline();

            for (OptionMetadata option : options) {
                // option names
                UsagePrinter optionPrinter = out.newIndentedPrinter(8);
                optionPrinter.append(UsageHelper.toDescription(option)).newline();

                // description
                UsagePrinter descriptionPrinter = optionPrinter.newIndentedPrinter(4);
                descriptionPrinter.append(option.getDescription()).newline();

                descriptionPrinter.newline();
            }
        }

        //
        // COMMANDS
        //
        if (commands.size() > 0 || group.getDefaultCommand() != null) {
            out.append("COMMANDS").newline();
            UsagePrinter commandPrinter = out.newIndentedPrinter(8);

            if (group.getDefaultCommand() != null && group.getDefaultCommand().getDescription() != null) {
                commandPrinter.append("With no arguments,")
                        .append(group.getDefaultCommand().getDescription())
                        .newline()
                        .newline();
            }

            for (CommandMetadata command : group.getCommands()) {
                commandPrinter.append(command.getName()).newline();
                UsagePrinter descriptionPrinter = commandPrinter.newIndentedPrinter(4);

                descriptionPrinter.append(command.getDescription()).newline().newline();

                for (OptionMetadata option : command.getCommandOptions()) {
                    if (!option.isHidden() && option.getDescription() != null) {
                        descriptionPrinter.append("With")
                                .append(longest(option.getOptions()))
                                .append("option,")
                                .append(option.getDescription())
View Full Code Here

TOP

Related Classes of io.airlift.airline.model.CommandMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.