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 namespace openmsx {
8 
10  : cmdLineParser(cmdLineParser_)
11 {
12  cmdLineParser.registerOption("-ext", *this);
13  cmdLineParser.registerOption("-exta", *this);
14  cmdLineParser.registerOption("-extb", *this);
15  cmdLineParser.registerOption("-extc", *this);
16  cmdLineParser.registerOption("-extd", *this);
17 }
18 
19 void CliExtension::parseOption(const std::string& option, span<std::string>& cmdLine)
20 {
21  try {
22  std::string extensionName = getArgument(option, cmdLine);
23  MSXMotherBoard* motherboard = cmdLineParser.getMotherBoard();
24  assert(motherboard);
25  std::string slotname;
26  if (option.size() == 5) {
27  slotname = option[4];
28  } else {
29  slotname = "any";
30  }
31  motherboard->loadExtension(extensionName, slotname);
32  } catch (MSXException& e) {
33  throw FatalError(std::move(e).getMessage());
34  }
35 }
36 
37 std::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, span< std::string > &cmdLine)
Definition: CLIOption.cc:9
void parseOption(const std::string &option, span< std::string > &cmdLine) override
Definition: CliExtension.cc:19
CliExtension(CommandLineParser &cmdLineParser)
Definition: CliExtension.cc:9
std::string_view optionHelp() const override
Definition: CliExtension.cc:37
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
MSXMotherBoard * getMotherBoard() const
std::string loadExtension(std::string_view extensionName, std::string_view slotname)
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:9