More colorfull error messages
This commit is contained in:
parent
20a6779e2f
commit
a2d8f28cd1
@ -50,7 +50,8 @@ static Requires_Argument show_docs = [](std::string_view builtin) {
|
|||||||
std::cout << *maybe_docs << std::endl;
|
std::cout << *maybe_docs << std::endl;
|
||||||
return;
|
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);
|
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) {
|
[&state, p](Requires_Argument const& h) {
|
||||||
auto arg = state.value();
|
auto arg = state.value();
|
||||||
if (!arg) {
|
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);
|
std::exit(1);
|
||||||
}
|
}
|
||||||
h(*arg);
|
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) {
|
[&state, &runnables, p](Defines_Code const& h) {
|
||||||
auto arg = state.value();
|
auto arg = state.value();
|
||||||
if (!arg) {
|
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);
|
std::exit(1);
|
||||||
}
|
}
|
||||||
runnables.push_back(h(*arg));
|
runnables.push_back(h(*arg));
|
||||||
@ -300,11 +303,11 @@ void cmd::print_close_matches(std::string_view arg)
|
|||||||
} else {
|
} else {
|
||||||
std::cout << "The most similar commands are:\n";
|
std::cout << "The most similar commands are:\n";
|
||||||
for (auto const& name : shown) {
|
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()
|
void cmd::usage()
|
||||||
|
@ -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)) {
|
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());
|
cmd::print_close_matches(args.front());
|
||||||
std::exit(1);
|
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>());
|
eternal_sources.emplace_back(std::istreambuf_iterator<char>(std::cin), std::istreambuf_iterator<char>());
|
||||||
} else {
|
} else {
|
||||||
if (not fs::exists(path)) {
|
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::exit(1);
|
||||||
}
|
}
|
||||||
std::ifstream source_file{fs::path(path)};
|
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(':')) {
|
if (command.starts_with(':')) {
|
||||||
command.remove_prefix(1);
|
command.remove_prefix(1);
|
||||||
if (!Try(handle_repl_session_commands(command, runner))) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user