openMSX
DiskImageCLI.cc
Go to the documentation of this file.
1 #include "DiskImageCLI.hh"
2 #include "CommandLineParser.hh"
3 #include "Interpreter.hh"
4 #include "TclObject.hh"
5 #include "MSXException.hh"
6 
7 namespace 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  driveLetter = 'a';
16 }
17 
18 void DiskImageCLI::parseOption(const std::string& option, span<std::string>& cmdLine)
19 {
20  std::string filename = getArgument(option, cmdLine);
21  parse(zstring_view(option).substr(1), filename, cmdLine);
22 }
23 std::string_view DiskImageCLI::optionHelp() const
24 {
25  return "Insert the disk image specified in argument";
26 }
27 
28 void DiskImageCLI::parseFileType(const std::string& filename, span<std::string>& cmdLine)
29 {
30  parse(tmpStrCat("disk", driveLetter), filename, cmdLine);
31  ++driveLetter;
32 }
33 
34 std::string_view DiskImageCLI::fileTypeHelp() const
35 {
36  return "Disk image";
37 }
38 
39 std::string_view DiskImageCLI::fileTypeCategoryName() const
40 {
41  return "disk";
42 }
43 
44 void DiskImageCLI::parse(zstring_view drive, std::string_view image,
45  span<std::string>& cmdLine)
46 {
47  if (!parser.getInterpreter().hasCommand(drive)) {
48  throw MSXException("No disk drive ", char(::toupper(drive.back())), " present to put image '", image, "' in.");
49  }
50  TclObject command = makeTclList(drive, image);
51  while (peekArgument(cmdLine) == "-ips") {
52  cmdLine = cmdLine.subspan(1);
53  command.addListElement(getArgument("-ips", cmdLine));
54  }
55  command.executeCommand(parser.getInterpreter());
56 }
57 
58 } // namespace openmsx
std::string image
Definition: HDImageCLI.cc:13
static std::string peekArgument(const span< std::string > &cmdLine)
Definition: CLIOption.cc:19
static std::string getArgument(const std::string &option, span< std::string > &cmdLine)
Definition: CLIOption.cc:9
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
void parseFileType(const std::string &filename, span< std::string > &cmdLine) override
Definition: DiskImageCLI.cc:28
DiskImageCLI(CommandLineParser &parser)
Definition: DiskImageCLI.cc:9
void parseOption(const std::string &option, span< std::string > &cmdLine) override
Definition: DiskImageCLI.cc:18
std::string_view fileTypeHelp() const override
Definition: DiskImageCLI.cc:34
std::string_view fileTypeCategoryName() const override
Definition: DiskImageCLI.cc:39
std::string_view optionHelp() const override
Definition: DiskImageCLI.cc:23
bool hasCommand(zstring_view name) const
Definition: Interpreter.cc:148
Definition: span.hh:126
constexpr subspan_return_t< Offset, Count > subspan() const
Definition: span.hh:266
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
constexpr const char *const filename
TclObject makeTclList(Args &&... args)
Definition: TclObject.hh:290
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:659