openMSX
DiskImageCLI.cc
Go to the documentation of this file.
1#include "DiskImageCLI.hh"
2
4#include "Interpreter.hh"
5#include "MSXException.hh"
6#include "TclObject.hh"
7
8namespace openmsx {
9
10std::span<const std::string_view> DiskImageCLI::getExtensions()
11{
12 static constexpr std::array<std::string_view, 7> extensions = {
13 "di1", "di2", "dmk", "dsk", "xsa", "fd1", "fd2"
14 };
15 return extensions;
16}
17
19 : parser(parser_)
20{
21 for (const auto* disk : {"-diska", "-diskb"}) {
22 parser.registerOption(disk, *this);
23 }
24 parser.registerFileType(getExtensions(), *this);
25}
26
27void DiskImageCLI::parseOption(const std::string& option, std::span<std::string>& cmdLine)
28{
29 std::string filename = getArgument(option, cmdLine);
30 parse(zstring_view(option).substr(1), filename, cmdLine);
31}
32std::string_view DiskImageCLI::optionHelp() const
33{
34 return "Insert the disk image specified in argument";
35}
36
37void DiskImageCLI::parseFileType(const std::string& filename, std::span<std::string>& cmdLine)
38{
39 parse(tmpStrCat("disk", driveLetter), filename, cmdLine);
40 ++driveLetter;
41}
42
43std::string_view DiskImageCLI::fileTypeHelp() const
44{
45 return "Disk image";
46}
47
48std::string_view DiskImageCLI::fileTypeCategoryName() const
49{
50 return "disk";
51}
52
53void DiskImageCLI::parse(zstring_view drive, std::string_view image,
54 std::span<std::string>& cmdLine) const
55{
56 if (!parser.getInterpreter().hasCommand(drive)) {
57 throw MSXException("No disk drive ", char(::toupper(drive.back())), " present to put image '", image, "' in.");
58 }
59 TclObject command = makeTclList(drive, image);
60 while (peekArgument(cmdLine) == "-ips") {
61 cmdLine = cmdLine.subspan(1);
62 command.addListElement(getArgument("-ips", cmdLine));
63 }
64 command.executeCommand(parser.getInterpreter());
65}
66
67} // namespace openmsx
std::string image
Definition HDImageCLI.cc:16
static std::string getArgument(const std::string &option, std::span< std::string > &cmdLine)
Definition CLIOption.cc:9
static std::string peekArgument(const std::span< std::string > &cmdLine)
Definition CLIOption.cc:19
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
DiskImageCLI(CommandLineParser &parser)
void parseOption(const std::string &option, std::span< std::string > &cmdLine) override
static std::span< const std::string_view > getExtensions()
void parseFileType(const std::string &filename, std::span< std::string > &cmdLine) override
std::string_view fileTypeHelp() const override
std::string_view fileTypeCategoryName() const override
std::string_view optionHelp() const override
bool hasCommand(zstring_view name) const
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
constexpr char back() const
This file implemented 3 utility functions:
Definition Autofire.cc:11
TclObject makeTclList(Args &&... args)
Definition TclObject.hh:293
TemporaryString tmpStrCat(Ts &&... ts)
Definition strCat.hh:742