modules/console: Improve bad command error format; improve subcommands display.

This commit is contained in:
Jason Volk 2023-02-22 12:37:17 -08:00
parent cd6eb8ed0a
commit 314dacdce0
2 changed files with 30 additions and 12 deletions

View File

@ -278,7 +278,15 @@ catch(const std::out_of_range &e)
}
catch(const bad_command &e)
{
std::cerr << "Bad command or file name: " << e.what() << std::endl;
const ircd::string_view what(e.what());
std::cerr << "\nBad command";
if(what)
std::cerr << " :" << what;
else
std::cerr << '.';
std::cerr << std::endl;
return true;
}
catch(const http::error &e)

View File

@ -410,7 +410,7 @@ console_cmd__help(opt &out, const string_view &line)
find_cmd(line)
};
if(cmd)
if(cmd && (false))
{
out << "No help available for '" << cmd->name << "'."
<< std::endl;
@ -418,15 +418,13 @@ console_cmd__help(opt &out, const string_view &line)
//TODO: help string symbol map
}
out << "\nSubcommands available:\n"
<< std::endl;
const size_t elems
{
std::min(token_count(line, ' '), cmd::MAX_DEPTH)
};
size_t num(0);
std::vector<string_view> subs;
subs.reserve(128);
for(size_t e(elems+1); e > 0; --e)
{
const auto name
@ -461,17 +459,29 @@ console_cmd__help(opt &out, const string_view &line)
e > 1? tokens_after(prefix, ' ', e - 2) : prefix
};
if(empty(suffix))
continue;
out << std::left << std::setw(20) << suffix;
if(++num % 4 == 0)
out << std::endl;
if(!empty(suffix))
subs.emplace_back(suffix);
}
break;
}
if(!subs.empty())
{
out << "\nSubcommands available:\n" << std::endl;
size_t num(0);
for(size_t i(0); i < subs.size(); ++i)
{
out << std::left << std::setw(20) << subs.at(i);
if(++num % 4 == 0)
out << '\n';
}
if(num % 4 != 0)
out << std::endl;
}
return true;
}