From a8b6f227302f2264eea38ce95d82ddc5aebf1100 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sat, 18 Jul 2020 13:17:31 -0400 Subject: formatting for command list added empty exe and run commands --- src/commandline.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-) (limited to 'src/commandline.cpp') diff --git a/src/commandline.cpp b/src/commandline.cpp index 11f43dea..819ac1c6 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -5,9 +5,47 @@ namespace cl { +std::string pad_right(std::string s, std::size_t n, char c=' ') +{ + if (s.size() < n) + s.append(n - s.size() , c); + + return s; +} + +std::string table( + const std::vector>& v, + std::size_t indent, std::size_t spacing) +{ + std::size_t longest = 0; + + for (auto&& p : v) + longest = std::max(longest, p.first.size()); + + std::string s; + + for (auto&& p : v) + { + if (!s.empty()) + s += "\n"; + + s += + std::string(indent, ' ') + + pad_right(p.first, longest) + " " + + std::string(spacing, ' ') + + p.second; + } + + return s; + +} + + CommandLine::CommandLine() { createOptions(); + m_commands.push_back(std::make_unique()); + m_commands.push_back(std::make_unique()); m_commands.push_back(std::make_unique()); m_commands.push_back(std::make_unique()); } @@ -156,11 +194,14 @@ std::string CommandLine::usage(const Command* c) const << "\n" << "Commands:\n"; + std::vector> v; for (auto&& c : m_commands) { - oss << " " << c->name() << " " << c->description() << "\n"; + v.push_back({c->name(), c->description()}); } - oss << "\n"; + oss + << table(v, 2, 4) << "\n" + << "\n"; } oss @@ -353,7 +394,7 @@ po::options_description LaunchCommand::doOptions() const Command::Meta LaunchCommand::meta() const { - return {"launch", ""}; + return {"launch", "(internal, do not use)"}; } std::optional LaunchCommand::doRun() @@ -421,4 +462,46 @@ LPCWSTR LaunchCommand::UntouchedCommandLineArguments( return cmd; } + +bool ExeCommand::allow_unregistered() const +{ + return true; +} + +po::options_description ExeCommand::doOptions() const +{ + return {}; +} + +Command::Meta ExeCommand::meta() const +{ + return {"exe", "launches a configured executable"}; +} + +std::optional ExeCommand::doRun() +{ + return {}; +} + + +bool RunCommand::allow_unregistered() const +{ + return true; +} + +po::options_description RunCommand::doOptions() const +{ + return {}; +} + +Command::Meta RunCommand::meta() const +{ + return {"run", "launches an arbitrary program"}; +} + +std::optional RunCommand::doRun() +{ + return {}; +} + } // namespace -- cgit v1.3.1