diff options
author | David Kalnischkies <david@kalnischkies.de> | 2015-10-25 23:45:09 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2015-11-04 18:04:04 +0100 |
commit | 011188e3920f21e6883c2dab956b3d4fb4e8cbfa (patch) | |
tree | 9649094789cf2369d82758e24995feb2b0bed59c /cmdline | |
parent | 2b0660b537581e9e65180e4cf1a94d763fd66847 (diff) |
generate commands array after config is loaded
This ensures that location strings loaded from a location specified via
configuration (Dir::Locale) effect the help messages for commands.
Git-Dch: Ignore
Diffstat (limited to 'cmdline')
-rw-r--r-- | cmdline/apt-cache.cc | 15 | ||||
-rw-r--r-- | cmdline/apt-cdrom.cc | 15 | ||||
-rw-r--r-- | cmdline/apt-config.cc | 17 | ||||
-rw-r--r-- | cmdline/apt-extracttemplates.cc | 17 | ||||
-rw-r--r-- | cmdline/apt-get.cc | 17 | ||||
-rw-r--r-- | cmdline/apt-helper.cc | 31 | ||||
-rw-r--r-- | cmdline/apt-internal-solver.cc | 13 | ||||
-rw-r--r-- | cmdline/apt-mark.cc | 15 | ||||
-rw-r--r-- | cmdline/apt-sortpkgs.cc | 17 | ||||
-rw-r--r-- | cmdline/apt.cc | 17 |
10 files changed, 99 insertions, 75 deletions
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 67e4a8523..2933db218 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -1523,7 +1523,7 @@ static bool GenCaches(CommandLine &) } /*}}}*/ // ShowHelp - Show a help screen /*{{{*/ -static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) +bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) { ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); @@ -1558,11 +1558,9 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) return true; } /*}}}*/ -int main(int argc,const char *argv[]) /*{{{*/ +std::vector<CommandLine::DispatchWithHelp> GetCommands() /*{{{*/ { - InitLocale(); - - CommandLine::DispatchWithHelp Cmds[] = { + return { {"gencaches",&GenCaches, nullptr}, {"showsrc",&ShowSrcPackage, _("Show source records")}, {"showpkg",&DumpPackage, nullptr}, @@ -1582,10 +1580,15 @@ int main(int argc,const char *argv[]) /*{{{*/ {"madison",&Madison, nullptr}, {nullptr, nullptr, nullptr} }; +} + /*}}}*/ +int main(int argc,const char *argv[]) /*{{{*/ +{ + InitLocale(); // Parse the command line and initialize the package library CommandLine CmdL; - ParseCommandLine(CmdL, Cmds, "apt-cache", &_config, &_system, argc, argv, ShowHelp); + auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_CACHE, &_config, &_system, argc, argv); InitOutput(); diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index 3fc3faf4a..397ff2b65 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -204,7 +204,7 @@ static bool DoIdent(CommandLine &) } /*}}}*/ // ShowHelp - Show the help screen /*{{{*/ -static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) +bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) { ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); @@ -241,19 +241,22 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) return true; } /*}}}*/ -int main(int argc,const char *argv[]) /*{{{*/ +std::vector<CommandLine::DispatchWithHelp> GetCommands() /*{{{*/ { - InitLocale(); - - CommandLine::DispatchWithHelp Cmds[] = { + return { {"add", &DoAdd, "Add a CDROM"}, {"ident", &DoIdent, "Report the identity of a CDROM"}, {nullptr, nullptr, nullptr} }; +} + /*}}}*/ +int main(int argc,const char *argv[]) /*{{{*/ +{ + InitLocale(); // Parse the command line and initialize the package library CommandLine CmdL; - ParseCommandLine(CmdL, Cmds, "apt-cdrom", &_config, &_system, argc, argv, ShowHelp); + auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_CDROM, &_config, &_system, argc, argv); InitOutput(); diff --git a/cmdline/apt-config.cc b/cmdline/apt-config.cc index 3ccfa9a95..9d80e4ebf 100644 --- a/cmdline/apt-config.cc +++ b/cmdline/apt-config.cc @@ -77,9 +77,7 @@ static bool DoDump(CommandLine &CmdL) } /*}}}*/ // ShowHelp - Show the help screen /*{{{*/ -// --------------------------------------------------------------------- -/* */ -static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) +bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) { ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); if (_config->FindB("version") == true) @@ -106,19 +104,22 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) return true; } /*}}}*/ -int main(int argc,const char *argv[]) /*{{{*/ +std::vector<CommandLine::DispatchWithHelp> GetCommands() /*{{{*/ { - InitLocale(); - - CommandLine::DispatchWithHelp Cmds[] = { + return { {"shell", &DoShell, _("get configuration values via shell evaluation")}, {"dump", &DoDump, _("show the active configuration setting")}, {nullptr, nullptr, nullptr} }; +} + /*}}}*/ +int main(int argc,const char *argv[]) /*{{{*/ +{ + InitLocale(); // Parse the command line and initialize the package library CommandLine CmdL; - ParseCommandLine(CmdL, Cmds, "apt-config", &_config, &_system, argc, argv, ShowHelp); + auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_CONFIG, &_config, &_system, argc, argv); std::vector<std::string> const langs = APT::Configuration::getLanguages(true); _config->Clear("Acquire::Languages"); diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc index e28b42870..c5c37d122 100644 --- a/cmdline/apt-extracttemplates.cc +++ b/cmdline/apt-extracttemplates.cc @@ -216,9 +216,7 @@ bool DebFile::ParseInfo() } /*}}}*/ // ShowHelp - show a short help text /*{{{*/ -// --------------------------------------------------------------------- -/* */ -static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *) +bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *) { ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); @@ -343,17 +341,22 @@ static bool Go(CommandLine &CmdL) return !_error->PendingError(); } /*}}}*/ +std::vector<CommandLine::DispatchWithHelp> GetCommands() /*{{{*/ +{ + return { + {nullptr, nullptr, nullptr} + }; +} + /*}}}*/ int main(int argc, const char **argv) /*{{{*/ { InitLocale(); - // Parse the command line and initialize the package library - CommandLine::DispatchWithHelp Cmds[] = {{nullptr, nullptr, nullptr}}; CommandLine CmdL; - ParseCommandLine(CmdL, Cmds, "apt-extracttemplates", &_config, &_system, argc, argv, ShowHelp); + auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_EXTRACTTEMPLATES, &_config, &_system, argc, argv); Go(CmdL); - return DispatchCommandLine(CmdL, nullptr); + return DispatchCommandLine(CmdL, {}); } /*}}}*/ diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 2a19360c8..fd7f045c6 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -1527,9 +1527,7 @@ static bool DoIndexTargets(CommandLine &CmdL) } /*}}}*/ // ShowHelp - Show a help screen /*{{{*/ -// --------------------------------------------------------------------- -/* */ -static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) +bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) { ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); @@ -1613,11 +1611,9 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) return true; } /*}}}*/ -int main(int argc,const char *argv[]) /*{{{*/ +std::vector<CommandLine::DispatchWithHelp> GetCommands() /*{{{*/ { - InitLocale(); - - CommandLine::DispatchWithHelp Cmds[] = { + return { {"update", &DoUpdate, _("Retrieve new lists of packages")}, {"upgrade", &DoUpgrade, _("Perform an upgrade")}, {"install", &DoInstall, _("Install new packages (pkg is libc6 not libc6.deb)")}, @@ -1642,10 +1638,15 @@ int main(int argc,const char *argv[]) /*{{{*/ {"moo", &DoMoo, nullptr}, {nullptr, nullptr, nullptr} }; +} + /*}}}*/ +int main(int argc,const char *argv[]) /*{{{*/ +{ + InitLocale(); // Parse the command line and initialize the package library CommandLine CmdL; - ParseCommandLine(CmdL, Cmds, "apt-get", &_config, &_system, argc, argv, ShowHelp); + auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_GET, &_config, &_system, argc, argv); InitSignals(); InitOutput(); diff --git a/cmdline/apt-helper.cc b/cmdline/apt-helper.cc index 186fded17..aef10828d 100644 --- a/cmdline/apt-helper.cc +++ b/cmdline/apt-helper.cc @@ -32,7 +32,7 @@ #include <apti18n.h> /*}}}*/ -static bool DoAutoDetectProxy(CommandLine &CmdL) +static bool DoAutoDetectProxy(CommandLine &CmdL) /*{{{*/ { if (CmdL.FileSize() != 2) return _error->Error(_("Need one URL as argument")); @@ -44,8 +44,8 @@ static bool DoAutoDetectProxy(CommandLine &CmdL) return true; } - -static bool DoDownloadFile(CommandLine &CmdL) + /*}}}*/ +static bool DoDownloadFile(CommandLine &CmdL) /*{{{*/ { if (CmdL.FileSize() <= 2) return _error->Error(_("Must specify at least one pair url/filename")); @@ -77,8 +77,8 @@ static bool DoDownloadFile(CommandLine &CmdL) return true; } - -static bool DoSrvLookup(CommandLine &CmdL) + /*}}}*/ +static bool DoSrvLookup(CommandLine &CmdL) /*{{{*/ { if (CmdL.FileSize() <= 1) return _error->Error("Must specify at least one SRV record"); @@ -104,8 +104,8 @@ static bool DoSrvLookup(CommandLine &CmdL) } return true; } - -static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) + /*}}}*/ +bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)/*{{{*/ { ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); @@ -131,22 +131,23 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) _("This APT helper has Super Meep Powers.") << std::endl; return true; } - - -int main(int argc,const char *argv[]) /*{{{*/ + /*}}}*/ +std::vector<CommandLine::DispatchWithHelp> GetCommands() /*{{{*/ { - InitLocale(); - - CommandLine::DispatchWithHelp Cmds[] = { + return { {"download-file", &DoDownloadFile, _("download the given uri to the target-path")}, {"srv-lookup", &DoSrvLookup, _("lookup a SRV record (e.g. _http._tcp.ftp.debian.org)")}, {"auto-detect-proxy", &DoAutoDetectProxy, _("detect proxy using apt.conf")}, {nullptr, nullptr, nullptr} }; +} + /*}}}*/ +int main(int argc,const char *argv[]) /*{{{*/ +{ + InitLocale(); - // Parse the command line and initialize the package library CommandLine CmdL; - ParseCommandLine(CmdL, Cmds, "apt-helper", &_config, &_system, argc, argv, ShowHelp); + auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_HELPER, &_config, &_system, argc, argv); InitOutput(); diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc index 278f6d471..f6eaa11f7 100644 --- a/cmdline/apt-internal-solver.cc +++ b/cmdline/apt-internal-solver.cc @@ -42,9 +42,7 @@ /*}}}*/ // ShowHelp - Show a help screen /*{{{*/ -// --------------------------------------------------------------------- -/* */ -static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *) { +bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *) { ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); std::cout << @@ -67,6 +65,11 @@ APT_NORETURN static void DIE(std::string const &message) { /*{{{*/ exit(EXIT_FAILURE); } /*}}}*/ +std::vector<CommandLine::DispatchWithHelp> GetCommands() /*{{{*/ +{ + return {}; +} + /*}}}*/ int main(int argc,const char *argv[]) /*{{{*/ { InitLocale(); @@ -75,7 +78,7 @@ int main(int argc,const char *argv[]) /*{{{*/ DropPrivileges(); CommandLine CmdL; - ParseCommandLine(CmdL, nullptr, "apt-internal-solver", &_config, NULL, argc, argv, ShowHelp); + ParseCommandLine(CmdL, APT_CMD::APT_INTERNAL_SOLVER, &_config, NULL, argc, argv); if (CmdL.FileList[0] != 0 && strcmp(CmdL.FileList[0], "scenario") == 0) { @@ -182,6 +185,6 @@ int main(int argc,const char *argv[]) /*{{{*/ EDSP::WriteProgress(100, "Done", output); - return DispatchCommandLine(CmdL, nullptr); + return DispatchCommandLine(CmdL, {}); } /*}}}*/ diff --git a/cmdline/apt-mark.cc b/cmdline/apt-mark.cc index 0a5bb164a..c49476c7c 100644 --- a/cmdline/apt-mark.cc +++ b/cmdline/apt-mark.cc @@ -281,7 +281,7 @@ static bool ShowSelection(CommandLine &CmdL) /*{{{*/ } /*}}}*/ // ShowHelp - Show a help screen /*{{{*/ -static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) +bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) { ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); @@ -314,11 +314,9 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) return true; } /*}}}*/ -int main(int argc,const char *argv[]) /*{{{*/ +std::vector<CommandLine::DispatchWithHelp> GetCommands() /*{{{*/ { - InitLocale(); - - CommandLine::DispatchWithHelp Cmds[] = { + return { {"auto",&DoAuto, _("Mark the given packages as automatically installed")}, {"manual",&DoAuto, _("Mark the given packages as manually installed")}, {"hold",&DoSelection, _("Mark a package as held back")}, @@ -339,9 +337,14 @@ int main(int argc,const char *argv[]) /*{{{*/ {"unmarkauto", &DoMarkAuto, nullptr}, {nullptr, nullptr, nullptr} }; +} + /*}}}*/ +int main(int argc,const char *argv[]) /*{{{*/ +{ + InitLocale(); CommandLine CmdL; - ParseCommandLine(CmdL, Cmds, "apt-mark", &_config, &_system, argc, argv, ShowHelp); + auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_MARK, &_config, &_system, argc, argv); InitOutput(); diff --git a/cmdline/apt-sortpkgs.cc b/cmdline/apt-sortpkgs.cc index 93aa5a76b..82c9c333d 100644 --- a/cmdline/apt-sortpkgs.cc +++ b/cmdline/apt-sortpkgs.cc @@ -133,9 +133,7 @@ static bool DoIt(string InFile) } /*}}}*/ // ShowHelp - Show the help text /*{{{*/ -// --------------------------------------------------------------------- -/* */ -static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *) +bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *) { ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); if (_config->FindB("version") == true) @@ -156,20 +154,25 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *) return true; } /*}}}*/ +std::vector<CommandLine::DispatchWithHelp> GetCommands() /*{{{*/ +{ + return { + {nullptr, nullptr, nullptr} + }; +} + /*}}}*/ int main(int argc,const char *argv[]) /*{{{*/ { InitLocale(); - // Parse the command line and initialize the package library - CommandLine::DispatchWithHelp Cmds[] = {{nullptr, nullptr, nullptr}}; CommandLine CmdL; - ParseCommandLine(CmdL, Cmds, "apt-sortpkgs", &_config, &_system, argc, argv, ShowHelp); + ParseCommandLine(CmdL, APT_CMD::APT_SORTPKG, &_config, &_system, argc, argv); // Match the operation for (unsigned int I = 0; I != CmdL.FileSize(); I++) if (DoIt(CmdL.FileList[I]) == false) break; - return DispatchCommandLine(CmdL, nullptr); + return DispatchCommandLine(CmdL, {}); } /*}}}*/ diff --git a/cmdline/apt.cc b/cmdline/apt.cc index eb16b561c..e32a9f1e3 100644 --- a/cmdline/apt.cc +++ b/cmdline/apt.cc @@ -37,7 +37,7 @@ #include <apti18n.h> /*}}}*/ -static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) +bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)/*{{{*/ { ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH); @@ -57,12 +57,10 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds) return true; } - -int main(int argc, const char *argv[]) /*{{{*/ + /*}}}*/ +std::vector<CommandLine::DispatchWithHelp> GetCommands() /*{{{*/ { - InitLocale(); - - CommandLine::DispatchWithHelp Cmds[] = { + return { // query {"list", &DoList, _("list packages based on package names")}, {"search", &DoSearch, _("search in package descriptions")}, @@ -86,9 +84,14 @@ int main(int argc, const char *argv[]) /*{{{*/ {"moo", &DoMoo, nullptr}, {nullptr, nullptr, nullptr} }; +} + /*}}}*/ +int main(int argc, const char *argv[]) /*{{{*/ +{ + InitLocale(); CommandLine CmdL; - ParseCommandLine(CmdL, Cmds, "apt", &_config, &_system, argc, argv, ShowHelp); + auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT, &_config, &_system, argc, argv); int const quiet = _config->FindI("quiet", 0); if (quiet == 2) |