Java源码示例:io.airlift.airline.OptionType

示例1
/**
 * We check if the option is set here rather than in each command
 * to have a single place to catch all exceptions.
 *
 * Given that we first catch ParseArgumentsUnexpectedException we
 * do expect that parsing the same input again will not throw an exception.
 */
private static boolean stacktraceIsSet(final GlobalMetadata globalMetadata, final String[] args) {
    try {
        Parser p = new Parser();
        ListMultimap<OptionMetadata, Object> options = p.parse(globalMetadata, args).getParsedOptions();

        for (Map.Entry<OptionMetadata, Collection<Object>> option : options.asMap().entrySet()) {
            OptionMetadata metadata = option.getKey();

            if (metadata.getOptionType() == OptionType.GLOBAL
                    && metadata.getOptions().contains("--stacktrace")) {
                return option.getValue().contains(true);
            }
        }
    } catch (Exception e) {
        System.err.println("Failed to determine if the stacktrace should be shown. Please report this bug.");
    }

    return false;
}