From d11b9e3a272d21be9df3c4741d3785b48058974d Mon Sep 17 00:00:00 2001 From: SulfurNitride Date: Fri, 1 May 2026 01:05:16 -0500 Subject: 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. Cherry-picked from upstream 49da80c. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/src/commandline.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src') 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 #include #include +#include namespace cl { @@ -233,8 +234,12 @@ std::optional CommandLine::runEarly() std::optional CommandLine::runPostApplication(MOApplication& a) { - // handle -i with no arguments - if (m_vm.contains("instance") && m_vm["instance"].as().empty()) { + const auto instanceArg = m_vm.find("instance"); + if (instanceArg != m_vm.end() && + !instanceArg->second.as>().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()->implicit_value(""), + ("instance,i", + po::value>()->implicit_value( + boost::none), "use the given instance (defaults to last used)") ("profile,p", po::value(), @@ -414,8 +421,15 @@ std::optional 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()); + } else { + const auto instanceArg = m_vm.find("instance"); + if (instanceArg != m_vm.end()) { + const auto& instanceVal = + instanceArg->second.as>(); + if (instanceVal.has_value()) { + return QString::fromStdString(instanceVal.value()); + } + } } return {}; -- cgit v1.3.1