]> git.saurik.com Git - apt.git/commitdiff
deduplicate main methods
authorDavid Kalnischkies <david@kalnischkies.de>
Sat, 24 Oct 2015 20:43:37 +0000 (22:43 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Wed, 4 Nov 2015 17:04:03 +0000 (18:04 +0100)
All mains pretty much do the same thing, so lets try a little harder to
move the common parts into -private to have the real differences more
visible.

Git-Dch: Ignore

17 files changed:
apt-pkg/contrib/cmndline.cc
apt-pkg/contrib/cmndline.h
apt-private/private-cmndline.cc
apt-private/private-cmndline.h
apt-private/private-main.cc
apt-private/private-main.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

index 60ce90f1f839507d435f9fadbc8548fa25a59b6a..d299bbbdfd74a04c709def4552aa3ea333d6a9e4 100644 (file)
@@ -411,7 +411,7 @@ unsigned int CommandLine::FileSize() const
 }
                                                                        /*}}}*/
 // CommandLine::DispatchArg - Do something with the first arg          /*{{{*/
-bool CommandLine::DispatchArg(DispatchWithHelp *Map,bool NoMatch)
+bool CommandLine::DispatchArg(DispatchWithHelp const * const Map,bool NoMatch)
 {
    int I;
    for (I = 0; Map[I].Match != 0; I++)
index a698a18b84f55f79b0b0aa068420578ee50d760e..33d9f9f3ad64cfd829978b4ca2c2aa63704a8364 100644 (file)
@@ -85,7 +85,7 @@ class CommandLine
    void ShowHelp();
    unsigned int FileSize() const APT_PURE;
    bool DispatchArg(Dispatch *List,bool NoMatch = true);
-   bool DispatchArg(DispatchWithHelp *List,bool NoMatch = true);
+   bool DispatchArg(DispatchWithHelp const * const List,bool NoMatch = true);
       
    static char const * GetCommand(Dispatch const * const Map,
         unsigned int const argc, char const * const * const argv) APT_PURE;
index 265c5d4823475394d23fe5e0bf61823ffd3dc19a..a0acbbd79bd4d9406e92054b6d8265a5d836d587 100644 (file)
@@ -124,6 +124,32 @@ static bool addArgumentsAPTConfig(std::vector<CommandLine::Args> &Args, char con
    else
       return false;
 
+   return true;
+}
+                                                                       /*}}}*/
+static bool addArgumentsAPTExtractTemplates(std::vector<CommandLine::Args> &Args, char const * const)/*{{{*/
+{
+   addArg('t',"tempdir","APT::ExtractTemplates::TempDir",CommandLine::HasArg);
+   return true;
+}
+                                                                       /*}}}*/
+static bool addArgumentsAPTFTPArchive(std::vector<CommandLine::Args> &Args, char const * const)/*{{{*/
+{
+   addArg(0,"md5","APT::FTPArchive::MD5",0);
+   addArg(0,"sha1","APT::FTPArchive::SHA1",0);
+   addArg(0,"sha256","APT::FTPArchive::SHA256",0);
+   addArg(0,"sha512","APT::FTPArchive::SHA512",0);
+   addArg('d',"db","APT::FTPArchive::DB",CommandLine::HasArg);
+   addArg('s',"source-override","APT::FTPArchive::SourceOverride",CommandLine::HasArg);
+   addArg(0,"delink","APT::FTPArchive::DeLinkAct",0);
+   addArg(0,"readonly","APT::FTPArchive::ReadOnlyDB",0);
+   addArg(0,"contents","APT::FTPArchive::Contents",0);
+   addArg('a',"arch","APT::FTPArchive::Architecture",CommandLine::HasArg);
+   return true;
+}
+                                                                       /*}}}*/
+static bool addArgumentsAPTInternalSolver(std::vector<CommandLine::Args> &, char const * const)/*{{{*/
+{
    return true;
 }
                                                                        /*}}}*/
@@ -254,6 +280,12 @@ static bool addArgumentsAPTMark(std::vector<CommandLine::Args> &Args, char const
       addArg('s',"no-act","APT::Mark::Simulate",0);
    }
 
+   return true;
+}
+                                                                       /*}}}*/
+static bool addArgumentsAPTSortPkgs(std::vector<CommandLine::Args> &Args, char const * const)/*{{{*/
+{
+   addArg('s',"source","APT::SortPkgs::Source",0);
    return true;
 }
                                                                        /*}}}*/
@@ -299,8 +331,16 @@ std::vector<CommandLine::Args> getCommandArgs(char const * const Program, char c
       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);
 
@@ -340,10 +380,19 @@ static void BinarySpecificConfiguration(char const * const Binary)        /*{{{*/
    _config->MoveSubTree(conf.c_str(), NULL);
 }
                                                                        /*}}}*/
-void ParseCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * Cmds, CommandLine::Args * const Args,/*{{{*/
+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 *))
 {
-   CmdL = CommandLine(Args,_config);
+   // 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();
@@ -377,3 +426,19 @@ void ParseCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * C
    }
 }
                                                                        /*}}}*/
+unsigned short DispatchCommandLine(CommandLine &CmdL, CommandLine::DispatchWithHelp const * const Cmds)        /*{{{*/
+{
+   // Match the operation
+   bool const returned = (Cmds != nullptr) ? CmdL.DispatchArg(Cmds) : true;
+
+   // 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);
+   if (returned == false)
+      return 100;
+   return Errors == true ? 100 : 0;
+}
+                                                                       /*}}}*/
index 0d6c0bba6ee311fddfa515f88c6853d05390bb8e..5674088bcc2abef3b1ec8b521f2724b7e617ff1d 100644 (file)
@@ -10,8 +10,9 @@ 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, CommandLine::Args * const Args,
+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);
 
 #endif
index 3886c7df65474a2ac394ca66d07e14790ddda7c4..9eb306834c5de2d616b4329a6da3e512b9710e0b 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <apt-pkg/cmndline.h>
 #include <apt-pkg/configuration.h>
+#include <apt-pkg/fileutl.h>
 
 #include <apt-private/private-main.h>
 
 #include <apti18n.h>
 
 
-void InitSignals()
+void InitLocale()                                                      /*{{{*/
+{
+   setlocale(LC_ALL,"");
+   textdomain(PACKAGE);
+}
+                                                                       /*}}}*/
+void InitSignals()                                                     /*{{{*/
 {
-   // Setup the signals
    signal(SIGPIPE,SIG_IGN);
 }
-
-
-void CheckSimulateMode(CommandLine &CmdL)
+                                                                       /*}}}*/
+void CheckIfSimulateMode(CommandLine &CmdL)                            /*{{{*/
 {
    // disable locking in simulation, but show the message only for users
    // as root hasn't the same problems like unreadable files which can heavily
@@ -39,3 +44,20 @@ void CheckSimulateMode(CommandLine &CmdL)
       _config->Set("Debug::NoLocking",true);
    }
 }
+                                                                       /*}}}*/
+void CheckIfCalledByScript(int argc, const char *argv[])               /*{{{*/
+{
+   if (unlikely(argc < 1)) return;
+
+   if(!isatty(STDOUT_FILENO) &&
+      _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
+   {
+      std::cerr << std::endl
+                << "WARNING: " << flNotDir(argv[0]) << " "
+                << "does not have a stable CLI interface. "
+                << "Use with caution in scripts."
+                << std::endl
+                << std::endl;
+   }
+}
+                                                                       /*}}}*/
index a03bf444145523c7dcc73c28b103a127e37fb724..db6d3e0b7011bfce1f76a4f44fb4d9fcc57c791e 100644 (file)
@@ -5,7 +5,9 @@
 
 class CommandLine;
 
-APT_PUBLIC void CheckSimulateMode(CommandLine &CmdL);
+APT_PUBLIC void InitLocale();
 APT_PUBLIC void InitSignals();
+APT_PUBLIC void CheckIfSimulateMode(CommandLine &CmdL);
+APT_PUBLIC void CheckIfCalledByScript(int argc, const char *argv[]);
 
 #endif
index 4b3a74922c69422dbaed2ed68056219277c4b8fb..67e4a852345d29dd8bea875c6300156d371ea497 100644 (file)
@@ -45,6 +45,7 @@
 #include <apt-private/private-cmndline.h>
 #include <apt-private/private-show.h>
 #include <apt-private/private-search.h>
+#include <apt-private/private-main.h>
 
 #include <regex.h>
 #include <stddef.h>
@@ -1559,6 +1560,8 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
                                                                        /*}}}*/
 int main(int argc,const char *argv[])                                  /*{{{*/
 {
+   InitLocale();
+
    CommandLine::DispatchWithHelp Cmds[] =  {
       {"gencaches",&GenCaches, nullptr},
       {"showsrc",&ShowSrcPackage, _("Show source records")},
@@ -1580,30 +1583,15 @@ int main(int argc,const char *argv[])                                   /*{{{*/
       {nullptr, nullptr, nullptr}
    };
 
-   std::vector<CommandLine::Args> Args = getCommandArgs("apt-cache", CommandLine::GetCommand(Cmds, argc, argv));
-
-   // Set up gettext support
-   setlocale(LC_ALL,"");
-   textdomain(PACKAGE);
-
    // Parse the command line and initialize the package library
    CommandLine CmdL;
-   ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
+   ParseCommandLine(CmdL, Cmds, "apt-cache", &_config, &_system, argc, argv, ShowHelp);
 
    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);
 }
                                                                        /*}}}*/
index 1838a76fedef5aa89883d40f1ad04bb08c454642..3fc3faf4afe1960f0846ad2d86ef56eefc36b8bb 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <apt-private/private-cmndline.h>
 #include <apt-private/private-output.h>
+#include <apt-private/private-main.h>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -242,31 +243,20 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
                                                                        /*}}}*/
 int main(int argc,const char *argv[])                                  /*{{{*/
 {
+   InitLocale();
+
    CommandLine::DispatchWithHelp Cmds[] = {
       {"add", &DoAdd, "Add a CDROM"},
       {"ident", &DoIdent, "Report the identity of a CDROM"},
       {nullptr, nullptr, nullptr}
    };
 
-   std::vector<CommandLine::Args> Args = getCommandArgs("apt-cdrom", CommandLine::GetCommand(Cmds, argc, argv));
-
-   // Set up gettext support
-   setlocale(LC_ALL,"");
-   textdomain(PACKAGE);
-
    // Parse the command line and initialize the package library
    CommandLine CmdL;
-   ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
+   ParseCommandLine(CmdL, Cmds, "apt-cdrom", &_config, &_system, argc, argv, ShowHelp);
 
    InitOutput();
 
-   // Match the operation
-   bool returned = CmdL.DispatchArg(Cmds);
-
-   if (_config->FindI("quiet",0) > 0)
-      _error->DumpErrors();
-   else
-      _error->DumpErrors(GlobalError::DEBUG);
-   return returned == true ? 0 : 100;
+   return DispatchCommandLine(CmdL, Cmds);
 }
                                                                        /*}}}*/
index e0383e0197978aadf6e3542aef659ac7a7cdeadb..3ccfa9a95bfd61f3787281ee48f3885a62d35260 100644 (file)
@@ -32,6 +32,7 @@
 #include <string.h>
 
 #include <apt-private/private-cmndline.h>
+#include <apt-private/private-main.h>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -107,21 +108,17 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
                                                                        /*}}}*/
 int main(int argc,const char *argv[])                                  /*{{{*/
 {
+   InitLocale();
+
    CommandLine::DispatchWithHelp Cmds[] = {
       {"shell", &DoShell, _("get configuration values via shell evaluation")},
       {"dump", &DoDump, _("show the active configuration setting")},
       {nullptr, nullptr, nullptr}
    };
 
-   std::vector<CommandLine::Args> Args = getCommandArgs("apt-config", CommandLine::GetCommand(Cmds, argc, argv));
-
-   // Set up gettext support
-   setlocale(LC_ALL,"");
-   textdomain(PACKAGE);
-
    // Parse the command line and initialize the package library
    CommandLine CmdL;
-   ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
+   ParseCommandLine(CmdL, Cmds, "apt-config", &_config, &_system, argc, argv, ShowHelp);
 
    std::vector<std::string> const langs = APT::Configuration::getLanguages(true);
    _config->Clear("Acquire::Languages");
@@ -154,17 +151,6 @@ int main(int argc,const char *argv[])                                      /*{{{*/
    for (std::vector<std::string>::const_iterator p = profiles.begin(); p != profiles.end(); ++p)
       _config->Set("APT::Build-Profiles::", *p);
 
-   // Match the operation
-   CmdL.DispatchArg(Cmds);
-   
-   // Print any errors or warnings found during parsing
-   if (_error->empty() == false)
-   {
-      bool Errors = _error->PendingError();
-      _error->DumpErrors();
-      return Errors == true?100:0;
-   }
-   
-   return 0;
+   return DispatchCommandLine(CmdL, Cmds);
 }
                                                                        /*}}}*/
index cd52cfe3379edc262ed69d45ce89e4699a572834..e28b42870146cee261dbff00dae705cc47698cfb 100644 (file)
@@ -34,6 +34,7 @@
 #include <apt-pkg/mmap.h>
 
 #include <apt-private/private-cmndline.h>
+#include <apt-private/private-main.h>
 
 #include <iostream>
 #include <stdio.h>
@@ -344,34 +345,15 @@ static bool Go(CommandLine &CmdL)
                                                                        /*}}}*/
 int main(int argc, const char **argv)                                  /*{{{*/
 {
-       CommandLine::Args Args[] = {
-               {'h',"help","help",0},
-               {'v',"version","version",0},
-               {'t',"tempdir","APT::ExtractTemplates::TempDir",CommandLine::HasArg},
-               {'c',"config-file",0,CommandLine::ConfigFile},
-               {'o',"option",0,CommandLine::ArbItem},
-               {0,0,0,0}};
-
-       // Set up gettext support
-       setlocale(LC_ALL,"");
-       textdomain(PACKAGE);
+       InitLocale();
 
        // Parse the command line and initialize the package library
        CommandLine::DispatchWithHelp Cmds[] = {{nullptr, nullptr, nullptr}};
        CommandLine CmdL;
-       ParseCommandLine(CmdL, Cmds, Args, &_config, &_system, argc, argv, ShowHelp);
+       ParseCommandLine(CmdL, Cmds, "apt-extracttemplates", &_config, &_system, argc, argv, ShowHelp);
 
        Go(CmdL);
 
-       // Print any errors or warnings found during operation
-       if (_error->empty() == false)
-       {
-               // This goes to stderr..
-               bool Errors = _error->PendingError();
-               _error->DumpErrors();
-               return Errors == true?100:0;
-       }
-       
-       return 0;
+       return DispatchCommandLine(CmdL, nullptr);
 }
                                                                        /*}}}*/
index be5bc0851d0569d28e6a27432acd29e259311366..1379c607ed064c6398d3c60d0ca85c514fb93599 100644 (file)
@@ -1622,6 +1622,8 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
                                                                        /*}}}*/
 int main(int argc,const char *argv[])                                  /*{{{*/
 {
+   InitLocale();
+
    CommandLine::DispatchWithHelp Cmds[] = {
       {"update", &DoUpdate, _("Retrieve new lists of packages")},
       {"upgrade", &DoUpgrade, _("Perform an upgrade")},
@@ -1648,34 +1650,15 @@ int main(int argc,const char *argv[])                                   /*{{{*/
       {nullptr, nullptr, nullptr}
    };
 
-   std::vector<CommandLine::Args> Args = getCommandArgs("apt-get", CommandLine::GetCommand(Cmds, argc, argv));
-
-   // Set up gettext support
-   setlocale(LC_ALL,"");
-   textdomain(PACKAGE);
-
    // Parse the command line and initialize the package library
    CommandLine CmdL;
-   ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
+   ParseCommandLine(CmdL, Cmds, "apt-get", &_config, &_system, argc, argv, ShowHelp);
 
-   // see if we are in simulate mode
-   CheckSimulateMode(CmdL);
-
-   // Init the signals
    InitSignals();
-
-   // Setup the output streams
    InitOutput();
 
-   // Match the operation
-   CmdL.DispatchArg(Cmds);
+   CheckIfSimulateMode(CmdL);
 
-   // 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);
 }
                                                                        /*}}}*/
index 3df8588135e29c55f60df38a2c12e4f4faa6726c..ff9061dc79c3cafee4f365bb179528320b6f224d 100644 (file)
@@ -22,6 +22,7 @@
 #include <apt-private/private-output.h>
 #include <apt-private/private-download.h>
 #include <apt-private/private-cmndline.h>
+#include <apt-private/private-main.h>
 #include <apt-pkg/srvrec.h>
 
 #include <iostream>
@@ -136,6 +137,8 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const  * Cmds)
 
 int main(int argc,const char *argv[])                                  /*{{{*/
 {
+   InitLocale();
+
    CommandLine::DispatchWithHelp Cmds[] = {
       {"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)")},
@@ -143,28 +146,12 @@ int main(int argc,const char *argv[])                                     /*{{{*/
       {nullptr, nullptr, nullptr}
    };
 
-   std::vector<CommandLine::Args> Args = getCommandArgs(
-      "apt-helper", CommandLine::GetCommand(Cmds, argc, argv));
-
-   // Set up gettext support
-   setlocale(LC_ALL,"");
-   textdomain(PACKAGE);
-
    // Parse the command line and initialize the package library
    CommandLine CmdL;
-   ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
+   ParseCommandLine(CmdL, Cmds, "apt-helper", &_config, &_system, argc, argv, ShowHelp);
 
    InitOutput();
 
-   // 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);
 }
                                                                        /*}}}*/
index fbcbf07e971e809eab62000d453916c593753863..278f6d47176bb5856f35f58285705e5b05c6f108 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <apt-private/private-output.h>
 #include <apt-private/private-cmndline.h>
+#include <apt-private/private-main.h>
 
 #include <string.h>
 #include <iostream>
@@ -68,20 +69,13 @@ APT_NORETURN static void DIE(std::string const &message) {          /*{{{*/
                                                                        /*}}}*/
 int main(int argc,const char *argv[])                                  /*{{{*/
 {
-       CommandLine::Args Args[] = {
-               {'h',"help","help",0},
-               {'v',"version","version",0},
-               {'q',"quiet","quiet",CommandLine::IntLevel},
-               {'q',"silent","quiet",CommandLine::IntLevel},
-               {'c',"config-file",0,CommandLine::ConfigFile},
-               {'o',"option",0,CommandLine::ArbItem},
-               {0,0,0,0}};
-
-        // we really don't need anything
-        DropPrivileges();
+       InitLocale();
+
+       // we really don't need anything
+       DropPrivileges();
 
        CommandLine CmdL;
-       ParseCommandLine(CmdL, nullptr, Args, &_config, NULL, argc, argv, ShowHelp);
+       ParseCommandLine(CmdL, nullptr, "apt-internal-solver", &_config, NULL, argc, argv, ShowHelp);
 
        if (CmdL.FileList[0] != 0 && strcmp(CmdL.FileList[0], "scenario") == 0)
        {
@@ -188,11 +182,6 @@ int main(int argc,const char *argv[])                                      /*{{{*/
 
        EDSP::WriteProgress(100, "Done", output);
 
-       bool const Errors = _error->PendingError();
-       if (_config->FindI("quiet",0) > 0)
-               _error->DumpErrors(std::cerr);
-       else
-               _error->DumpErrors(std::cerr, GlobalError::DEBUG);
-       return Errors == true ? 100 : 0;
+       return DispatchCommandLine(CmdL, nullptr);
 }
                                                                        /*}}}*/
index 361d4e553182343cd600f368fd1985db2e0e3b86..0a5bb164afe1b5603bd81381f31885df2adbcd85 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <apt-private/private-cmndline.h>
 #include <apt-private/private-output.h>
+#include <apt-private/private-main.h>
 
 #include <errno.h>
 #include <fcntl.h>
@@ -315,6 +316,8 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
                                                                        /*}}}*/
 int main(int argc,const char *argv[])                                  /*{{{*/
 {
+   InitLocale();
+
    CommandLine::DispatchWithHelp Cmds[] = {
       {"auto",&DoAuto, _("Mark the given packages as automatically installed")},
       {"manual",&DoAuto, _("Mark the given packages as manually installed")},
@@ -337,26 +340,11 @@ int main(int argc,const char *argv[])                                     /*{{{*/
       {nullptr, nullptr, nullptr}
    };
 
-   std::vector<CommandLine::Args> Args = getCommandArgs("apt-mark", CommandLine::GetCommand(Cmds, argc, argv));
-
-   // Set up gettext support
-   setlocale(LC_ALL,"");
-   textdomain(PACKAGE);
-
    CommandLine CmdL;
-   ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
+   ParseCommandLine(CmdL, Cmds, "apt-mark", &_config, &_system, argc, argv, ShowHelp);
 
    InitOutput();
 
-   // 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);
 }
                                                                        /*}}}*/
index e3d520a9609bc44e0e09226a8cfbef35b4d7868f..93aa5a76b64af90fc03851aceba793c9e0995079 100644 (file)
@@ -24,6 +24,7 @@
 #include <apt-pkg/pkgsystem.h>
 
 #include <apt-private/private-cmndline.h>
+#include <apt-private/private-main.h>
 
 #include <vector>
 #include <algorithm>
@@ -157,36 +158,18 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const *)
                                                                        /*}}}*/
 int main(int argc,const char *argv[])                                  /*{{{*/
 {
-   CommandLine::Args Args[] = {
-      {'h',"help","help",0},
-      {'v',"version","version",0},
-      {'s',"source","APT::SortPkgs::Source",0},
-      {'c',"config-file",0,CommandLine::ConfigFile},
-      {'o',"option",0,CommandLine::ArbItem},
-      {0,0,0,0}};
-
-   // Set up gettext support
-   setlocale(LC_ALL,"");
-   textdomain(PACKAGE);
+   InitLocale();
 
    // Parse the command line and initialize the package library
    CommandLine::DispatchWithHelp Cmds[] = {{nullptr, nullptr, nullptr}};
    CommandLine CmdL;
-   ParseCommandLine(CmdL, Cmds, Args, &_config, &_system, argc, argv, ShowHelp);
+   ParseCommandLine(CmdL, Cmds, "apt-sortpkgs", &_config, &_system, argc, argv, ShowHelp);
 
    // Match the operation
    for (unsigned int I = 0; I != CmdL.FileSize(); I++)
       if (DoIt(CmdL.FileList[I]) == false)
         break;
-   
-   // Print any errors or warnings found during parsing
-   if (_error->empty() == false)
-   {
-      bool Errors = _error->PendingError();
-      _error->DumpErrors();
-      return Errors == true?100:0;
-   }
-   
-   return 0;   
+
+   return DispatchCommandLine(CmdL, nullptr);
 }
                                                                        /*}}}*/
index 53735356dcd6d42d4275f33e2add9a51090fc6ca..98e715625f00eaddcd260cc547389c7792d096fc 100644 (file)
@@ -60,6 +60,8 @@ static bool ShowHelp(CommandLine &, CommandLine::DispatchWithHelp const * Cmds)
 
 int main(int argc, const char *argv[])                                 /*{{{*/
 {
+   InitLocale();
+
    CommandLine::DispatchWithHelp Cmds[] = {
       // query
       {"list", &DoList, _("list packages based on package names")},
@@ -85,51 +87,16 @@ int main(int argc, const char *argv[])                                      /*{{{*/
       {nullptr, nullptr, nullptr}
    };
 
-   std::vector<CommandLine::Args> Args = getCommandArgs("apt", CommandLine::GetCommand(Cmds, argc, argv));
-
-   // Init the signals
+   // FIXME: Those ignore commandline configuration like -q
    InitSignals();
-
-   // Init the output
    InitOutput();
 
-   // Set up gettext support
-   setlocale(LC_ALL,"");
-   textdomain(PACKAGE);
-
-    if(pkgInitConfig(*_config) == false) 
-    {
-        _error->DumpErrors();
-        return 100;
-    }
-
-   // Parse the command line and initialize the package library
    CommandLine CmdL;
-   ParseCommandLine(CmdL, Cmds, Args.data(), NULL, &_system, argc, argv, ShowHelp);
-
-   if(!isatty(STDOUT_FILENO) &&
-      _config->FindB("Apt::Cmd::Disable-Script-Warning", false) == false)
-   {
-      std::cerr << std::endl
-                << "WARNING: " << argv[0] << " "
-                << "does not have a stable CLI interface yet. "
-                << "Use with caution in scripts."
-                << std::endl
-                << std::endl;
-   }
-
-   // see if we are in simulate mode
-   CheckSimulateMode(CmdL);
+   ParseCommandLine(CmdL, Cmds, "apt", &_config, &_system, argc, argv, ShowHelp);
 
-   // parse args
-   CmdL.DispatchArg(Cmds);
+   CheckIfCalledByScript(argc, argv);
+   CheckIfSimulateMode(CmdL);
 
-   // 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);
 }
                                                                        /*}}}*/
index 857f0aff56e4f02071a50553c99c0c0564c4d5c6..ca03080ca221c584119220accb9a5f660000666b 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <apt-private/private-cmndline.h>
 #include <apt-private/private-output.h>
+#include <apt-private/private-main.h>
 
 #include <algorithm>
 #include <climits>
@@ -1026,25 +1027,7 @@ static bool Clean(CommandLine &CmdL)
 
 int main(int argc, const char *argv[])
 {
-   setlocale(LC_ALL, "");
-   CommandLine::Args Args[] = {
-      {'h',"help","help",0},
-      {0,"md5","APT::FTPArchive::MD5",0},
-      {0,"sha1","APT::FTPArchive::SHA1",0},
-      {0,"sha256","APT::FTPArchive::SHA256",0},
-      {0,"sha512","APT::FTPArchive::SHA512",0},
-      {'v',"version","version",0},
-      {'d',"db","APT::FTPArchive::DB",CommandLine::HasArg},
-      {'s',"source-override","APT::FTPArchive::SourceOverride",CommandLine::HasArg},
-      {'q',"quiet","quiet",CommandLine::IntLevel},
-      {'q',"silent","quiet",CommandLine::IntLevel},
-      {0,"delink","APT::FTPArchive::DeLinkAct",0},
-      {0,"readonly","APT::FTPArchive::ReadOnlyDB",0},
-      {0,"contents","APT::FTPArchive::Contents",0},
-      {'a',"arch","APT::FTPArchive::Architecture",CommandLine::HasArg},
-      {'c',"config-file",0,CommandLine::ConfigFile},
-      {'o',"option",0,CommandLine::ArbItem},
-      {0,0,0,0}};
+   InitLocale();
 
    CommandLine::DispatchWithHelp Cmds[] = {
       {"packages",&SimpleGenPackages, nullptr},
@@ -1057,21 +1040,12 @@ int main(int argc, const char *argv[])
    };
 
    // Parse the command line and initialize the package library
-   CommandLine CmdL(Args,_config);
-   ParseCommandLine(CmdL, Cmds, Args, &_config, NULL, argc, argv, ShowHelp);
+   CommandLine CmdL;
+   ParseCommandLine(CmdL, Cmds, "apt-ftparchive", &_config, NULL, argc, argv, ShowHelp);
 
    _config->CndSet("quiet",0);
    Quiet = _config->FindI("quiet",0);
    InitOutput(clog.rdbuf());
 
-   // Match the operation
-   CmdL.DispatchArg(Cmds);
-   
-   if (_error->empty() == false)
-   {
-      bool Errors = _error->PendingError();
-      _error->DumpErrors();
-      return Errors == true?100:0;
-   }
-   return 0;
+   return DispatchCommandLine(CmdL, Cmds);
 }