openMSX
DiskImageCLI.cc
Go to the documentation of this file.
1 #include "DiskImageCLI.hh"
2 #include "CommandLineParser.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(std::string_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(strCat("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(std::string_view drive, std::string_view image,
47  span<string>& cmdLine)
48 {
49  if (!parser.getGlobalCommandController().hasCommand(drive)) { // TODO WIP
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
openmsx::CommandLineParser::registerOption
void registerOption(const char *str, CLIOption &cliOption, ParsePhase phase=PHASE_LAST, unsigned length=2)
Definition: CommandLineParser.cc:84
TclObject.hh
openmsx::CommandLineParser::getInterpreter
Interpreter & getInterpreter() const
Definition: CommandLineParser.cc:306
openmsx::GlobalCommandController::hasCommand
bool hasCommand(std::string_view command) const override
Does a command with this name already exist?
Definition: GlobalCommandController.cc:174
CommandLineParser.hh
utf8::unchecked::substr
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)
Definition: utf8_unchecked.hh:231
openmsx::DiskImageCLI::parseOption
void parseOption(const std::string &option, span< std::string > &cmdLine) override
Definition: DiskImageCLI.cc:20
openmsx::CLIOption::peekArgument
std::string peekArgument(const span< std::string > &cmdLine) const
Definition: CLIOption.cc:21
MSXException.hh
openmsx::MSXException
Definition: MSXException.hh:10
openmsx::DiskImageCLI::optionHelp
std::string_view optionHelp() const override
Definition: DiskImageCLI.cc:25
span::subspan
constexpr subspan_return_t< Offset, Count > subspan() const
Definition: span.hh:266
span
Definition: span.hh:126
DiskImageCLI.hh
openmsx::DiskImageCLI::parseFileType
void parseFileType(const std::string &filename, span< std::string > &cmdLine) override
Definition: DiskImageCLI.cc:30
openmsx::filename
constexpr const char *const filename
Definition: FirmwareSwitch.cc:10
openmsx::CommandLineParser
Definition: CommandLineParser.hh:35
openmsx::DiskImageCLI::fileTypeHelp
std::string_view fileTypeHelp() const override
Definition: DiskImageCLI.cc:36
GlobalCommandController.hh
openmsx::makeTclList
TclObject makeTclList(Args &&... args)
Definition: TclObject.hh:280
openmsx::DiskImageCLI::fileTypeCategoryName
std::string_view fileTypeCategoryName() const override
Definition: DiskImageCLI.cc:41
openmsx::CommandLineParser::getGlobalCommandController
GlobalCommandController & getGlobalCommandController() const
Definition: CommandLineParser.cc:301
openmsx::DiskImageCLI::DiskImageCLI
DiskImageCLI(CommandLineParser &parser)
Definition: DiskImageCLI.cc:11
openmsx::CommandLineParser::registerFileType
void registerFileType(std::initializer_list< std::string_view > extensions, CLIFileType &cliFileType)
Definition: CommandLineParser.cc:90
openmsx::CLIOption::getArgument
std::string getArgument(const std::string &option, span< std::string > &cmdLine) const
Definition: CLIOption.cc:11
strCat
std::string strCat(Ts &&...ts)
Definition: strCat.hh:573
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5