Skip to content

Commit a4e3a07

Browse files
Launch portable instance using -i "" instead of -i "Portable"
1 parent 7166eb8 commit a4e3a07

2 files changed

Lines changed: 19 additions & 9 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 {};

src/instancemanager.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,6 @@ std::shared_ptr<Instance> InstanceManager::currentInstance() const
566566
// no instance set
567567
return {};
568568
}
569-
} else if (name.compare("portable", Qt::CaseInsensitive) == 0 &&
570-
portableInstanceExists()) {
571-
// use portable
572-
return std::make_shared<Instance>(portablePath(), true, profile);
573569
}
574570

575571
return std::make_shared<Instance>(instancePath(name), false, profile);

0 commit comments

Comments
 (0)