mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[Support] Indent multi-line descr of enum cli options.
As noted in https://reviews.llvm.org/D93459, the formatting of multi-line descriptions of clEnumValN and the likes is unfavorable. Thus this patch adds support for correctly indenting these. Reviewed By: serge-sans-paille Differential Revision: https://reviews.llvm.org/D93494
This commit is contained in:
parent
ab4f1aa423
commit
f40f02934a
@ -369,9 +369,22 @@ public:
|
|||||||
|
|
||||||
virtual void setDefault() = 0;
|
virtual void setDefault() = 0;
|
||||||
|
|
||||||
|
// Prints the help string for an option.
|
||||||
|
//
|
||||||
|
// This maintains the Indent for multi-line descriptions.
|
||||||
|
// FirstLineIndentedBy is the count of chars of the first line
|
||||||
|
// i.e. the one containing the --<option name>.
|
||||||
static void printHelpStr(StringRef HelpStr, size_t Indent,
|
static void printHelpStr(StringRef HelpStr, size_t Indent,
|
||||||
size_t FirstLineIndentedBy);
|
size_t FirstLineIndentedBy);
|
||||||
|
|
||||||
|
// Prints the help string for an enum value.
|
||||||
|
//
|
||||||
|
// This maintains the Indent for multi-line descriptions.
|
||||||
|
// FirstLineIndentedBy is the count of chars of the first line
|
||||||
|
// i.e. the one containing the =<value>.
|
||||||
|
static void printEnumValHelpStr(StringRef HelpStr, size_t Indent,
|
||||||
|
size_t FirstLineIndentedBy);
|
||||||
|
|
||||||
virtual void getExtraOptionNames(SmallVectorImpl<StringRef> &) {}
|
virtual void getExtraOptionNames(SmallVectorImpl<StringRef> &) {}
|
||||||
|
|
||||||
// addOccurrence - Wrapper around handleOccurrence that enforces Flags.
|
// addOccurrence - Wrapper around handleOccurrence that enforces Flags.
|
||||||
|
@ -1726,6 +1726,19 @@ void Option::printHelpStr(StringRef HelpStr, size_t Indent,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Option::printEnumValHelpStr(StringRef HelpStr, size_t BaseIndent,
|
||||||
|
size_t FirstLineIndentedBy) {
|
||||||
|
const StringRef ValHelpPrefix = " ";
|
||||||
|
assert(BaseIndent >= FirstLineIndentedBy + ValHelpPrefix.size());
|
||||||
|
std::pair<StringRef, StringRef> Split = HelpStr.split('\n');
|
||||||
|
outs().indent(BaseIndent - FirstLineIndentedBy)
|
||||||
|
<< ArgHelpPrefix << ValHelpPrefix << Split.first << "\n";
|
||||||
|
while (!Split.second.empty()) {
|
||||||
|
Split = Split.second.split('\n');
|
||||||
|
outs().indent(BaseIndent + ValHelpPrefix.size()) << Split.first << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Print out the option for the alias.
|
// Print out the option for the alias.
|
||||||
void alias::printOptionInfo(size_t GlobalWidth) const {
|
void alias::printOptionInfo(size_t GlobalWidth) const {
|
||||||
outs() << PrintArg(ArgStr);
|
outs() << PrintArg(ArgStr);
|
||||||
@ -1971,17 +1984,17 @@ void generic_parser_base::printOptionInfo(const Option &O,
|
|||||||
StringRef Description = getDescription(i);
|
StringRef Description = getDescription(i);
|
||||||
if (!shouldPrintOption(OptionName, Description, O))
|
if (!shouldPrintOption(OptionName, Description, O))
|
||||||
continue;
|
continue;
|
||||||
assert(GlobalWidth >= OptionName.size() + OptionPrefixesSize);
|
size_t FirstLineIndent = OptionName.size() + OptionPrefixesSize;
|
||||||
size_t NumSpaces = GlobalWidth - OptionName.size() - OptionPrefixesSize;
|
|
||||||
outs() << OptionPrefix << OptionName;
|
outs() << OptionPrefix << OptionName;
|
||||||
if (OptionName.empty()) {
|
if (OptionName.empty()) {
|
||||||
outs() << EmptyOption;
|
outs() << EmptyOption;
|
||||||
assert(NumSpaces >= EmptyOption.size());
|
assert(FirstLineIndent >= EmptyOption.size());
|
||||||
NumSpaces -= EmptyOption.size();
|
FirstLineIndent += EmptyOption.size();
|
||||||
}
|
}
|
||||||
if (!Description.empty())
|
if (!Description.empty())
|
||||||
outs().indent(NumSpaces) << ArgHelpPrefix << " " << Description;
|
Option::printEnumValHelpStr(Description, GlobalWidth, FirstLineIndent);
|
||||||
outs() << '\n';
|
else
|
||||||
|
outs() << '\n';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!O.HelpStr.empty())
|
if (!O.HelpStr.empty())
|
||||||
|
@ -1263,6 +1263,28 @@ TEST_F(PrintOptionInfoTest, PrintOptionInfoEmptyValueDescription) {
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(PrintOptionInfoTest, PrintOptionInfoMultilineValueDescription) {
|
||||||
|
std::string Output =
|
||||||
|
runTest(cl::ValueRequired,
|
||||||
|
cl::values(clEnumValN(OptionValue::Val, "v1",
|
||||||
|
"This is the first enum value\n"
|
||||||
|
"which has a really long description\n"
|
||||||
|
"thus it is multi-line."),
|
||||||
|
clEnumValN(OptionValue::Val, "",
|
||||||
|
"This is an unnamed enum value option\n"
|
||||||
|
"Should be indented as well")));
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
EXPECT_EQ(Output,
|
||||||
|
(" --" + Opt + "=<value> - " + HelpText + "\n"
|
||||||
|
" =v1 - This is the first enum value\n"
|
||||||
|
" which has a really long description\n"
|
||||||
|
" thus it is multi-line.\n"
|
||||||
|
" =<empty> - This is an unnamed enum value option\n"
|
||||||
|
" Should be indented as well\n").str());
|
||||||
|
// clang-format on
|
||||||
|
}
|
||||||
|
|
||||||
class GetOptionWidthTest : public ::testing::Test {
|
class GetOptionWidthTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
enum class OptionValue { Val };
|
enum class OptionValue { Val };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user