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, array_ref<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(e.getMessage());
36  }
37 }
38 
40 {
41  return "Insert the extension specified in argument";
42 }
43 
44 } // namespace openmsx
string_ref optionHelp() const override
Definition: CliExtension.cc:39
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
void parseOption(const std::string &option, array_ref< std::string > &cmdLine) override
Definition: CliExtension.cc:21
const std::string & getMessage() const
Definition: MSXException.hh:13
This class implements a subset of the proposal for std::array_ref (proposed for the next c++ standard...
Definition: array_ref.hh:19
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
CliExtension(CommandLineParser &cmdLineParser)
Definition: CliExtension.cc:11
std::string getArgument(const std::string &option, array_ref< std::string > &cmdLine) const
Definition: CLIOption.cc:11
std::string loadExtension(string_ref extensionName, string_ref slotname)
MSXMotherBoard * getMotherBoard() const