]> git.saurik.com Git - apt.git/blobdiff - apt-private/private-cmndline.cc
centralize 'show' implementation of apt and apt-cache
[apt.git] / apt-private / private-cmndline.cc
index 5d6fd3c2e6bd851b938b608d580b8ea2f6e70f8c..1299b85f091400c5d081af7a4fdd0ee65f832409 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <apt-pkg/cmndline.h>
 #include <apt-pkg/configuration.h>
+#include <apt-pkg/fileutl.h>
 #include <apt-pkg/pkgsystem.h>
 #include <apt-pkg/init.h>
 #include <apt-pkg/error.h>
@@ -318,12 +319,35 @@ std::vector<CommandLine::Args> getCommandArgs(char const * const Program, char c
                                                                        /*}}}*/
 #undef CmdMatches
 #undef addArg
+static void BinarySpecificConfiguration(char const * const Binary)     /*{{{*/
+{
+   std::string const binary = flNotDir(Binary);
+   if (binary == "apt" || binary == "apt-config")
+   {
+      _config->CndSet("Binary::apt::APT::Cache::Show::Version", 2);
+      _config->CndSet("Binary::apt::APT::Cache::AllVersions", false);
+      _config->CndSet("Binary::apt::APT::Cache::ShowVirtuals", true);
+   }
+
+   _config->Set("Binary", binary);
+   std::string const conf = "Binary::" + binary;
+   _config->MoveSubTree(conf.c_str(), NULL);
+}
+                                                                       /*}}}*/
 void ParseCommandLine(CommandLine &CmdL, CommandLine::Dispatch * const Cmds, CommandLine::Args * const Args,/*{{{*/
       Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char *argv[], bool(*ShowHelp)(CommandLine &CmdL))
 {
    CmdL = CommandLine(Args,_config);
-   if ((Cnf != NULL && pkgInitConfig(**Cnf) == false) ||
-       CmdL.Parse(argc,argv) == false ||
+   if (Cnf != NULL && pkgInitConfig(**Cnf) == false)
+   {
+      _error->DumpErrors();
+      exit(100);
+   }
+
+   if (likely(argc != 0 && argv[0] != NULL))
+      BinarySpecificConfiguration(argv[0]);
+
+   if (CmdL.Parse(argc,argv) == false ||
        (Sys != NULL && pkgInitSystem(*_config, *Sys) == false))
    {
       if (_config->FindB("version") == true)