diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -1537,15 +1537,29 @@ } static StringRef ArgPrefix = " -"; +static StringRef ArgPrefixLong = " --"; static StringRef ArgHelpPrefix = " - "; -static size_t ArgPrefixesSize = ArgPrefix.size() + ArgHelpPrefix.size(); + +static size_t argPrefixesSize(size_t len) { + if (len == 1) + return ArgPrefix.size() + ArgHelpPrefix.size(); + return ArgPrefixLong.size() + ArgHelpPrefix.size(); +} + +static StringRef argPrefix(size_t len) { + if (len == 1) + return ArgPrefix; + return ArgPrefixLong; +} //===----------------------------------------------------------------------===// // cl::alias class implementation // // Return the width of the option tag for printing... -size_t alias::getOptionWidth() const { return ArgStr.size() + ArgPrefixesSize; } +size_t alias::getOptionWidth() const { + return ArgStr.size() + argPrefixesSize(ArgStr.size()); +} void Option::printHelpStr(StringRef HelpStr, size_t Indent, size_t FirstLineIndentedBy) { @@ -1561,8 +1575,9 @@ // Print out the option for the alias. void alias::printOptionInfo(size_t GlobalWidth) const { - outs() << ArgPrefix << ArgStr; - printHelpStr(HelpStr, GlobalWidth, ArgStr.size() + ArgPrefixesSize); + outs() << argPrefix(ArgStr.size()) << ArgStr; + printHelpStr(HelpStr, GlobalWidth, + ArgStr.size() + argPrefixesSize(ArgStr.size())); } //===----------------------------------------------------------------------===// @@ -1583,7 +1598,7 @@ Len += getValueStr(O, ValName).size() + FormattingLen; } - return Len + ArgPrefixesSize; + return Len + argPrefixesSize(O.ArgStr.size()); } // printOptionInfo - Print out information about this option. The @@ -1591,7 +1606,7 @@ // void basic_parser_impl::printOptionInfo(const Option &O, size_t GlobalWidth) const { - outs() << ArgPrefix << O.ArgStr; + outs() << argPrefix(O.ArgStr.size()) << O.ArgStr; auto ValName = getValueName(); if (!ValName.empty()) { @@ -1607,7 +1622,7 @@ void basic_parser_impl::printOptionName(const Option &O, size_t GlobalWidth) const { - outs() << ArgPrefix << O.ArgStr; + outs() << argPrefix(O.ArgStr.size()) << O.ArgStr; outs().indent(GlobalWidth - O.ArgStr.size()); } @@ -1739,7 +1754,8 @@ // Return the width of the option tag for printing... size_t generic_parser_base::getOptionWidth(const Option &O) const { if (O.hasArgStr()) { - size_t Size = O.ArgStr.size() + ArgPrefixesSize + EqValue.size(); + size_t Size = + O.ArgStr.size() + argPrefixesSize(O.ArgStr.size()) + EqValue.size(); for (unsigned i = 0, e = getNumOptions(); i != e; ++i) { StringRef Name = getOption(i); if (!shouldPrintOption(Name, getDescription(i), O)) @@ -1767,17 +1783,19 @@ if (O.getValueExpectedFlag() == ValueOptional) { for (unsigned i = 0, e = getNumOptions(); i != e; ++i) { if (getOption(i).empty()) { - outs() << ArgPrefix << O.ArgStr; + outs() << argPrefix(O.ArgStr.size()) << O.ArgStr; Option::printHelpStr(O.HelpStr, GlobalWidth, - O.ArgStr.size() + ArgPrefixesSize); + O.ArgStr.size() + + argPrefixesSize(O.ArgStr.size())); break; } } } - outs() << ArgPrefix << O.ArgStr << EqValue; + outs() << argPrefix(O.ArgStr.size()) << O.ArgStr << EqValue; Option::printHelpStr(O.HelpStr, GlobalWidth, - O.ArgStr.size() + EqValue.size() + ArgPrefixesSize); + O.ArgStr.size() + EqValue.size() + + argPrefixesSize(O.ArgStr.size())); for (unsigned i = 0, e = getNumOptions(); i != e; ++i) { StringRef OptionName = getOption(i); StringRef Description = getDescription(i);