diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2020-07-18 13:17:31 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2020-11-03 11:39:02 -0500 |
| commit | a8b6f227302f2264eea38ce95d82ddc5aebf1100 (patch) | |
| tree | 7f78fd7aae719c14a43cf01353f80e623a924667 /src | |
| parent | f4ca82f798fa7e456bb904ed301ddc17db5410c8 (diff) | |
formatting for command list
added empty exe and run commands
Diffstat (limited to 'src')
| -rw-r--r-- | src/commandline.cpp | 89 | ||||
| -rw-r--r-- | src/commandline.h | 24 |
2 files changed, 110 insertions, 3 deletions
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<std::pair<std::string, std::string>>& 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<ExeCommand>()); + m_commands.push_back(std::make_unique<RunCommand>()); m_commands.push_back(std::make_unique<CrashDumpCommand>()); m_commands.push_back(std::make_unique<LaunchCommand>()); } @@ -156,11 +194,14 @@ std::string CommandLine::usage(const Command* c) const << "\n" << "Commands:\n"; + std::vector<std::pair<std::string, std::string>> 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<int> 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<int> 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<int> RunCommand::doRun() +{ + return {}; +} + } // namespace diff --git a/src/commandline.h b/src/commandline.h index ecc19c89..f633518b 100644 --- a/src/commandline.h +++ b/src/commandline.h @@ -87,6 +87,30 @@ protected: }; +class ExeCommand : public Command +{ +public: + bool allow_unregistered() const override; + +protected: + po::options_description doOptions() const; + Meta meta() const override; + std::optional<int> doRun() override; +}; + + +class RunCommand : public Command +{ +public: + bool allow_unregistered() const override; + +protected: + po::options_description doOptions() const; + Meta meta() const override; + std::optional<int> doRun() override; +}; + + class CommandLine { public: |
