openMSX
CassettePlayerCLI.cc
Go to the documentation of this file.
3#include "Interpreter.hh"
4#include "MSXException.hh"
5#include "TclObject.hh"
6
7namespace openmsx {
8
9std::span<const std::string_view> CassettePlayerCLI::getExtensions()
10{
11 static constexpr std::array<std::string_view, 2> extensions = {
12 "cas", "wav"
13 };
14 return extensions;
15}
16
18 : parser(parser_)
19{
20 parser.registerOption("-cassetteplayer", *this);
21 parser.registerFileType(getExtensions(), *this);
22}
23
24void CassettePlayerCLI::parseOption(const std::string& option,
25 std::span<std::string>& cmdLine)
26{
27 parseFileType(getArgument(option, cmdLine), cmdLine);
28}
29
30std::string_view CassettePlayerCLI::optionHelp() const
31{
32 return "Put cassette image specified in argument in "
33 "virtual cassetteplayer";
34}
35
36void CassettePlayerCLI::parseFileType(const std::string& filename,
37 std::span<std::string>& /*cmdLine*/)
38{
39 if (!parser.getInterpreter().hasCommand("cassetteplayer")) {
40 throw MSXException("No cassette player present.");
41 }
42 TclObject command = makeTclList("cassetteplayer", filename);
43 command.executeCommand(parser.getInterpreter());
44}
45
46std::string_view CassettePlayerCLI::fileTypeHelp() const
47{
48 return "Cassette image, raw recording or fMSX CAS image";
49}
50
52{
53 return "cassette";
54}
55
56} // namespace openmsx
static std::string getArgument(const std::string &option, std::span< std::string > &cmdLine)
Definition CLIOption.cc:9
CassettePlayerCLI(CommandLineParser &parser)
void parseOption(const std::string &option, std::span< std::string > &cmdLine) override
std::string_view fileTypeCategoryName() const override
void parseFileType(const std::string &filename, std::span< std::string > &cmdLine) override
std::string_view fileTypeHelp() const override
static std::span< const std::string_view > getExtensions()
std::string_view optionHelp() const override
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
void registerFileType(std::span< const std::string_view > extensions, CLIFileType &cliFileType)
Interpreter & getInterpreter() const
bool hasCommand(zstring_view name) const
TclObject executeCommand(Interpreter &interp, bool compile=false)
Interpret this TclObject as a command and execute it.
Definition TclObject.cc:248
This file implemented 3 utility functions:
Definition Autofire.cc:11
TclObject makeTclList(Args &&... args)
Definition TclObject.hh:293