More colorfull error messages

This commit is contained in:
Robert Bendun 2023-03-04 20:15:58 +01:00
parent 20a6779e2f
commit a2d8f28cd1
2 changed files with 14 additions and 8 deletions

View File

@ -50,7 +50,8 @@ static Requires_Argument show_docs = [](std::string_view builtin) {
std::cout << *maybe_docs << std::endl;
return;
}
std::cerr << "musique: error: cannot find documentation for given builtin" << std::endl;
std::cerr << pretty::begin_error << "musique: error:" << pretty::end;
std::cerr << " cannot find documentation for given builtin" << std::endl;
std::exit(1);
};
@ -223,7 +224,8 @@ std::optional<std::string_view> cmd::accept_commandline_argument(std::vector<cmd
[&state, p](Requires_Argument const& h) {
auto arg = state.value();
if (!arg) {
std::cerr << "musique: error: option " << std::quoted(p.name) << " requires an argument" << std::endl;
std::cerr << pretty::begin_error << "musique: error:" << pretty::end;
std::cerr << " option " << std::quoted(p.name) << " requires an argument" << std::endl;
std::exit(1);
}
h(*arg);
@ -231,7 +233,8 @@ std::optional<std::string_view> cmd::accept_commandline_argument(std::vector<cmd
[&state, &runnables, p](Defines_Code const& h) {
auto arg = state.value();
if (!arg) {
std::cerr << "musique: error: option " << std::quoted(p.name) << " requires an argument" << std::endl;
std::cerr << pretty::begin_error << "musique: error:" << pretty::end;
std::cerr << " option " << std::quoted(p.name) << " requires an argument" << std::endl;
std::exit(1);
}
runnables.push_back(h(*arg));
@ -300,11 +303,11 @@ void cmd::print_close_matches(std::string_view arg)
} else {
std::cout << "The most similar commands are:\n";
for (auto const& name : shown) {
std::cout << " " << name << " - " << find_documentation_for_parameter(name).short_documentation;
std::cout << " " << name << " - " << find_documentation_for_parameter(name).short_documentation << '\n';
}
}
std::cout << "Invoke 'musique help' to read more about available commands\n";
std::cout << "\nInvoke 'musique help' to read more about available commands\n";
}
void cmd::usage()

View File

@ -301,7 +301,8 @@ static std::optional<Error> Main(std::span<char const*> args)
while (args.size()) if (auto failed = cmd::accept_commandline_argument(runnables, args)) {
std::cerr << "musique: error: Failed to recognize parameter " << std::quoted(*failed) << std::endl;
std::cerr << pretty::begin_error << "musique: error:" << pretty::end;
std::cerr << " Failed to recognize parameter " << std::quoted(*failed) << std::endl;
cmd::print_close_matches(args.front());
std::exit(1);
}
@ -320,7 +321,8 @@ static std::optional<Error> Main(std::span<char const*> args)
eternal_sources.emplace_back(std::istreambuf_iterator<char>(std::cin), std::istreambuf_iterator<char>());
} else {
if (not fs::exists(path)) {
std::cerr << "musique: error: couldn't open file: " << path << std::endl;
std::cerr << pretty::begin_error << "musique: error:" << pretty::end;
std::cerr << " couldn't open file: " << path << std::endl;
std::exit(1);
}
std::ifstream source_file{fs::path(path)};
@ -381,7 +383,8 @@ static std::optional<Error> Main(std::span<char const*> args)
if (command.starts_with(':')) {
command.remove_prefix(1);
if (!Try(handle_repl_session_commands(command, runner))) {
std::cerr << "musique: error: unrecognized REPL command '" << command << '\'' << std::endl;
std::cerr << pretty::begin_error << "musique: error:" << pretty::end;
std::cerr << " unrecognized REPL command '" << command << '\'' << std::endl;
}
continue;
}