openMSX
CassettePlayerCLI.cc
Go to the documentation of this file.
1 #include "CassettePlayerCLI.hh"
2 #include "CommandLineParser.hh"
3 #include "Interpreter.hh"
4 #include "MSXException.hh"
5 #include "TclObject.hh"
6 
7 namespace openmsx {
8 
10  : parser(parser_)
11 {
12  parser.registerOption("-cassetteplayer", *this);
13  parser.registerFileType({"cas", "wav"}, *this);
14 }
15 
16 void CassettePlayerCLI::parseOption(const std::string& option,
17  span<std::string>& cmdLine)
18 {
19  parseFileType(getArgument(option, cmdLine), cmdLine);
20 }
21 
22 std::string_view CassettePlayerCLI::optionHelp() const
23 {
24  return "Put cassette image specified in argument in "
25  "virtual cassetteplayer";
26 }
27 
29  span<std::string>& /*cmdLine*/)
30 {
31  if (!parser.getInterpreter().hasCommand("cassetteplayer")) {
32  throw MSXException("No cassette player present.");
33  }
34  TclObject command = makeTclList("cassetteplayer", filename);
35  command.executeCommand(parser.getInterpreter());
36 }
37 
38 std::string_view CassettePlayerCLI::fileTypeHelp() const
39 {
40  return "Cassette image, raw recording or fMSX CAS image";
41 }
42 
44 {
45  return "cassette";
46 }
47 
48 } // 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
CassettePlayerCLI(CommandLineParser &parser)
std::string_view fileTypeCategoryName() const override
void parseFileType(const std::string &filename, span< std::string > &cmdLine) override
std::string_view fileTypeHelp() const override
std::string_view optionHelp() const override
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
void registerFileType(std::initializer_list< std::string_view > extensions, CLIFileType &cliFileType)
Interpreter & getInterpreter() const
bool hasCommand(zstring_view name) const
Definition: Interpreter.cc:148
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:290