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