openMSX
CliExtension.cc
Go to the documentation of this file.
1#include "CliExtension.hh"
3#include "HardwareConfig.hh"
4#include "MSXMotherBoard.hh"
5#include "MSXException.hh"
6#include <cassert>
7
8namespace openmsx {
9
11 : cmdLineParser(cmdLineParser_)
12{
13 for (const auto* ext : {"-ext", "-exta", "-extb", "-extc", "-extd"}) {
14 cmdLineParser.registerOption(ext, *this);
15 }
16}
17
18void CliExtension::parseOption(const std::string& option, std::span<std::string>& cmdLine)
19{
20 try {
21 std::string extensionName = getArgument(option, cmdLine);
22 MSXMotherBoard* motherboard = cmdLineParser.getMotherBoard();
23 assert(motherboard);
24 std::string slotName;
25 if (option.size() == 5) {
26 slotName = option[4];
27 } else {
28 slotName = "any";
29 }
30 motherboard->insertExtension(extensionName,
31 motherboard->loadExtension(extensionName, slotName));
32 } catch (MSXException& e) {
33 throw FatalError(std::move(e).getMessage());
34 }
35}
36
37std::string_view CliExtension::optionHelp() const
38{
39 return "Insert the extension specified in argument";
40}
41
42} // namespace openmsx
static std::string getArgument(const std::string &option, std::span< std::string > &cmdLine)
Definition CLIOption.cc:9
CliExtension(CommandLineParser &cmdLineParser)
std::string_view optionHelp() const override
void parseOption(const std::string &option, std::span< std::string > &cmdLine) override
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
MSXMotherBoard * getMotherBoard() const
std::unique_ptr< HardwareConfig > loadExtension(std::string_view extensionName, std::string_view slotName)
std::string insertExtension(std::string_view name, std::unique_ptr< HardwareConfig > extension)
This file implemented 3 utility functions:
Definition Autofire.cc:11