aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSulfurNitride <SulfurNitride@users.noreply.github.com>2026-05-01 01:05:16 -0500
committerSulfurNitride <SulfurNitride@users.noreply.github.com>2026-05-01 01:05:16 -0500
commitd11b9e3a272d21be9df3c4741d3785b48058974d (patch)
tree4873dce820743604f3003ecd090ba5623b1abc04
parent496befb51f8f876ab62f78b524e612d940b02956 (diff)
Port upstream PR #2341: -i "" launches portable instance
Distinguish between -i (no value, prints current instance and exits) and -i "" (launches the portable instance if one exists) by switching the option parser from std::string to boost::optional<std::string>. Cherry-picked from upstream 49da80c. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
-rw-r--r--src/src/commandline.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/src/commandline.cpp b/src/src/commandline.cpp
index 4ff408e..46f9be0 100644
--- a/src/src/commandline.cpp
+++ b/src/src/commandline.cpp
@@ -13,6 +13,7 @@
#include <QFile>
#include <QSettings>
#include <QTextStream>
+#include <boost/optional/optional_io.hpp>
namespace cl
{
@@ -233,8 +234,12 @@ std::optional<int> CommandLine::runEarly()
std::optional<int> CommandLine::runPostApplication(MOApplication& a)
{
- // handle -i with no arguments
- if (m_vm.contains("instance") && m_vm["instance"].as<std::string>().empty()) {
+ const auto instanceArg = m_vm.find("instance");
+ if (instanceArg != m_vm.end() &&
+ !instanceArg->second.as<boost::optional<std::string>>().has_value()) {
+ // handle -i with no arguments (distinct from -i "", which will launch the
+ // portable instance if it exists, hence the use of boost::optional).
+ // Upstream PR #2341.
env::Console const c;
if (auto i = InstanceManager::singleton().currentInstance()) {
@@ -326,7 +331,9 @@ void CommandLine::createOptions()
("logs", "duplicates the logs to stdout")
- ("instance,i", po::value<std::string>()->implicit_value(""),
+ ("instance,i",
+ po::value<boost::optional<std::string>>()->implicit_value(
+ boost::none),
"use the given instance (defaults to last used)")
("profile,p", po::value<std::string>(),
@@ -414,8 +421,15 @@ std::optional<QString> CommandLine::instance() const
if (m_shortcut.isValid() && m_shortcut.hasInstance()) {
return m_shortcut.instanceName();
- } else if (m_vm.contains("instance")) {
- return QString::fromStdString(m_vm["instance"].as<std::string>());
+ } else {
+ const auto instanceArg = m_vm.find("instance");
+ if (instanceArg != m_vm.end()) {
+ const auto& instanceVal =
+ instanceArg->second.as<boost::optional<std::string>>();
+ if (instanceVal.has_value()) {
+ return QString::fromStdString(instanceVal.value());
+ }
+ }
}
return {};