|
10 | 10 | #include <log.h> |
11 | 11 | #include <report.h> |
12 | 12 |
|
| 13 | +#include <boost/optional/optional_io.hpp> |
| 14 | + |
13 | 15 | namespace cl |
14 | 16 | { |
15 | 17 |
|
@@ -221,8 +223,12 @@ std::optional<int> CommandLine::runEarly() |
221 | 223 |
|
222 | 224 | std::optional<int> CommandLine::runPostApplication(MOApplication& a) |
223 | 225 | { |
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) |
226 | 232 | env::Console c; |
227 | 233 |
|
228 | 234 | if (auto i = InstanceManager::singleton().currentInstance()) { |
@@ -314,7 +320,9 @@ void CommandLine::createOptions() |
314 | 320 |
|
315 | 321 | ("logs", "duplicates the logs to stdout") |
316 | 322 |
|
317 | | - ("instance,i", po::value<std::string>()->implicit_value(""), |
| 323 | + ("instance,i", |
| 324 | + po::value<boost::optional<std::string>>()->implicit_value( |
| 325 | + boost::none), |
318 | 326 | "use the given instance (defaults to last used)") |
319 | 327 |
|
320 | 328 | ("profile,p", po::value<std::string>(), |
@@ -402,8 +410,14 @@ std::optional<QString> CommandLine::instance() const |
402 | 410 |
|
403 | 411 | if (m_shortcut.isValid() && m_shortcut.hasInstance()) { |
404 | 412 | 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 | + } |
407 | 421 | } |
408 | 422 |
|
409 | 423 | return {}; |
|
0 commit comments