summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commandline.cpp8
-rw-r--r--src/commandline.h75
2 files changed, 65 insertions, 18 deletions
diff --git a/src/commandline.cpp b/src/commandline.cpp
index 10d0f1fd..1b7c7b0e 100644
--- a/src/commandline.cpp
+++ b/src/commandline.cpp
@@ -133,7 +133,7 @@ std::optional<int> CommandLine::process(const std::wstring& line)
}
}
- c->process(line, m_vm, opts);
+ c->set(line, m_vm, opts);
m_command = c.get();
return m_command->runEarly();
@@ -228,6 +228,10 @@ bool CommandLine::forwardToPrimary(MOMultiProcess& multiProcess)
std::optional<int> CommandLine::runPostMultiProcess(MOMultiProcess& mp)
{
+ if (m_command) {
+ return m_command->runPostMultiProcess(mp);
+ }
+
return {};
}
@@ -511,7 +515,7 @@ po::positional_options_description Command::getPositional() const
return {};
}
-void Command::process(
+void Command::set(
const std::wstring& originalLine,
po::variables_map vm,
std::vector<std::wstring> untouched)
diff --git a/src/commandline.h b/src/commandline.h
index a92ef094..5dcb8871 100644
--- a/src/commandline.h
+++ b/src/commandline.h
@@ -55,20 +55,43 @@ public:
//
virtual bool legacy() const;
+ // remembers the given values
//
- //
- void process(
+ void set(
const std::wstring& originalLine,
po::variables_map vm,
std::vector<std::wstring> untouched);
- //
+
+ // called as soon as the command line has been parsed; return something to
+ // exit immediately
//
virtual std::optional<int> runEarly();
- virtual bool canForwardToPrimary() const;
+
+ // called as soon as the multi process checks have confirmed that this is
+ // a primary instance; return something to exit immediately
+ //
virtual std::optional<int> runPostMultiProcess(MOMultiProcess& mp);
+
+ // called after the OrganizerCore has been initialized; return something to
+ // exit immediatley
+ //
virtual std::optional<int> runPostOrganizer(OrganizerCore& core);
+ // whether this command can be forwarded to the primary instance if one is
+ // already running
+ //
+ // if an instance is already running and this returns true, the whole command
+ // line is sent as a message to the primary instance, which will construct a
+ // new CommandLine and call runPostOrganizer() with it
+ //
+ // if an instance is already running and this returns false, the "an instance
+ // is already running" error dialog will be shown
+ //
+ // if this is the primary instance, this function is not called
+ //
+ virtual bool canForwardToPrimary() const;
+
protected:
// meta information about this command, returned by derived classes
//
@@ -81,6 +104,12 @@ protected:
std::string usage, std::string more);
};
+
+ // meta
+ //
+ virtual Meta meta() const = 0;
+
+
// returns visible options specific to this command
//
virtual po::options_description getVisibleOptions() const;
@@ -94,11 +123,6 @@ protected:
virtual po::positional_options_description getPositional() const;
- // meta
- //
- virtual Meta meta() const = 0;
-
-
// returns the original command line
//
const std::wstring& originalCmd() const;
@@ -238,23 +262,41 @@ class CommandLine
public:
CommandLine();
- // parses the given command line and executes the appropriate command, if
- // any
+ // parses the given command line and calls runEarly() on the appropriate
+ // command, if any
//
// returns an empty optional if execution should continue, or a return code
// if MO must quit
//
std::optional<int> process(const std::wstring& line);
- // handles moshortcut, nxm links and starting processes
+ // calls Command::runPostMultiProcess() on the command, if any
//
- // returns an empty optional if execution should continue, or a return code
- // if MO must quit
- //
- bool forwardToPrimary(MOMultiProcess& multiProcess);
std::optional<int> runPostMultiProcess(MOMultiProcess& mp);
+
+ // calls Command::runPostOrganizer() on the command, if any
+ //
+ // if MO wasn't invoked with a valid command, this also handles moshortcut,
+ // nxm links and starting processes
+ //
std::optional<int> runPostOrganizer(OrganizerCore& core);
+ // called when this instance is not the primary one
+ //
+ // if a command was executed and the command returns true for
+ // canForwardToPrimary(), this forwards the command line as an external
+ // message and returns true
+ //
+ // if the command returns false for canForwardToPrimary(), returns false
+ //
+ // if there was no valid command on the command line, this also forwards
+ // moshortcut and nxm links
+ //
+ // if there was no command, moshortcut or nxm links, this returns false, which
+ // will end up displaying an error message about an instance already running
+ //
+ bool forwardToPrimary(MOMultiProcess& multiProcess);
+
// clears parsed options, used when MO is "restarted" so the options aren't
// processed again
@@ -287,6 +329,7 @@ public:
std::optional<QString> nxmLink() const;
// returns the executable/binary, if any
+ //
std::optional<QString> executable() const;
// returns the list of arguments, excluding moshortcut or executable name;