diff --git a/src/launch/command.cpp b/src/launch/command.cpp index 9e1a45b..6ec1a3f 100644 --- a/src/launch/command.cpp +++ b/src/launch/command.cpp @@ -164,7 +164,12 @@ void sortInstances(QVector& list, bool newestFirst) { }); }; -int selectInstance(CommandState& cmd, InstanceLockInfo* instance, bool deadFallback = false) { +int selectInstance( + CommandState& cmd, + InstanceLockInfo* instance, + bool deadFallback = false, + bool logHelp = true +) { auto* basePath = QsPaths::instance()->baseRunDir(); if (!basePath) return -1; @@ -173,7 +178,7 @@ int selectInstance(CommandState& cmd, InstanceLockInfo* instance, bool deadFallb if (cmd.instance.pid != -1) { path = QDir(basePath->filePath("by-pid")).filePath(QString::number(cmd.instance.pid)); if (!QsPaths::checkLock(path, instance, deadFallback)) { - qCInfo(logBare) << "No instance found for pid" << cmd.instance.pid; + if (logHelp) qCInfo(logBare) << "No instance found for pid" << cmd.instance.pid; return -1; } } else if (!cmd.instance.id->isEmpty()) { @@ -196,39 +201,43 @@ int selectInstance(CommandState& cmd, InstanceLockInfo* instance, bool deadFallb auto instances = liveInstances.isEmpty() && deadFallback ? deadInstances : liveInstances; if (instances.isEmpty()) { - if (!mismatchedInstances.isEmpty()) { - qCInfo(logBare) << "No running instances on the current display" << getDisplayConnection() - << "start with" << *cmd.instance.id; + if (logHelp) { + if (!mismatchedInstances.isEmpty()) { + qCInfo(logBare) << "No running instances on the current display" << getDisplayConnection() + << "start with" << *cmd.instance.id; - qCInfo(logBare) << "Some instances on other displays match:"; + qCInfo(logBare) << "Some instances on other displays match:"; - for (auto& instance: mismatchedInstances) { - qCInfo(logBare).noquote().nospace() - << " - " << instance.instance.instanceId << " (" << instance.instance.display << ')'; + for (auto& instance: mismatchedInstances) { + qCInfo(logBare).noquote().nospace() << " - " << instance.instance.instanceId << " (" + << instance.instance.display << ')'; + } } - } - if (deadFallback) { - qCInfo(logBare) << "No instances start with" << *cmd.instance.id; - } else { - qCInfo(logBare) << "No running instances start with" << *cmd.instance.id; + if (deadFallback) { + qCInfo(logBare) << "No instances start with" << *cmd.instance.id; + } else { + qCInfo(logBare) << "No running instances start with" << *cmd.instance.id; - if (!deadInstances.isEmpty()) { - qCInfo(logBare) << "Some dead instances match:"; + if (!deadInstances.isEmpty()) { + qCInfo(logBare) << "Some dead instances match:"; - for (auto& instance: deadInstances) { - qCInfo(logBare).noquote() << " -" << instance.instance.instanceId; + for (auto& instance: deadInstances) { + qCInfo(logBare).noquote() << " -" << instance.instance.instanceId; + } } } } return -1; } else if (instances.length() != 1) { - qCInfo(logBare) << "More than one instance starts with" << *cmd.instance.id; + if (logHelp) { + qCInfo(logBare) << "More than one instance starts with" << *cmd.instance.id; - for (auto& instance: instances) { - qCInfo(logBare).noquote() << " -" << instance.instance.instanceId - << (instance.pid == -1 ? "(dead)" : ""); + for (auto& instance: instances) { + qCInfo(logBare).noquote() + << " -" << instance.instance.instanceId << (instance.pid == -1 ? "(dead)" : ""); + } } return -1; @@ -259,26 +268,29 @@ int selectInstance(CommandState& cmd, InstanceLockInfo* instance, bool deadFallb ); if (instances.isEmpty()) { - if (liveInstances.isEmpty() && deadInstances.length() > 1) { - qCInfo(logBare) << "No running instances for" << configFilePath; - qCInfo(logBare) << "Dead instances:"; - sortInstances(deadInstances, cmd.config.newest); - for (auto& instance: deadInstances) { - qCInfo(logBare).noquote() << " -" << instance.instance.instanceId; - } - } else if (!mismatchedInstances.isEmpty()) { - qCInfo(logBare) << "No running instances for" << configFilePath - << " present on the current display" << getDisplayConnection(); + if (logHelp) { + if (liveInstances.isEmpty() && deadInstances.length() > 1) { + qCInfo(logBare) << "No running instances for" << configFilePath; + qCInfo(logBare) << "Dead instances:"; + sortInstances(deadInstances, cmd.config.newest); + for (auto& instance: deadInstances) { + qCInfo(logBare).noquote() << " -" << instance.instance.instanceId; + } + } else if (!mismatchedInstances.isEmpty()) { + qCInfo(logBare) << "No running instances for" << configFilePath + << " present on the current display" << getDisplayConnection(); - qCInfo(logBare) << "Some instances on other displays match:"; + qCInfo(logBare) << "Some instances on other displays match:"; - for (auto& instance: mismatchedInstances) { - qCInfo(logBare).noquote().nospace() - << " - " << instance.instance.instanceId << " (" << instance.instance.display << ')'; + for (auto& instance: mismatchedInstances) { + qCInfo(logBare).noquote().nospace() << " - " << instance.instance.instanceId << " (" + << instance.instance.display << ')'; + } + } else { + qCInfo(logBare) << "No running instances for" << configFilePath; } - } else { - qCInfo(logBare) << "No running instances for" << configFilePath; } + return -1; } @@ -461,7 +473,7 @@ int launchFromCommand(CommandState& cmd, QCoreApplication* coreApplication) { { InstanceLockInfo info; - if (cmd.misc.noDuplicate && selectInstance(cmd, &info) == 0) { + if (cmd.misc.noDuplicate && selectInstance(cmd, &info, false, false) == 0) { qCInfo(logBare) << "An instance of this configuration is already running."; return 0; }