diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2021-01-11 01:43:48 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2021-01-18 08:20:08 -0500 |
| commit | 65a9e51e0ed8169bbf2a176ce147ca5a9ae09a6f (patch) | |
| tree | 9c7e0959f711ecbb90a3b778f22778bfa1d8a094 /src | |
| parent | 09eb507ddad0d164a39d72c5c121d332966ef462 (diff) | |
added refresh command
added more help for run
Diffstat (limited to 'src')
| -rw-r--r-- | src/commandline.cpp | 75 | ||||
| -rw-r--r-- | src/commandline.h | 26 |
2 files changed, 90 insertions, 11 deletions
diff --git a/src/commandline.cpp b/src/commandline.cpp index b6210463..01ee866e 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -60,6 +60,7 @@ CommandLine::CommandLine() add< RunCommand, ReloadPluginCommand, + RefreshCommand, CrashDumpCommand, LaunchCommand>(); } @@ -322,8 +323,14 @@ std::string CommandLine::usage(const Command* c) const if (c) { oss - << " ModOrganizer.exe [global-options] " << c->usageLine() << "\n" - << "\n" + << " ModOrganizer.exe [global-options] " << c->usageLine() << "\n\n"; + + const std::string more = c->moreInfo(); + if (!more.empty()) { + oss << more << "\n\n"; + } + + oss << "Command options:\n" << c->visibleOptions() << "\n"; } else { @@ -335,6 +342,11 @@ std::string CommandLine::usage(const Command* c) const // name and description for all commands std::vector<std::pair<std::string, std::string>> v; for (auto&& c : m_commands) { + // don't show legacy commands + if (c->legacy()) { + continue; + } + v.push_back({c->name(), c->description()}); } @@ -441,6 +453,11 @@ std::string Command::usageLine() const return name() + " " + getUsageLine(); } +std::string Command::moreInfo() const +{ + return getMoreInfo(); +} + po::options_description Command::allOptions() const { po::options_description d; @@ -476,6 +493,11 @@ std::string Command::getUsageLine() const return "[options]"; } +std::string Command::getMoreInfo() const +{ + return ""; +} + po::options_description Command::getVisibleOptions() const { // no-op @@ -653,7 +675,16 @@ LPCWSTR LaunchCommand::UntouchedCommandLineArguments( std::string RunCommand::getUsageLine() const { - return "[options] program"; + return "[options] NAME"; +} + +std::string RunCommand::getMoreInfo() const +{ + return + "Runs a program or a file with the virtual filesystem. If NAME is a path\n" + "to a non-executable file, the program that is associated with the file\n" + "extension is run instead. With -e, NAME must refer to the name of an\n" + "executable in the instance (for example, \"SKSE\")."; } po::options_description RunCommand::getVisibleOptions() const @@ -661,7 +692,7 @@ po::options_description RunCommand::getVisibleOptions() const po::options_description d; d.add_options() - ("executable,e", po::value<bool>()->default_value(false)->zero_tokens(), "the program is a configured executable name") + ("executable,e", po::value<bool>()->default_value(false)->zero_tokens(), "the name is a configured executable name") ("arguments,a", po::value<std::string>(), "override arguments") ("cwd,c", po::value<std::string>(), "override working directory"); @@ -673,7 +704,7 @@ po::options_description RunCommand::getInternalOptions() const po::options_description d; d.add_options() - ("program", po::value<std::string>()->required(), "program or executable name"); + ("NAME", po::value<std::string>()->required(), "program or executable name"); return d; } @@ -682,7 +713,7 @@ po::positional_options_description RunCommand::getPositional() const { po::positional_options_description d; - d.add("program", 1); + d.add("NAME", 1); return d; } @@ -692,9 +723,14 @@ Command::Meta RunCommand::meta() const return {"run", "runs a program, file or a configured executable"}; } +bool RunCommand::canForwardToPrimary() const +{ + return true; +} + std::optional<int> RunCommand::runPostOrganizer(OrganizerCore& core) { - const auto program = QString::fromStdString(vm()["program"].as<std::string>()); + const auto program = QString::fromStdString(vm()["NAME"].as<std::string>()); try { @@ -753,7 +789,7 @@ std::optional<int> RunCommand::runPostOrganizer(OrganizerCore& core) std::string ReloadPluginCommand::getUsageLine() const { - return "plugin-name"; + return "PLUGIN"; } po::options_description ReloadPluginCommand::getInternalOptions() const @@ -761,7 +797,7 @@ po::options_description ReloadPluginCommand::getInternalOptions() const po::options_description d; d.add_options() - ("plugin-name", po::value<std::string>()->required(), "plugin name"); + ("PLUGIN", po::value<std::string>()->required(), "plugin name"); return d; } @@ -770,7 +806,7 @@ po::positional_options_description ReloadPluginCommand::getPositional() const { po::positional_options_description d; - d.add("plugin-name", 1); + d.add("PLUGIN", 1); return d; } @@ -787,7 +823,7 @@ bool ReloadPluginCommand::canForwardToPrimary() const std::optional<int> ReloadPluginCommand::runPostOrganizer(OrganizerCore& core) { - const QString name = QString::fromStdString(vm()["plugin-name"].as<std::string>()); + const QString name = QString::fromStdString(vm()["PLUGIN"].as<std::string>()); QString filepath = QDir( qApp->applicationDirPath() + "/" + @@ -800,4 +836,21 @@ std::optional<int> ReloadPluginCommand::runPostOrganizer(OrganizerCore& core) return {}; } + +Command::Meta RefreshCommand::meta() const +{ + return {"refresh", "refreshes MO (same as F5)"}; +} + +bool RefreshCommand::canForwardToPrimary() const +{ + return true; +} + +std::optional<int> RefreshCommand::runPostOrganizer(OrganizerCore& core) +{ + core.refresh(); + return {}; +} + } // namespace diff --git a/src/commandline.h b/src/commandline.h index 6f96d724..9cad4c71 100644 --- a/src/commandline.h +++ b/src/commandline.h @@ -32,6 +32,10 @@ public: // std::string usageLine() const; + // shown after the usage line + // + std::string moreInfo() const; + // returns all options for this command, including hidden ones; used to parse // the command line @@ -77,6 +81,10 @@ protected: // virtual std::string getUsageLine() const; + // returns text shown after the usage line + // + virtual std::string getMoreInfo() const; + // returns visible options specific to this command // virtual po::options_description getVisibleOptions() const; @@ -159,10 +167,14 @@ class RunCommand : public Command { protected: std::string getUsageLine() const override; + std::string getMoreInfo() const override; + po::options_description getVisibleOptions() const override; po::options_description getInternalOptions() const override; po::positional_options_description getPositional() const override; Meta meta() const override; + + bool canForwardToPrimary() const override; std::optional<int> runPostOrganizer(OrganizerCore& core) override; }; @@ -173,14 +185,28 @@ class ReloadPluginCommand : public Command { protected: std::string getUsageLine() const override; + po::options_description getInternalOptions() const override; po::positional_options_description getPositional() const override; Meta meta() const override; + bool canForwardToPrimary() const override; std::optional<int> runPostOrganizer(OrganizerCore& core) override; }; +// refreshes mo +// +class RefreshCommand : public Command +{ +protected: + Meta meta() const override; + bool canForwardToPrimary() const override; + std::optional<int> runPostOrganizer(OrganizerCore& core) override; +}; + + + // parses the command line and runs any given command // // the command line used to support a few commands but with no real conventions; |
