Refactor command line errors to mirror diagnostic style (#4568)

This changes to an `Error` return to let the driver do the "error: "
prefix, except for one case with `help` that needs more work to change
(I'm not planning on picking up that TODO). It also changes
capitalization, backtick use, and a few minor punctuation things to try
to better match the diagnostic style.

This also adds `Error` matchers so that the changes to command line
testing are clearer.
This commit is contained in:
Jon Ross-Perkins
2024-11-26 19:22:05 +00:00
committed by GitHub
parent f921923b4b
commit 5880954041
11 changed files with 475 additions and 372 deletions
+5 -5
View File
@@ -54,9 +54,8 @@ auto Run(llvm::ArrayRef<llvm::StringRef> args) -> bool {
int lines = 10'000;
SourceGen::Language language;
CommandLine::ParseResult parsed_args = CommandLine::Parse(
args, llvm::outs(), llvm::errs(), Info,
[&](CommandLine::CommandBuilder& b) {
auto parse_result = CommandLine::Parse(
args, llvm::outs(), Info, [&](CommandLine::CommandBuilder& b) {
b.AddStringOption(OutputArgInfo,
[&](auto& arg_b) { arg_b.Set(&output_filename); });
b.AddIntegerOption(LinesArgInfo,
@@ -74,9 +73,10 @@ auto Run(llvm::ArrayRef<llvm::StringRef> args) -> bool {
// No-op action as there is only one operation for this command.
b.Do([] {});
});
if (parsed_args == CommandLine::ParseResult::Error) {
if (!parse_result.ok()) {
llvm::errs() << "error: " << *parse_result << "\n";
return false;
} else if (parsed_args == CommandLine::ParseResult::MetaSuccess) {
} else if (*parse_result == CommandLine::ParseResult::MetaSuccess) {
// Fully handled by the CLI library.
return true;
}