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