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
+7 -5
View File
@@ -84,19 +84,21 @@ auto Options::Build(CommandLine::CommandBuilder& b) -> void {
auto Driver::RunCommand(llvm::ArrayRef<llvm::StringRef> args) -> DriverResult {
if (driver_env_.installation->error()) {
llvm::errs() << "error: " << *driver_env_.installation->error() << "\n";
driver_env_.error_stream << "error: " << *driver_env_.installation->error()
<< "\n";
return {.success = false};
}
Options options;
CommandLine::ParseResult result = CommandLine::Parse(
args, driver_env_.output_stream, driver_env_.error_stream, Options::Info,
ErrorOr<CommandLine::ParseResult> result = CommandLine::Parse(
args, driver_env_.output_stream, Options::Info,
[&](CommandLine::CommandBuilder& b) { options.Build(b); });
if (result == CommandLine::ParseResult::Error) {
if (!result.ok()) {
driver_env_.error_stream << "error: " << result.error() << "\n";
return {.success = false};
} else if (result == CommandLine::ParseResult::MetaSuccess) {
} else if (*result == CommandLine::ParseResult::MetaSuccess) {
return {.success = true};
}