Skip to content

Commit 49da80c

Browse files
Make command-line arguments -i "" launch the portable instance (#2341)
1 parent f80ad04 commit 49da80c

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

src/commandline.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <log.h>
1111
#include <report.h>
1212

13+
#include <boost/optional/optional_io.hpp>
14+
1315
namespace cl
1416
{
1517

@@ -221,8 +223,12 @@ std::optional<int> CommandLine::runEarly()
221223

222224
std::optional<int> CommandLine::runPostApplication(MOApplication& a)
223225
{
224-
// handle -i with no arguments
225-
if (m_vm.count("instance") && m_vm["instance"].as<std::string>() == "") {
226+
const auto instanceArg = m_vm.find("instance");
227+
if (instanceArg != m_vm.end() &&
228+
!instanceArg->second.as<boost::optional<std::string>>().has_value()) {
229+
230+
// handle -i with no arguments (distinct from -i "", which will launch the
231+
// portable instance if it exists, hence the use of boost::optional)
226232
env::Console c;
227233

228234
if (auto i = InstanceManager::singleton().currentInstance()) {
@@ -314,7 +320,9 @@ void CommandLine::createOptions()
314320

315321
("logs", "duplicates the logs to stdout")
316322

317-
("instance,i", po::value<std::string>()->implicit_value(""),
323+
("instance,i",
324+
po::value<boost::optional<std::string>>()->implicit_value(
325+
boost::none),
318326
"use the given instance (defaults to last used)")
319327

320328
("profile,p", po::value<std::string>(),
@@ -402,8 +410,14 @@ std::optional<QString> CommandLine::instance() const
402410

403411
if (m_shortcut.isValid() && m_shortcut.hasInstance()) {
404412
return m_shortcut.instanceName();
405-
} else if (m_vm.count("instance")) {
406-
return QString::fromStdString(m_vm["instance"].as<std::string>());
413+
} else {
414+
const auto instanceArg = m_vm.find("instance");
415+
if (instanceArg != m_vm.end()) {
416+
const auto& instanceVal = instanceArg->second.as<boost::optional<std::string>>();
417+
if (instanceVal.has_value()) {
418+
return QString::fromStdString(instanceVal.value());
419+
}
420+
}
407421
}
408422

409423
return {};

0 commit comments

Comments
 (0)