openMSX
CDImageCLI.cc
Go to the documentation of this file.
1 #include "CDImageCLI.hh"
2 #include "CommandLineParser.hh"
4 #include "TclObject.hh"
5 #include "MSXException.hh"
6 
7 using std::string;
8 
9 namespace openmsx {
10 
12  : parser(parser_)
13 {
14  parser.registerOption("-cda", *this);
15  // TODO: offer more options in case you want to specify 2 hard disk images?
16 }
17 
18 void CDImageCLI::parseOption(const string& option, span<string>& cmdLine)
19 {
20  auto cd = std::string_view(option).substr(1); // cda
21  string filename = getArgument(option, cmdLine);
22  if (!parser.getGlobalCommandController().hasCommand(cd)) { // TODO WIP
23  throw MSXException("No CDROM named '", cd, "'.");
24  }
25  TclObject command = makeTclList(cd, filename);
26  command.executeCommand(parser.getInterpreter());
27 }
28 std::string_view CDImageCLI::optionHelp() const
29 {
30  return "Use iso image in argument for the CDROM extension";
31 }
32 
33 } // namespace openmsx
openmsx::CDImageCLI::CDImageCLI
CDImageCLI(CommandLineParser &parser)
Definition: CDImageCLI.cc:11
openmsx::CommandLineParser::registerOption
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
Definition: CommandLineParser.cc:84
TclObject.hh
openmsx::CommandLineParser::getInterpreter
Interpreter & getInterpreter() const
Definition: CommandLineParser.cc:306
openmsx::GlobalCommandController::hasCommand
bool hasCommand(std::string_view command) const override
Does a command with this name already exist?
Definition: GlobalCommandController.cc:174
CommandLineParser.hh
MSXException.hh
openmsx::MSXException
Definition: MSXException.hh:9
span
Definition: span.hh:34
openmsx::CDImageCLI::parseOption
void parseOption(const std::string &option, span< std::string > &cmdLine) override
Definition: CDImageCLI.cc:18
openmsx::filename
constexpr const char *const filename
Definition: FirmwareSwitch.cc:10
openmsx::TclObject::executeCommand
TclObject executeCommand(Interpreter &interp, bool compile=false)
Interpret this TclObject as a command and execute it.
Definition: TclObject.cc:172
openmsx::CommandLineParser
Definition: CommandLineParser.hh:34
GlobalCommandController.hh
CDImageCLI.hh
openmsx::makeTclList
TclObject makeTclList(Args &&... args)
Definition: TclObject.hh:280
openmsx::TclObject
Definition: TclObject.hh:21
openmsx::CommandLineParser::getGlobalCommandController
GlobalCommandController & getGlobalCommandController() const
Definition: CommandLineParser.cc:301
openmsx::CLIOption::getArgument
std::string getArgument(const std::string &option, span< std::string > &cmdLine) const
Definition: CLIOption.cc:11
openmsx::CDImageCLI::optionHelp
std::string_view optionHelp() const override
Definition: CDImageCLI.cc:28
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5