]> git.saurik.com Git - apt.git/commitdiff
generate commands array after config is loaded
authorDavid Kalnischkies <david@kalnischkies.de>
Sun, 25 Oct 2015 22:45:09 +0000 (23:45 +0100)
committerDavid Kalnischkies <david@kalnischkies.de>
Wed, 4 Nov 2015 17:04:04 +0000 (18:04 +0100)
This ensures that location strings loaded from a location specified via
configuration (Dir::Locale) effect the help messages for commands.

Git-Dch: Ignore

15 files changed:
apt-private/private-cmndline.cc
apt-private/private-cmndline.h
cmdline/apt-cache.cc
cmdline/apt-cdrom.cc
cmdline/apt-config.cc
cmdline/apt-extracttemplates.cc
cmdline/apt-get.cc
cmdline/apt-helper.cc
cmdline/apt-internal-solver.cc
cmdline/apt-mark.cc
cmdline/apt-sortpkgs.cc
cmdline/apt.cc
ftparchive/apt-ftparchive.cc
test/libapt/commandline_test.cc
test/libapt/gtest_runner.cc

index a0acbbd79bd4d9406e92054b6d8265a5d836d587..c99a0afe01588096dfc761df9bf2e74804ef210a 100644 (file)
@@ -149,6 +149,11 @@ static bool addArgumentsAPTFTPArchive(std::vector<CommandLine::Args> &Args, char
 }
                                                                        /*}}}*/
 static bool addArgumentsAPTInternalSolver(std::vector<CommandLine::Args> &, char const * const)/*{{{*/
+{
+   return true;
+}
+                                                                       /*}}}*/
+static bool addArgumentsAPTHelper(std::vector<CommandLine::Args> &, char const * const)/*{{{*/
 {
    return true;
 }
@@ -315,34 +320,32 @@ static bool addArgumentsAPT(std::vector<CommandLine::Args> &Args, char const * c
    return true;
 }
                                                                        /*}}}*/
-std::vector<CommandLine::Args> getCommandArgs(char const * const Program, char const * const Cmd)/*{{{*/
+std::vector<CommandLine::Args> getCommandArgs(APT_CMD const Program, char const * const Cmd)/*{{{*/
 {
    std::vector<CommandLine::Args> Args;
    Args.reserve(50);
-   if (Program == NULL || Cmd == NULL)
-      ; // FIXME: Invalid command supplied
+   if (Cmd == nullptr)
+   {
+      if (Program == APT_CMD::APT_EXTRACTTEMPLATES)
+        addArgumentsAPTExtractTemplates(Args, Cmd);
+   }
    else if (strcmp(Cmd, "help") == 0)
       ; // no options for help so no need to implement it in each
-   else if (strcmp(Program, "apt-get") == 0)
-      addArgumentsAPTGet(Args, Cmd);
-   else if (strcmp(Program, "apt-cache") == 0)
-      addArgumentsAPTCache(Args, Cmd);
-   else if (strcmp(Program, "apt-cdrom") == 0)
-      addArgumentsAPTCDROM(Args, Cmd);
-   else if (strcmp(Program, "apt-config") == 0)
-      addArgumentsAPTConfig(Args, Cmd);
-   else if (strcmp(Program, "apt-extracttemplates") == 0)
-      addArgumentsAPTExtractTemplates(Args, Cmd);
-   else if (strcmp(Program, "apt-ftparchive") == 0)
-      addArgumentsAPTFTPArchive(Args, Cmd);
-   else if (strcmp(Program, "apt-internal-solver") == 0)
-      addArgumentsAPTInternalSolver(Args, Cmd);
-   else if (strcmp(Program, "apt-mark") == 0)
-      addArgumentsAPTMark(Args, Cmd);
-   else if (strcmp(Program, "apt-sortpkg") == 0)
-      addArgumentsAPTSortPkgs(Args, Cmd);
-   else if (strcmp(Program, "apt") == 0)
-      addArgumentsAPT(Args, Cmd);
+   else
+      switch (Program)
+      {
+        case APT_CMD::APT: addArgumentsAPT(Args, Cmd); break;
+        case APT_CMD::APT_GET: addArgumentsAPTGet(Args, Cmd); break;
+        case APT_CMD::APT_CACHE: addArgumentsAPTCache(Args, Cmd); break;
+        case APT_CMD::APT_CDROM: addArgumentsAPTCDROM(Args, Cmd); break;
+        case APT_CMD::APT_CONFIG: addArgumentsAPTConfig(Args, Cmd); break;
+        case APT_CMD::APT_EXTRACTTEMPLATES: addArgumentsAPTExtractTemplates(Args, Cmd); break;
+        case APT_CMD::APT_FTPARCHIVE: addArgumentsAPTFTPArchive(Args, Cmd); break;
+        case APT_CMD::APT_HELPER: addArgumentsAPTHelper(Args, Cmd); break;
+        case APT_CMD::APT_INTERNAL_SOLVER: addArgumentsAPTInternalSolver(Args, Cmd); break;
+        case APT_CMD::APT_MARK: addArgumentsAPTMark(Args, Cmd); break;
+        case APT_CMD::APT_SORTPKG: addArgumentsAPTSortPkgs(Args, Cmd); break;
+      }
 
    // options without a command
    addArg('h', "help", "help", 0);
@@ -380,19 +383,9 @@ static void BinarySpecificConfiguration(char const * const Binary) /*{{{*/
    _config->MoveSubTree(conf.c_str(), NULL);
 }
                                                                        /*}}}*/
-void ParseCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * Cmds, char const * const Binary,/*{{{*/
-      Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char *argv[], bool(*ShowHelp)(CommandLine &, CommandLine::DispatchWithHelp const *))
+std::vector<CommandLine::DispatchWithHelp> ParseCommandLine(CommandLine &CmdL, APT_CMD const Binary,/*{{{*/
+      Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char *argv[])
 {
-   // Args running out of scope invalidates the pointer stored in CmdL,
-   // but we don't use the pointer after this function, so we ignore
-   // this problem for now and figure something out if we have to.
-   std::vector<CommandLine::Args> Args;
-   if (Cmds != nullptr && Cmds[0].Handler != nullptr)
-      Args = getCommandArgs(Binary, CommandLine::GetCommand(Cmds, argc, argv));
-   else
-      Args = getCommandArgs(Binary, Binary);
-   CmdL = CommandLine(Args.data(), _config);
-
    if (Cnf != NULL && pkgInitConfig(**Cnf) == false)
    {
       _error->DumpErrors();
@@ -402,11 +395,22 @@ void ParseCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * C
    if (likely(argc != 0 && argv[0] != NULL))
       BinarySpecificConfiguration(argv[0]);
 
+   std::vector<CommandLine::DispatchWithHelp> const Cmds = GetCommands();
+   // Args running out of scope invalidates the pointer stored in CmdL,
+   // but we don't use the pointer after this function, so we ignore
+   // this problem for now and figure something out if we have to.
+   std::vector<CommandLine::Args> Args;
+   if (Cmds.empty() == false && Cmds[0].Handler != nullptr)
+      Args = getCommandArgs(Binary, CommandLine::GetCommand(Cmds.data(), argc, argv));
+   else
+      Args = getCommandArgs(Binary, nullptr);
+   CmdL = CommandLine(Args.data(), _config);
+
    if (CmdL.Parse(argc,argv) == false ||
        (Sys != NULL && pkgInitSystem(*_config, *Sys) == false))
    {
       if (_config->FindB("version") == true)
-        ShowHelp(CmdL, Cmds);
+        ShowHelp(CmdL, Cmds.data());
 
       _error->DumpErrors();
       exit(100);
@@ -416,20 +420,21 @@ void ParseCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * C
    if (_config->FindB("help") == true || _config->FindB("version") == true ||
         (CmdL.FileSize() > 0 && strcmp(CmdL.FileList[0], "help") == 0))
    {
-      ShowHelp(CmdL, Cmds);
+      ShowHelp(CmdL, Cmds.data());
       exit(0);
    }
-   if (Cmds != nullptr && CmdL.FileSize() == 0)
+   if (Cmds.empty() == false && CmdL.FileSize() == 0)
    {
-      ShowHelp(CmdL, Cmds);
+      ShowHelp(CmdL, Cmds.data());
       exit(1);
    }
+   return Cmds;
 }
                                                                        /*}}}*/
-unsigned short DispatchCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * const Cmds)        /*{{{*/
+unsigned short DispatchCommandLine(CommandLine &CmdL, std::vector<CommandLine::DispatchWithHelp> const &Cmds)  /*{{{*/
 {
    // Match the operation
-   bool const returned = (Cmds != nullptr) ? CmdL.DispatchArg(Cmds) : true;
+   bool const returned = Cmds.empty() ? true : CmdL.DispatchArg(Cmds.data());
 
    // Print any errors or warnings found during parsing
    bool const Errors = _error->PendingError();
index 5674088bcc2abef3b1ec8b521f2724b7e617ff1d..aee679bf899c93a81383825d0a9827ec67fdc34f 100644 (file)
@@ -9,10 +9,27 @@
 class Configuration;
 class pkgSystem;
 
-APT_PUBLIC std::vector<CommandLine::Args> getCommandArgs(char const * const Program, char const * const Cmd);
-APT_PUBLIC void ParseCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * Cmds, char const * const Binary,
-      Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char * argv[],
-      bool(*ShowHelp)(CommandLine &, CommandLine::DispatchWithHelp const *));
-APT_PUBLIC unsigned short DispatchCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * const Cmds);
+enum class APT_CMD {
+   APT,
+   APT_GET,
+   APT_CACHE,
+   APT_CDROM,
+   APT_CONFIG,
+   APT_EXTRACTTEMPLATES,
+   APT_FTPARCHIVE,
+   APT_HELPER,
+   APT_INTERNAL_SOLVER,
+   APT_MARK,
+   APT_SORTPKG,
+};
+
+bool ShowHelp(CommandLine &CmdL, CommandLine::DispatchWithHelp const * Cmds);
+std::vector<CommandLine::DispatchWithHelp> GetCommands();
+
+APT_PUBLIC std::vector<CommandLine::DispatchWithHelp> ParseCommandLine(CommandLine &CmdL, APT_CMD const Binary,
+      Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char * argv[]);
+APT_PUBLIC unsigned short DispatchCommandLine(CommandLine &CmdL, std::vector<CommandLine::DispatchWithHelp> const &Cmds);
+
+APT_PUBLIC std::vector<CommandLine::Args> getCommandArgs(APT_CMD const Program, char const * const Cmd);
 
 #endif
index 67e4a852345d29dd8bea875c6300156d371ea497..2933db21850e64939f31a5526cc72ac52171b423 100644 (file)
@@ -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();
 
index 3fc3faf4afe1960f0846ad2d86ef56eefc36b8bb..397ff2b65abc69e56b8562843a4b0611221e1a3a 100644 (file)
@@ -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();
 
index 3ccfa9a95bfd61f3787281ee48f3885a62d35260..9d80e4ebf3f994dbbfc19ac32108d04649c1d9f1 100644 (file)
@@ -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");
index e28b42870146cee261dbff00dae705cc47698cfb..c5c37d122e506a2f825456f4a259e749ba80fca4 100644 (file)
@@ -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, {});
 }
                                                                        /*}}}*/
index 2a19360c8b6b74db81ca7b9829abb17211dfc5e3..fd7f045c68eadb282e56179618e32c9d2db474b0 100644 (file)
@@ -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();
index 186fded17b82ac2d26b2e2d88f16a6ac8c38cc11..aef10828de8a917ac25c2d4b43dab1ee44f2679c 100644 (file)
@@ -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();
 
index 278f6d47176bb5856f35f58285705e5b05c6f108..f6eaa11f7023a92f0ce6d6453f7a8ff0bed8ae18 100644 (file)
@@ -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, {});
 }
                                                                        /*}}}*/
index 0a5bb164afe1b5603bd81381f31885df2adbcd85..c49476c7c035917bccd48a7d75f52bcfba076916 100644 (file)
@@ -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();
 
index 93aa5a76b64af90fc03851aceba793c9e0995079..82c9c333de2a4ebb7d08d5cbbdb685c11c37cdfa 100644 (file)
@@ -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, {});
 }
                                                                        /*}}}*/
index eb16b561c36cd5cb79b14630712409d92227cbeb..e32a9f1e3b98a5b3b629979cc4d2f912d328b581 100644 (file)
@@ -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)
index ca03080ca221c584119220accb9a5f660000666b..f53958ceb3f9248df121920cd024a282051f39d1 100644 (file)
@@ -605,9 +605,7 @@ static void LoadBinDir(vector<PackageMap> &PkgList,Configuration &Setup)
                                                                        /*}}}*/
 
 // ShowHelp - Show the help text                                       /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *)
+bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *)
 {
    ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
    if (_config->FindB("version") == true)
@@ -1025,11 +1023,9 @@ static bool Clean(CommandLine &CmdL)
 }
                                                                        /*}}}*/
 
-int main(int argc, const char *argv[])
+std::vector<CommandLine::DispatchWithHelp> GetCommands()               /*{{{*/
 {
-   InitLocale();
-
-   CommandLine::DispatchWithHelp Cmds[] = {
+   return {
       {"packages",&SimpleGenPackages, nullptr},
       {"contents",&SimpleGenContents, nullptr},
       {"sources",&SimpleGenSources, nullptr},
@@ -1038,10 +1034,15 @@ int main(int argc, const char *argv[])
       {"clean",&Clean, 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-ftparchive", &_config, NULL, argc, argv, ShowHelp);
+   auto const Cmds = ParseCommandLine(CmdL, APT_CMD::APT_FTPARCHIVE, &_config, NULL, argc, argv);
 
    _config->CndSet("quiet",0);
    Quiet = _config->FindI("quiet",0);
@@ -1049,3 +1050,4 @@ int main(int argc, const char *argv[])
 
    return DispatchCommandLine(CmdL, Cmds);
 }
+                                                                       /*}}}*/
index 627f1b486312345916c1035922d4c06af4781565..0da2ba45fa9d9ea2041e409b9e1c82754f052e2d 100644 (file)
@@ -96,7 +96,7 @@ TEST(CommandLineTest,GetCommand)
    char const * argv[] = { "apt-get", "-t", "unstable", "remove", "-d", "foo" };
    char const * com = CommandLine::GetCommand(Cmds, sizeof(argv)/sizeof(argv[0]), argv);
    EXPECT_STREQ("remove", com);
-   std::vector<CommandLine::Args> Args = getCommandArgs("apt-get", com);
+   std::vector<CommandLine::Args> Args = getCommandArgs(APT_CMD::APT_GET, com);
    ::Configuration c;
    CommandLine CmdL(Args.data(), &c);
    ASSERT_TRUE(CmdL.Parse(sizeof(argv)/sizeof(argv[0]), argv));
@@ -110,7 +110,7 @@ TEST(CommandLineTest,GetCommand)
    char const * argv[] = {"apt-get", "-t", "unstable", "remove", "--", "-d", "foo" };
    char const * com = CommandLine::GetCommand(Cmds, sizeof(argv)/sizeof(argv[0]), argv);
    EXPECT_STREQ("remove", com);
-   std::vector<CommandLine::Args> Args = getCommandArgs("apt-get", com);
+   std::vector<CommandLine::Args> Args = getCommandArgs(APT_CMD::APT_GET, com);
    ::Configuration c;
    CommandLine CmdL(Args.data(), &c);
    ASSERT_TRUE(CmdL.Parse(sizeof(argv)/sizeof(argv[0]), argv));
@@ -125,7 +125,7 @@ TEST(CommandLineTest,GetCommand)
    char const * argv[] = {"apt-get", "-t", "unstable", "--", "remove", "-d", "foo" };
    char const * com = CommandLine::GetCommand(Cmds, sizeof(argv)/sizeof(argv[0]), argv);
    EXPECT_STREQ("remove", com);
-   std::vector<CommandLine::Args> Args = getCommandArgs("apt-get", com);
+   std::vector<CommandLine::Args> Args = getCommandArgs(APT_CMD::APT_GET, com);
    ::Configuration c;
    CommandLine CmdL(Args.data(), &c);
    ASSERT_TRUE(CmdL.Parse(sizeof(argv)/sizeof(argv[0]), argv));
@@ -140,7 +140,7 @@ TEST(CommandLineTest,GetCommand)
    char const * argv[] = {"apt-get", "install", "-t", "unstable", "--", "remove", "-d", "foo" };
    char const * com = CommandLine::GetCommand(Cmds, sizeof(argv)/sizeof(argv[0]), argv);
    EXPECT_STREQ("install", com);
-   std::vector<CommandLine::Args> Args = getCommandArgs("apt-get", com);
+   std::vector<CommandLine::Args> Args = getCommandArgs(APT_CMD::APT_GET, com);
    ::Configuration c;
    CommandLine CmdL(Args.data(), &c);
    ASSERT_TRUE(CmdL.Parse(sizeof(argv)/sizeof(argv[0]), argv));
index 5823c55de65de4d72e20d39a94be587417b02dd3..29f6313269deb9ab390a8293ba8524422e503877 100644 (file)
@@ -1,5 +1,11 @@
 #include <gtest/gtest.h>
+
 #include <apt-pkg/error.h>
+#include <apt-pkg/cmndline.h>
+
+bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *) {return false;}
+std::vector<CommandLine::DispatchWithHelp> GetCommands() {return {};}
+
 int main(int argc, char **argv) {
    ::testing::InitGoogleTest(&argc, argv);
    int result = RUN_ALL_TESTS();