X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/cbbee23e7768750ca1c8b49bdfbf8a650131bbb6..41d39345bdc31cb9b8be057cd678aa2890830437:/cmdline/apt-cache.cc?ds=sidebyside diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 4b3a74922..4e8a51583 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -1521,29 +1522,16 @@ static bool GenCaches(CommandLine &) return CacheFile.BuildCaches(&Progress, true); } /*}}}*/ -// ShowHelp - Show a help screen /*{{{*/ -static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) +bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds) /*{{{*/ { - ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); - - if (_config->FindB("version") == true) - return true; - std::cout << _("Usage: apt-cache [options] command\n" " apt-cache [options] show pkg1 [pkg2 ...]\n" "\n" "apt-cache is a low-level tool used to query information\n" "from APT's binary cache files\n") - << std::endl - << _("Commands:") << std::endl; - for (; Cmds->Handler != nullptr; ++Cmds) - { - if (Cmds->Help == nullptr) - continue; - std::cout << " " << Cmds->Match << " - " << Cmds->Help << std::endl; - } - + << std::endl; + ShowHelpListCommands(Cmds); std::cout << std::endl << _("Options:\n" " -h This help text.\n" @@ -1557,9 +1545,9 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) return true; } /*}}}*/ -int main(int argc,const char *argv[]) /*{{{*/ +std::vector GetCommands() /*{{{*/ { - CommandLine::DispatchWithHelp Cmds[] = { + return { {"gencaches",&GenCaches, nullptr}, {"showsrc",&ShowSrcPackage, _("Show source records")}, {"showpkg",&DumpPackage, nullptr}, @@ -1579,31 +1567,21 @@ int main(int argc,const char *argv[]) /*{{{*/ {"madison",&Madison, nullptr}, {nullptr, nullptr, nullptr} }; - - std::vector Args = getCommandArgs("apt-cache", CommandLine::GetCommand(Cmds, argc, argv)); - - // Set up gettext support - setlocale(LC_ALL,""); - textdomain(PACKAGE); +} + /*}}}*/ +int main(int argc,const char *argv[]) /*{{{*/ +{ + InitLocale(); // Parse the command line and initialize the package library CommandLine CmdL; - ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp); + auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_CACHE, &_config, &_system, argc, argv); InitOutput(); if (_config->Exists("APT::Cache::Generate") == true) _config->Set("pkgCacheFile::Generate", _config->FindB("APT::Cache::Generate", true)); - // Match the operation - CmdL.DispatchArg(Cmds); - - // Print any errors or warnings found during parsing - bool const Errors = _error->PendingError(); - if (_config->FindI("quiet",0) > 0) - _error->DumpErrors(); - else - _error->DumpErrors(GlobalError::DEBUG); - return Errors == true ? 100 : 0; + return DispatchCommandLine(CmdL, Cmds); } /*}}}*/