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
10 : parser(parser_)
11{
12 parser.registerOption("-diska", *this);
13 parser.registerOption("-diskb", *this);
14 parser.registerFileType({"di1", "di2", "dmk", "dsk", "xsa", "fd1", "fd2"}, *this);
15}
16
17void DiskImageCLI::parseOption(const std::string& option, std::span<std::string>& cmdLine)
18{
19 std::string filename = getArgument(option, cmdLine);
20 parse(zstring_view(option).substr(1), filename, cmdLine);
21}
22std::string_view DiskImageCLI::optionHelp() const
23{
24 return "Insert the disk image specified in argument";
25}
26
27void DiskImageCLI::parseFileType(const std::string& filename, std::span<std::string>& cmdLine)
28{
29 parse(tmpStrCat("disk", driveLetter), filename, cmdLine);
30 ++driveLetter;
31}
32
33std::string_view DiskImageCLI::fileTypeHelp() const
34{
35 return "Disk image";
36}
37
38std::string_view DiskImageCLI::fileTypeCategoryName() const
39{
40 return "disk";
41}
42
43void DiskImageCLI::parse(zstring_view drive, std::string_view image,
44 std::span<std::string>& cmdLine)
45{
46 if (!parser.getInterpreter().hasCommand(drive)) {
47 throw MSXException("No disk drive ", char(::toupper(drive.back())), " present to put image '", image, "' in.");
48 }
49 TclObject command = makeTclList(drive, image);
50 while (peekArgument(cmdLine) == "-ips") {
51 cmdLine = cmdLine.subspan(1);
52 command.addListElement(getArgument("-ips", cmdLine));
53 }
54 command.executeCommand(parser.getInterpreter());
55}
56
57} // 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::initializer_list< std::string_view > extensions, CLIFileType &cliFileType)
Interpreter & getInterpreter() const
DiskImageCLI(CommandLineParser &parser)
Definition: DiskImageCLI.cc:9
void parseOption(const std::string &option, std::span< std::string > &cmdLine) override
Definition: DiskImageCLI.cc:17
void parseFileType(const std::string &filename, std::span< std::string > &cmdLine) override
Definition: DiskImageCLI.cc:27
std::string_view fileTypeHelp() const override
Definition: DiskImageCLI.cc:33
std::string_view fileTypeCategoryName() const override
Definition: DiskImageCLI.cc:38
std::string_view optionHelp() const override
Definition: DiskImageCLI.cc:22
bool hasCommand(zstring_view name) const
Definition: Interpreter.cc:149
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
Definition: zstring_view.hh:22
constexpr char back() const
Definition: zstring_view.hh:47
This file implemented 3 utility functions:
Definition: Autofire.cc:9
TclObject makeTclList(Args &&... args)
Definition: TclObject.hh:283
std::string_view substr(std::string_view utf8, std::string_view::size_type first=0, std::string_view::size_type len=std::string_view::npos)
TemporaryString tmpStrCat(Ts &&... ts)
Definition: strCat.hh:610