From 181acfe832bef26228e33ac3a021d39528b1a4a9 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sun, 17 Jan 2021 18:29:17 -0500 Subject: renamed Refresh to TriggerRefresh, added WaitForRefresh removed duplicate refreshDirectoryStructure() call that could never work added --logs to output logs to stdout, added final "mod organizer done" log added -i with no arguments to output the current instance name `run -e` now does an additional, case insensitive check for names fixed error being output along with --help --- src/commandline.cpp | 100 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 83 insertions(+), 17 deletions(-) (limited to 'src/commandline.cpp') diff --git a/src/commandline.cpp b/src/commandline.cpp index 1b7c7b0e..97d54b92 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -3,6 +3,7 @@ #include "organizercore.h" #include "instancemanager.h" #include "multiprocess.h" +#include "loglist.h" #include "shared/util.h" #include "shared/error_report.h" #include "shared/appconfig.h" @@ -124,19 +125,22 @@ std::optional CommandLine::process(const std::wstring& line) parsed = parser.run(); po::store(parsed, m_vm); - po::notify(m_vm); if (m_vm.count("help")) { env::Console console; std::cout << usage(c.get()) << "\n"; return 0; } + + // must be below the help check because it throws if required + // positional arguments are missing + po::notify(m_vm); } c->set(line, m_vm, opts); m_command = c.get(); - return m_command->runEarly(); + return runEarly(); } catch(po::error& e) { @@ -164,6 +168,7 @@ std::optional CommandLine::process(const std::wstring& line) return 0; } + if (!opts.empty()) { const auto qs = QString::fromStdWString(opts[0]); @@ -226,6 +231,42 @@ bool CommandLine::forwardToPrimary(MOMultiProcess& multiProcess) return true; } +std::optional CommandLine::runEarly() +{ + if (m_vm.count("logs")) { + // in loglist.h + logToStdout(true); + } + + if (m_command) { + return m_command->runEarly(); + } + + return {}; +} + +std::optional CommandLine::runPostApplication(MOApplication& a) +{ + // handle -i with no arguments + if (m_vm.count("instance") && m_vm["instance"].as() == "") { + env::Console c; + + if (auto i=InstanceManager::singleton().currentInstance()) { + std::cout << i->name().toStdString() << "\n"; + } else { + std::cout << "no instance configured\n"; + } + + return 0; + } + + if (m_command) { + return m_command->runPostApplication(a); + } + + return {}; +} + std::optional CommandLine::runPostMultiProcess(MOMultiProcess& mp) { if (m_command) { @@ -244,7 +285,7 @@ std::optional CommandLine::runPostOrganizer(OrganizerCore& core) // PreventExit will do that core.processRunner() .setFromShortcut(m_shortcut) - .setWaitForCompletion(ProcessRunner::ForceWait, UILocker::PreventExit) + .setWaitForCompletion(ProcessRunner::ForCommandLine, UILocker::PreventExit) .run(); return 0; @@ -270,7 +311,7 @@ std::optional CommandLine::runPostOrganizer(OrganizerCore& core) // PreventExit will do that core.processRunner() .setFromFileOrExecutable(exeName, m_untouched) - .setWaitForCompletion(ProcessRunner::ForceWait, UILocker::PreventExit) + .setWaitForCompletion(ProcessRunner::ForCommandLine, UILocker::PreventExit) .run(); return 0; @@ -298,10 +339,23 @@ void CommandLine::clear() void CommandLine::createOptions() { m_visibleOptions.add_options() - ("help", "show this message") - ("multiple", "allow multiple MO processes to run; see below") - ("instance,i", po::value(), "use the given instance (defaults to last used)") - ("profile,p", po::value(), "use the given profile (defaults to last used)"); + ("help", + "show this message") + + ("multiple", + "allow multiple MO processes to run; see below") + + ("logs", + "duplicates the logs to stdout") + + ("instance,i", + po::value()->implicit_value(""), + "use the given instance (defaults to last used)") + + ("profile,p", + po::value(), + "use the given profile (defaults to last used)"); + po::options_description options; options.add_options() @@ -530,9 +584,9 @@ std::optional Command::runEarly() return {}; } -bool Command::canForwardToPrimary() const +std::optional Command::runPostApplication(MOApplication& a) { - return false; + return {}; } std::optional Command::runPostMultiProcess(MOMultiProcess&) @@ -545,6 +599,11 @@ std::optional Command::runPostOrganizer(OrganizerCore&) return {}; } +bool Command::canForwardToPrimary() const +{ + return false; +} + const std::wstring& Command::originalCmd() const { return m_original; @@ -740,14 +799,21 @@ std::optional RunCommand::runPostOrganizer(OrganizerCore& core) if (vm()["executable"].as()) { const auto& exes = *core.executablesList(); - auto itor = exes.find(program); + // case sensitive + auto itor = exes.find(program, true); if (itor == exes.end()) { - MOShared::criticalOnTop( - QObject::tr("Executable '%1' not found in instance '%2'.") - .arg(program) - .arg(InstanceManager::singleton().currentInstance()->name())); + // case insensitive + itor = exes.find(program, false); - return 1; + if (itor == exes.end()) { + // not found + MOShared::criticalOnTop( + QObject::tr("Executable '%1' not found in instance '%2'.") + .arg(program) + .arg(InstanceManager::singleton().currentInstance()->name())); + + return 1; + } } p.setFromExecutable(*itor); @@ -763,7 +829,7 @@ std::optional RunCommand::runPostOrganizer(OrganizerCore& core) p.setCurrentDirectory(QString::fromStdString(vm()["cwd"].as())); } - p.setWaitForCompletion(ProcessRunner::ForceWait, UILocker::PreventExit); + p.setWaitForCompletion(ProcessRunner::ForCommandLine, UILocker::PreventExit); const auto r = p.run(); if (r == ProcessRunner::Error) { -- cgit v1.3.1