openMSX
CDImageCLI.cc
Go to the documentation of this file.
1 #include "CDImageCLI.hh"
2 #include "CommandLineParser.hh"
3 #include "Interpreter.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.getInterpreter().hasCommand(std::string(cd))) { // TODO WIP
23  throw MSXException("No CD-ROM 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 CD-ROM extension";
31 }
32 
33 } // namespace openmsx
std::string_view optionHelp() const override
Definition: CDImageCLI.cc:28
void parseOption(const std::string &option, span< std::string > &cmdLine) override
Definition: CDImageCLI.cc:18
CDImageCLI(CommandLineParser &parser)
Definition: CDImageCLI.cc:11
static std::string getArgument(const std::string &option, span< std::string > &cmdLine)
Definition: CLIOption.cc:11
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
Interpreter & getInterpreter() const
bool hasCommand(zstring_view name) const
Definition: Interpreter.cc:145
TclObject executeCommand(Interpreter &interp, bool compile=false)
Interpret this TclObject as a command and execute it.
Definition: TclObject.cc:181
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr const char *const filename
TclObject makeTclList(Args &&... args)
Definition: TclObject.hh:291