bool StandardParserWithMandatoryCommand::parse(int argc, const char* argv[]) { if (StandardParserWithManpage::parse(argc, argv)) return true; if (!foundCommand()) { commandline::Help help(name(), m_version); help.outputHelp(cout, *this); return true; } if (foundCommand() == helpCommand) { commandline::Help help(name(), m_version); if (hasNext()) { // Help on a specific command string command = next(); if (Engine* e = this->command(command)) help.outputHelp(cout, *e); else throw BadOption("unknown command " + command + "; run '" + argv[0] + " help' " "for a list of all the available commands"); } else { // General help help.outputHelp(cout, *this); } return true; } return false; }
bool Connection::set_option(Option* o) { const std::type_info& oti = typeid(*o); if (driver_->set_option(o)) { error_message_.clear(); return true; } else { error_message_ = driver_->error(); if (throw_exceptions()) { throw BadOption(error_message_, oti); } return false; } }
void ParseIteractiveArguments (int argc, char** argv, char optchar) { int SortOrder = ASCENDING, SortCriterium = UNSORTED; int Method = FULL_OPTIMIZATION; int index = 1; if (argc > 1) /* If there where any arguments. */ { /* See wether argv[1] is a drive specification. */ if ((strlen(argv[1]) == 2) && (argv[1][1] == ':')) { ParsedDrive = argv[1][0]; SetOptimizationDrive(ParsedDrive); index++; } for (; index < argc; index++) { if ((argv[index][0] != optchar) && (argv[index][0] != '/')) ShowError("Invalid input"); switch(toupper(argv[index][1])) { case '\0': BadOption(); break; case 'F': if (argv[index][2] == '\0') { Method = FULL_OPTIMIZATION; MethodEntered = TRUE; } else BadOption(); break; case 'U': if (argv[index][2] == '\0') { Method = UNFRAGMENT_FILES; MethodEntered = TRUE; } else BadOption(); break; case 'S': switch(toupper(argv[index][2])) { case '\0': ShowError("Invalid sort criterium"); break; case 'N': SortCriterium = NAMESORTED; break; case 'D': SortCriterium = DATETIMESORTED; break; case 'E': SortCriterium = EXTENSIONSORTED; break; case 'S': SortCriterium = SIZESORTED; break; default: ShowError("Invalid sort criterium"); } switch(argv[index][3]) { case '\0': SortOrder = ASCENDING; break; case '-': if (argv[index][4] == '\0') SortOrder = DESCENDING; else BadOption(); break; default: ShowError("Invalid sort criterium"); } break; case 'B': if (argv[index][2] == 0) RebootRequested = TRUE; else BadOption(); break; case 'X': if (argv[index][2] == 0) AutoExit = TRUE; else BadOption(); break; default: if ((stricmp(&argv[index][1], "SKIPHIGH") == 0) || (stricmp(&argv[index][1], "LCD") == 0) || (stricmp(&argv[index][1], "BW") == 0) || (stricmp(&argv[index][1], "G0") == 0)) WarnOnNoOp(argv[index]); else BadOption(); } } } SetOptimizationMethod(Method); SetSortOptions(SortCriterium, SortOrder); }
void ParseCmdLineArguments (int argc, char** argv, char optchar) { int SortOrder = ASCENDING, SortCriterium = UNSORTED; int Method = FULL_OPTIMIZATION; int index; if (argc > 1) /* If there where any arguments. */ { /* See wether argv[1] is a drive specification. */ if ((strlen(argv[1]) == 2) && (argv[1][1] == ':')) { SetParsedDrive(argv[1][0]); SetOptimizationDrive(argv[1][0]); } else ShowError("No disk entered on command line"); for (index = 2; index < argc; index++) { if ((argv[index][0] != optchar) && (argv[index][0] != '/')) ShowError("Invalid input"); switch(toupper(argv[index][1])) { case '\0': BadOption(); break; case 'F': if (argv[index][2] == '\0') { Method = FULL_OPTIMIZATION; MethodIsEntered(); } else if ((toupper(argv[index][2]) == 'O') && (argv[index][3] == '\0')) SetFullOutput(); else BadOption(); break; case 'U': if (argv[index][2] == '\0') { Method = UNFRAGMENT_FILES; MethodIsEntered(); } else BadOption(); break; case 'S': switch(toupper(argv[index][2])) { case '\0': ShowError("Invalid sort criterium"); break; case 'N': SortCriterium = NAMESORTED; break; case 'D': SortCriterium = DATETIMESORTED; break; case 'E': SortCriterium = EXTENSIONSORTED; break; case 'S': SortCriterium = SIZESORTED; break; default: ShowError("Invalid sort criterium"); } switch(argv[index][3]) { case '\0': SortOrder = ASCENDING; break; case '-': if (argv[index][4] == '\0') SortOrder = DESCENDING; else BadOption(); break; default: ShowError("Invalid sort criterium"); } break; case 'B': if (argv[index][2] == 0) RequestReboot(); else BadOption(); break; case 'X': if (argv[index][2] == 0) AutomaticallyExit(); else BadOption(); break; case 'A': if (argv[index][2] == 0) SetAudibleWarning(); else BadOption(); break; default: if ((stricmp(&argv[index][1], "SKIPHIGH") == 0) || (stricmp(&argv[index][1], "LCD") == 0) || (stricmp(&argv[index][1], "BW") == 0) || (stricmp(&argv[index][1], "G0") == 0)) WarnOnNoOp(argv[index]); else BadOption(); } } } else ShowError("No disk entered on command line"); SetOptimizationMethod(Method); SetSortOptions(SortCriterium, SortOrder); }
ArgList::iterator Engine::parse(ArgList& list, ArgList::iterator begin) { rebuild(); // Parse and remove known switches begin = parseKnownSwitches(list, begin); m_found_command = 0; // Check if we have to handle commands if (!m_commands.empty()) { // Look for the first non-switch in the list ArgList::iterator cmd = begin; while (cmd != list.end() && list.isSwitch(cmd)) ++cmd; if (cmd != list.end()) { // A command has been found, ensure that we can handle it map<string, Engine*>::iterator a = m_aliases.find(*cmd); if (a == m_aliases.end()) throw BadOption("unknown command " + *cmd); // Remove the command from the list if (cmd == begin) ++begin; list.erase(cmd); // We found a valid command, let's enable subcommand parsing m_found_command = a->second; } } if (!m_found_command) { // If we don't have any more subcommands to parse, then ensure that // there are no switches left to process for (ArgList::iterator i = begin; i != list.end(); ++i) { if (*i == "--") { // Remove '--' and stop looking for switches if (begin == i) { begin++; list.erase(i); } break; } if (list.isSwitch(i)) throw BadOption(string("unknown option ") + *i); else if (no_switches_after_first_arg) // If requested, stop looking for switches // after the first non-switch argument break; } m_found_command = 0; return begin; } else { // Else, invoke the subcommand engine on the list return m_found_command->parse(list, begin); } }