From 314dacdce0cb9f1e3dd842021f846b82503c78c0 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 22 Feb 2023 12:37:17 -0800 Subject: [PATCH] modules/console: Improve bad command error format; improve subcommands display. --- construct/console.cc | 10 +++++++++- modules/console.cc | 32 +++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/construct/console.cc b/construct/console.cc index c18bc2b74..6b880300e 100644 --- a/construct/console.cc +++ b/construct/console.cc @@ -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) diff --git a/modules/console.cc b/modules/console.cc index 634303717..5ea5953c6 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -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 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; }