protected StringBuffer renderOptions()

in apache-rat-core/src/main/java/org/apache/rat/help/AbstractHelp.java [133:199]


        protected StringBuffer renderOptions(final StringBuffer sb, final int width, final Options options, final int leftPad, final int descPad) {
            final String lpad = createPadding(leftPad);
            final String dpad = createPadding(descPad);
            // first create list containing only <lpad>-a,--aaa where
            // -a is opt and --aaa is long opt; in parallel look for
            // the longest opt string; this list will then be used to
            // sort options ascending
            int max = 0;
            final List<StringBuffer> prefixList = new ArrayList<>();
            final List<Option> optList = new ArrayList<>(options.getOptions());
            optList.sort(helpFormatter.getOptionComparator());

            for (final Option option : optList) {
                final StringBuffer optBuf = new StringBuffer();
                if (option.getOpt() == null) {
                    optBuf.append(lpad).append("   ").append(getLongOptPrefix()).append(option.getLongOpt());
                } else {
                    optBuf.append(lpad).append(getOptPrefix()).append(option.getOpt());
                    if (option.hasLongOpt()) {
                        optBuf.append(',').append(getLongOptPrefix()).append(option.getLongOpt());
                    }
                }
                if (option.hasArg()) {
                    final String argName = option.getArgName();
                    if (argName != null && argName.isEmpty()) {
                        // if the option has a blank argname
                        optBuf.append(' ');
                    } else {
                        optBuf.append(option.hasLongOpt() ? helpFormatter.getLongOptSeparator() : " ");
                        optBuf.append("<").append(argName != null ? option.getArgName() : getArgName()).append(">");
                    }
                }
                prefixList.add(optBuf);
                max = Math.max(optBuf.length(), max);
            }
            int x = 0;
            for (final Iterator<Option> it = optList.iterator(); it.hasNext();) {
                final Option option = it.next();
                final StringBuilder optBuf = new StringBuilder(prefixList.get(x++).toString());
                if (optBuf.length() < max) {
                    optBuf.append(createPadding(max - optBuf.length()));
                }
                optBuf.append(dpad);
                final int nextLineTabStop = max + descPad;
                // check for deprecation
                if (option.isDeprecated()) {
                    optBuf.append(DEPRECATED_MSG.apply(option).trim());
                } else if (option.getDescription() != null) {
                    optBuf.append(option.getDescription());
                }
                // check for multiple values
                if (option.hasArgs()) {
                    optBuf.append(END_OF_OPTION_MSG);
                }
                // check for default value
                Arg arg = Arg.findArg(option);
                String defaultValue = arg == null ? null : arg.defaultValue();
                if (defaultValue != null) {
                    optBuf.append(format(" (Default value = %s)", defaultValue));
                }
                renderWrappedText(sb, width, nextLineTabStop, optBuf.toString());
                if (it.hasNext()) {
                    sb.append(getNewLine());
                }
            }
            return sb;
        }