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