X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/631800b139834947b21c49153ba7862b1f4e6984..41d39345bdc31cb9b8be057cd678aa2890830437:/cmdline/apt-cache.cc diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 24ed9eef3..4e8a51583 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -1521,42 +1522,18 @@ static bool GenCaches(CommandLine &) return CacheFile.BuildCaches(&Progress, true); } /*}}}*/ -// ShowHelp - Show a help screen /*{{{*/ -// --------------------------------------------------------------------- -/* */ -static bool ShowHelp(CommandLine &) +bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds) /*{{{*/ { - ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); - - if (_config->FindB("version") == true) - return true; - - cout << + std::cout << _("Usage: apt-cache [options] command\n" - " apt-cache [options] showpkg pkg1 [pkg2 ...]\n" - " apt-cache [options] showsrc pkg1 [pkg2 ...]\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" - "\n" - "Commands:\n" - " gencaches - Build both the package and source cache\n" - " showpkg - Show some general information for a single package\n" - " showsrc - Show source records\n" - " stats - Show some basic statistics\n" - " dump - Show the entire file in a terse form\n" - " dumpavail - Print an available file to stdout\n" - " unmet - Show unmet dependencies\n" - " search - Search the package list for a regex pattern\n" - " show - Show a readable record for the package\n" - " depends - Show raw dependency information for a package\n" - " rdepends - Show reverse dependency information for a package\n" - " pkgnames - List the names of all packages in the system\n" - " dotty - Generate package graphs for GraphViz\n" - " xvcg - Generate package graphs for xvcg\n" - " policy - Show policy settings\n" - "\n" - "Options:\n" + "from APT's binary cache files\n") + << std::endl; + ShowHelpListCommands(Cmds); + std::cout << std::endl + << _("Options:\n" " -h This help text.\n" " -p=? The package cache.\n" " -s=? The source cache.\n" @@ -1568,52 +1545,43 @@ static bool ShowHelp(CommandLine &) return true; } /*}}}*/ +std::vector GetCommands() /*{{{*/ +{ + return { + {"gencaches",&GenCaches, nullptr}, + {"showsrc",&ShowSrcPackage, _("Show source records")}, + {"showpkg",&DumpPackage, nullptr}, + {"stats",&Stats, nullptr}, + {"dump",&Dump, nullptr}, + {"dumpavail",&DumpAvail, nullptr}, + {"unmet",&UnMet, nullptr}, + {"search",&DoSearch, _("Search the package list for a regex pattern")}, + {"depends",&Depends, _("Show raw dependency information for a package")}, + {"rdepends",&RDepends, _("Show reverse dependency information for a package")}, + {"dotty",&Dotty, nullptr}, + {"xvcg",&XVcg, nullptr}, + {"show",&ShowPackage, _("Show a readable record for the package")}, + {"pkgnames",&ShowPkgNames, _("List the names of all packages in the system")}, + {"showauto",&ShowAuto, nullptr}, + {"policy",&Policy, _("Show policy settings")}, + {"madison",&Madison, nullptr}, + {nullptr, nullptr, nullptr} + }; +} + /*}}}*/ int main(int argc,const char *argv[]) /*{{{*/ { - CommandLine::Dispatch Cmds[] = {{"help",&ShowHelp}, - {"gencaches",&GenCaches}, - {"showsrc",&ShowSrcPackage}, - {"showpkg",&DumpPackage}, - {"stats",&Stats}, - {"dump",&Dump}, - {"dumpavail",&DumpAvail}, - {"unmet",&UnMet}, - {"search",&DoSearch}, - {"depends",&Depends}, - {"rdepends",&RDepends}, - {"dotty",&Dotty}, - {"xvcg",&XVcg}, - {"show",&ShowPackage}, - {"pkgnames",&ShowPkgNames}, - {"showauto",&ShowAuto}, - {"policy",&Policy}, - {"madison",&Madison}, - {0,0}}; - - std::vector Args = getCommandArgs("apt-cache", CommandLine::GetCommand(Cmds, argc, argv)); - - // Set up gettext support - setlocale(LC_ALL,""); - textdomain(PACKAGE); + 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); } /*}}}*/