public static String toDescription(ArgumentsMetadata arguments) { if (!arguments.getUsage().isEmpty()) { return arguments.getUsage(); } return "<" + arguments.getTitle() + ">"; }
public static String toUsage(ArgumentsMetadata arguments) { if (!arguments.getUsage().isEmpty()) { return arguments.getUsage(); } boolean required = arguments.isRequired(); StringBuilder stringBuilder = new StringBuilder(); if (!required) { stringBuilder.append('['); } stringBuilder.append("<").append(arguments.getTitle()).append(">"); if (arguments.isMultiValued()) { stringBuilder.append("..."); } if (!required) { stringBuilder.append(']'); } return stringBuilder.toString(); }
private ParseState parseArg(ParseState state, PeekingIterator<String> tokens, ArgumentsMetadata arguments) { if (arguments != null) { state = state.withArgument(TypeConverter.newInstance().convert(arguments.getTitle(), arguments.getJavaType(), tokens.next())); } else { state = state.withUnparsedInput(tokens.next()); } return state; }
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()); } } }