diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2021-01-10 22:28:38 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2021-01-18 08:20:07 -0500 |
| commit | e4ae41e3a29fc3e4714e1c3f8c9f071768d17b68 (patch) | |
| tree | e784d53c13f454fc960a4f903ac20a34dc08dbaf /src | |
| parent | 3bca0e761597f590fa3b1c6a57ee325e774e3f49 (diff) | |
fixed all commands being legacy
split running command into pre and post organizer
Diffstat (limited to 'src')
| -rw-r--r-- | src/commandline.cpp | 36 | ||||
| -rw-r--r-- | src/commandline.h | 26 | ||||
| -rw-r--r-- | src/main.cpp | 4 |
3 files changed, 40 insertions, 26 deletions
diff --git a/src/commandline.cpp b/src/commandline.cpp index 8c722990..c31b726f 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -49,6 +49,7 @@ std::string table( CommandLine::CommandLine() + : m_command(nullptr) { createOptions(); m_commands.push_back(std::make_unique<ExeCommand>()); @@ -57,7 +58,7 @@ CommandLine::CommandLine() m_commands.push_back(std::make_unique<LaunchCommand>()); } -std::optional<int> CommandLine::run(const std::wstring& line) +std::optional<int> CommandLine::process(const std::wstring& line) { try { @@ -125,8 +126,10 @@ std::optional<int> CommandLine::run(const std::wstring& line) } } - // run the command - return c->run(line, m_vm, opts); + c->process(line, m_vm, opts); + m_command = c.get(); + + return m_command->runPreOrganizer(); } catch(po::error& e) { @@ -201,7 +204,7 @@ std::optional<int> CommandLine::run(const std::wstring& line) } } -std::optional<int> CommandLine::setupCore(OrganizerCore& organizer) const +std::optional<int> CommandLine::run(OrganizerCore& organizer) const { if (m_shortcut.isValid()) { if (m_shortcut.hasExecutable()) { @@ -247,6 +250,8 @@ std::optional<int> CommandLine::setupCore(OrganizerCore& organizer) const QObject::tr("failed to start application: %1").arg(e.what())); return 1; } + } else if (m_command) { + return m_command->runPostOrganizer(); } return {}; @@ -437,7 +442,7 @@ po::positional_options_description Command::positional() const bool Command::legacy() const { - return true; + return false; } std::string Command::getUsageLine() const @@ -463,8 +468,7 @@ po::positional_options_description Command::getPositional() const return {}; } - -std::optional<int> Command::run( +void Command::process( const std::wstring& originalLine, po::variables_map vm, std::vector<std::wstring> untouched) @@ -472,8 +476,16 @@ std::optional<int> Command::run( m_original = originalLine; m_vm = vm; m_untouched = untouched; +} + +std::optional<int> Command::runPreOrganizer() +{ + return {}; +} - return doRun(); +std::optional<int> Command::runPostOrganizer() +{ + return {}; } const std::wstring& Command::originalCmd() const @@ -507,7 +519,7 @@ Command::Meta CrashDumpCommand::meta() const return {"crashdump", "writes a crashdump for a running process of MO"}; } -std::optional<int> CrashDumpCommand::doRun() +std::optional<int> CrashDumpCommand::runPreOrganizer() { env::Console console; @@ -537,7 +549,7 @@ bool LaunchCommand::legacy() const return true; } -std::optional<int> LaunchCommand::doRun() +std::optional<int> LaunchCommand::runPreOrganizer() { // needs at least the working directory and process name if (untouched().size() < 2) { @@ -643,7 +655,7 @@ Command::Meta ExeCommand::meta() const return {"exe", "launches a configured executable"}; } -std::optional<int> ExeCommand::doRun() +std::optional<int> ExeCommand::runPostOrganizer() { const auto exe = vm()["exe-name"].as<std::string>(); const auto args = vm()["arguments"].as<std::string>(); @@ -665,7 +677,7 @@ Command::Meta RunCommand::meta() const return {"run", "launches an arbitrary program"}; } -std::optional<int> RunCommand::doRun() +std::optional<int> RunCommand::runPostOrganizer() { std::cout << "not implemented\n"; return {}; diff --git a/src/commandline.h b/src/commandline.h index 09c1bb8e..14a453b2 100644 --- a/src/commandline.h +++ b/src/commandline.h @@ -50,13 +50,18 @@ public: // virtual bool legacy() const; - // runs this command, eventually calls doRun() // - std::optional<int> run( + // + void process( const std::wstring& originalLine, po::variables_map vm, std::vector<std::wstring> untouched); + // + // + virtual std::optional<int> runPreOrganizer(); + virtual std::optional<int> runPostOrganizer(); + protected: // meta information about this command, returned by derived classes // @@ -86,10 +91,6 @@ protected: // virtual Meta meta() const = 0; - // runs the command - // - virtual std::optional<int> doRun() = 0; - // returns the original command line // @@ -117,7 +118,7 @@ class CrashDumpCommand : public Command protected: po::options_description getVisibleOptions() const override; Meta meta() const override; - std::optional<int> doRun() override; + std::optional<int> runPreOrganizer() override; }; @@ -140,7 +141,7 @@ public: protected: Meta meta() const override; - std::optional<int> doRun() override; + std::optional<int> runPreOrganizer() override; int SpawnWaitProcess(LPCWSTR workingDirectory, LPCWSTR commandLine); @@ -159,7 +160,7 @@ protected: po::options_description getInternalOptions() const override; po::positional_options_description getPositional() const override; Meta meta() const override; - std::optional<int> doRun() override; + std::optional<int> runPostOrganizer() override; }; @@ -170,7 +171,7 @@ class RunCommand : public Command protected: po::options_description getOptions() const; Meta meta() const override; - std::optional<int> doRun() override; + std::optional<int> runPostOrganizer() override; }; @@ -218,14 +219,14 @@ public: // returns an empty optional if execution should continue, or a return code // if MO must quit // - std::optional<int> run(const std::wstring& line); + std::optional<int> process(const std::wstring& line); // handles moshortcut, nxm links and starting processes // // returns an empty optional if execution should continue, or a return code // if MO must quit // - std::optional<int> setupCore(OrganizerCore& organizer) const; + std::optional<int> run(OrganizerCore& organizer) const; // clears parsed options, used when MO is "restarted" so the options aren't @@ -275,6 +276,7 @@ private: std::optional<QString> m_nxmLink; std::optional<QString> m_executable; QStringList m_untouched; + Command* m_command; void createOptions(); std::string more() const; diff --git a/src/main.cpp b/src/main.cpp index 362caaad..f85e13f3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,7 @@ int main(int argc, char *argv[]) setExceptionHandlers(); cl::CommandLine cl; - if (auto r=cl.run(GetCommandLineW())) { + if (auto r=cl.process(GetCommandLineW())) { return *r; } @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) } } - if (auto r=cl.setupCore(app.core())) { + if (auto r=cl.run(app.core())) { return *r; } |
