diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2021-01-11 00:01:50 -0500 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2021-01-18 08:20:08 -0500 |
| commit | 7e8018481284ff9ac1915425e9ed94d532ab33db (patch) | |
| tree | 7fc710d0b769b8454436cb822a6f9c64eddf0c32 /src | |
| parent | aa7a552654ba3b218b87397dedc9e5a66d2f6701 (diff) | |
merged exe and run commands, added -e flag instead
added dialog when selected profile doesn't exist, this can happen with -p on the command line
Diffstat (limited to 'src')
| -rw-r--r-- | src/commandline.cpp | 92 | ||||
| -rw-r--r-- | src/commandline.h | 15 | ||||
| -rw-r--r-- | src/organizercore.cpp | 5 |
3 files changed, 53 insertions, 59 deletions
diff --git a/src/commandline.cpp b/src/commandline.cpp index 596ece68..fd0f6cb5 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -1,6 +1,7 @@ #include "commandline.h" #include "env.h" #include "organizercore.h" +#include "instancemanager.h" #include "shared/util.h" #include "shared/error_report.h" #include <log.h> @@ -53,7 +54,6 @@ CommandLine::CommandLine() : m_command(nullptr) { 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>()); @@ -616,64 +616,74 @@ LPCWSTR LaunchCommand::UntouchedCommandLineArguments( } -std::string ExeCommand::getUsageLine() const +std::string RunCommand::getUsageLine() const { - return "[options] exe-name"; + return "[options] program"; } -po::options_description ExeCommand::getVisibleOptions() const +po::options_description RunCommand::getVisibleOptions() const { po::options_description d; d.add_options() - ("arguments,a", po::value<std::string>()->default_value(""), "override arguments") - ("cwd,c", po::value<std::string>()->default_value(""), "override working directory"); + ("executable,e", po::value<bool>()->default_value(false)->zero_tokens(), "the program is a configured executable name") + ("arguments,a", po::value<std::string>(), "override arguments") + ("cwd,c", po::value<std::string>(), "override working directory"); return d; } -po::options_description ExeCommand::getInternalOptions() const +po::options_description RunCommand::getInternalOptions() const { po::options_description d; d.add_options() - ("exe-name", po::value<std::string>()->required(), "executable name"); + ("program", po::value<std::string>()->required(), "program or executable name"); return d; } -po::positional_options_description ExeCommand::getPositional() const +po::positional_options_description RunCommand::getPositional() const { po::positional_options_description d; - d.add("exe-name", 1); + d.add("program", 1); return d; } -Command::Meta ExeCommand::meta() const +Command::Meta RunCommand::meta() const { - return {"exe", "launches a configured executable"}; + return {"run", "runs a program, file or a configured executable"}; } -std::optional<int> ExeCommand::runPostOrganizer(OrganizerCore& organizer) +std::optional<int> RunCommand::runPostOrganizer(OrganizerCore& organizer) { - const auto exe = QString::fromStdString(vm()["exe-name"].as<std::string>()); - - const auto& exes = *organizer.executablesList(); - - auto itor = exes.find(exe); - if (itor == exes.end()) { - MOShared::criticalOnTop(QObject::tr("Executable '%1' not found.").arg(exe)); - return 1; - } + const auto program = QString::fromStdString(vm()["program"].as<std::string>()); - try { + try + { // make sure MO doesn't exit even if locking is disabled, ForceWait and // PreventExit will do that auto p = organizer.processRunner(); - p.setFromExecutable(*itor); + if (vm()["executable"].as<bool>()) { + const auto& exes = *organizer.executablesList(); + + auto itor = exes.find(program); + if (itor == exes.end()) { + MOShared::criticalOnTop( + QObject::tr("Executable '%1' not found in instance '%2'.") + .arg(program) + .arg(InstanceManager::singleton().currentInstance()->name())); + + return 1; + } + + p.setFromExecutable(*itor); + } else { + p.setFromFile(nullptr, QFileInfo(program)); + } if (vm().count("arguments")) { p.setArguments(QString::fromStdString(vm()["arguments"].as<std::string>())); @@ -684,34 +694,24 @@ std::optional<int> ExeCommand::runPostOrganizer(OrganizerCore& organizer) } p.setWaitForCompletion(ProcessRunner::ForceWait, UILocker::PreventExit); - p.run(); + + const auto r = p.run(); + if (r == ProcessRunner::Error) { + MOShared::criticalOnTop( + QObject::tr("Failed to run '%1'. The logs might have more information.").arg(program)); + + return 1; + } return 0; } catch (const std::exception &e) { - reportError( - QObject::tr("failed to start shortcut: %1").arg(e.what())); + MOShared::criticalOnTop( + QObject::tr("Failed to run '%1'. The logs might have more information. %2") + .arg(program).arg(e.what())); + return 1; } - - return 0; -} - - -po::options_description RunCommand::getOptions() const -{ - return {}; -} - -Command::Meta RunCommand::meta() const -{ - return {"run", "launches an arbitrary program"}; -} - -std::optional<int> RunCommand::runPostOrganizer(OrganizerCore&) -{ - std::cout << "not implemented\n"; - return {}; } } // namespace diff --git a/src/commandline.h b/src/commandline.h index d2cfbfa1..d0d62a72 100644 --- a/src/commandline.h +++ b/src/commandline.h @@ -150,9 +150,9 @@ protected: }; -// runs a configured executable +// runs a program or an executable // -class ExeCommand : public Command +class RunCommand : public Command { protected: std::string getUsageLine() const override; @@ -164,17 +164,6 @@ protected: }; -// runs an arbitrary executable -// -class RunCommand : public Command -{ -protected: - po::options_description getOptions() const; - Meta meta() const override; - std::optional<int> runPostOrganizer(OrganizerCore& organizer) override; -}; - - // parses the command line and runs any given command // // the command line used to support a few commands but with no real conventions; diff --git a/src/organizercore.cpp b/src/organizercore.cpp index e95aa565..5d079f89 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -37,6 +37,7 @@ #include "shared/filesorigin.h" #include "shared/fileentry.h" #include "shared/util.h" +#include "shared/error_report.h" #include <QApplication> #include <QCoreApplication> @@ -579,6 +580,10 @@ void OrganizerCore::setCurrentProfile(const QString &profileName) profileBaseDir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot).at(0)); log::error("picked profile '{}' instead", QDir(profileDir).dirName()); + + MOShared::criticalOnTop( + tr("The selected profile '%1' does not exist. The profile '%2' will be used instead") + .arg(profileName).arg(QDir(profileDir).dirName())); } // Keep the old profile to emit signal-changed: |
