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