diff options
| author | Jonathan Feenstra <26406078+JonathanFeenstra@users.noreply.github.com> | 2026-04-27 08:57:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-27 08:57:00 +0200 |
| commit | 49da80c2a4f97f472a14fb88f39b0e36ef5fc994 (patch) | |
| tree | 944542437fcc376227ca9f1ad18a8763baec42fa | |
| parent | f80ad0435c904731c8d749fa0c71287413e950a8 (diff) | |
Make command-line arguments -i "" launch the portable instance (#2341)
| -rw-r--r-- | src/commandline.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/commandline.cpp b/src/commandline.cpp index 1d44e043..aaa31c8a 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -10,6 +10,8 @@ #include <log.h> #include <report.h> +#include <boost/optional/optional_io.hpp> + namespace cl { @@ -221,8 +223,12 @@ std::optional<int> CommandLine::runEarly() std::optional<int> CommandLine::runPostApplication(MOApplication& a) { - // handle -i with no arguments - if (m_vm.count("instance") && m_vm["instance"].as<std::string>() == "") { + 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) env::Console c; if (auto i = InstanceManager::singleton().currentInstance()) { @@ -314,7 +320,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>(), @@ -402,8 +410,14 @@ std::optional<QString> CommandLine::instance() const if (m_shortcut.isValid() && m_shortcut.hasInstance()) { return m_shortcut.instanceName(); - } else if (m_vm.count("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 {}; |
