]> git.saurik.com Git - apt.git/blobdiff - apt-private/private-cmndline.cc
move 'search' implementations as well
[apt.git] / apt-private / private-cmndline.cc
index aceb865d578f94e261c97369c31cc858c8f368d9..463c087cc701749c25f26e68f80f34dfdd24586f 100644 (file)
@@ -3,18 +3,22 @@
 
 #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>
 
-#include <vector>
+#include <apt-private/private-cmndline.h>
 
+#include <vector>
 #include <stdarg.h>
 #include <string.h>
-
-#include "private-cmndline.h"
+#include <stdlib.h>
 
 #include <apti18n.h>
                                                                        /*}}}*/
 
-bool strcmp_match_in_list(char const * const Cmd, ...)                 /*{{{*/
+APT_SENTINEL static bool strcmp_match_in_list(char const * const Cmd, ...)             /*{{{*/
 {
    va_list args;
    bool found = false;
@@ -33,7 +37,7 @@ bool strcmp_match_in_list(char const * const Cmd, ...)                        /*{{{*/
                                                                        /*}}}*/
 #define addArg(w,x,y,z) Args.push_back(CommandLine::MakeArgs(w,x,y,z))
 #define CmdMatches(...) strcmp_match_in_list(Cmd, __VA_ARGS__, NULL)
-bool addArgumentsAPTCache(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
+static bool addArgumentsAPTCache(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
 {
    if (CmdMatches("depends", "rdepends", "xvcg", "dotty"))
    {
@@ -48,6 +52,7 @@ bool addArgumentsAPTCache(std::vector<CommandLine::Args> &Args, char const * con
       addArg(0, "conflicts", "APT::Cache::ShowConflicts", 0);
       addArg(0, "enhances", "APT::Cache::ShowEnhances", 0);
       addArg(0, "recurse", "APT::Cache::RecurseDepends", 0);
+      addArg(0, "implicit", "APT::Cache::ShowImplicit", 0);
    }
    else if (CmdMatches("search"))
    {
@@ -62,12 +67,22 @@ bool addArgumentsAPTCache(std::vector<CommandLine::Args> &Args, char const * con
    {
       addArg(0, "all-names", "APT::Cache::AllNames", 0);
    }
-   else if (CmdMatches("gencaches", "showsrc", "showpkg", "stats", "dump",
-           "dumpavail", "unmet", "showauto", "policy", "madison"))
+   else if (CmdMatches("unmet"))
+   {
+      addArg('i', "important", "APT::Cache::Important", 0);
+   }
+   else if (CmdMatches("showsrc"))
+   {
+      addArg(0,"only-source","APT::Cache::Only-Source",0);
+   }
+   else if (CmdMatches("gencaches", "showpkg", "stats", "dump",
+           "dumpavail", "showauto", "policy", "madison"))
       ;
    else
       return false;
 
+   bool const found_something = Args.empty() == false;
+
    // FIXME: move to the correct command(s)
    addArg('g', "generate", "APT::Cache::Generate", 0);
    addArg('t', "target-release", "APT::Default-Release", CommandLine::HasArg);
@@ -75,10 +90,11 @@ bool addArgumentsAPTCache(std::vector<CommandLine::Args> &Args, char const * con
 
    addArg('p', "pkg-cache", "Dir::Cache::pkgcache", CommandLine::HasArg);
    addArg('s', "src-cache", "Dir::Cache::srcpkgcache", CommandLine::HasArg);
-   return true;
+
+   return found_something;
 }
                                                                        /*}}}*/
-bool addArgumentsAPTCDROM(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
+static bool addArgumentsAPTCDROM(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
 {
    if (CmdMatches("add", "ident") == false)
       return false;
@@ -96,7 +112,7 @@ bool addArgumentsAPTCDROM(std::vector<CommandLine::Args> &Args, char const * con
    return true;
 }
                                                                        /*}}}*/
-bool addArgumentsAPTConfig(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
+static bool addArgumentsAPTConfig(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
 {
    if (CmdMatches("dump"))
    {
@@ -111,12 +127,12 @@ bool addArgumentsAPTConfig(std::vector<CommandLine::Args> &Args, char const * co
    return true;
 }
                                                                        /*}}}*/
-bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
+static bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
 {
    if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade",
-           "deselect-upgrade", "autoremove"))
+           "dselect-upgrade", "autoremove", "full-upgrade"))
    {
-      addArg(0, "dpkg-progress", "DpkgPM::Progress", 0);
+      addArg(0, "show-progress", "DpkgPM::Progress", 0);
       addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0);
       addArg(0, "purge", "APT::Get::Purge", 0);
       addArg('V',"verbose-versions","APT::Get::Show-Versions",0);
@@ -125,7 +141,8 @@ bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const * const
       addArg(0, "solver", "APT::Solver", CommandLine::HasArg);
       if (CmdMatches("upgrade"))
       {
-        addArg(0, "allow-new", "APT::Get::UpgradeAllowNew", 0);
+         addArg(0, "new-pkgs", "APT::Get::Upgrade-Allow-New", 
+                CommandLine::Boolean);
       }
    }
    else if (CmdMatches("update"))
@@ -136,6 +153,7 @@ bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const * const
    {
       addArg('b', "compile", "APT::Get::Compile", 0);
       addArg('b', "build", "APT::Get::Compile", 0);
+      addArg('P', "build-profiles", "APT::Build-Profiles", CommandLine::HasArg);
       addArg(0, "diff-only", "APT::Get::Diff-Only", 0);
       addArg(0, "debian-only", "APT::Get::Diff-Only", 0);
       addArg(0, "tar-only", "APT::Get::Tar-Only", 0);
@@ -144,17 +162,27 @@ bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const * const
    else if (CmdMatches("build-dep"))
    {
       addArg('a', "host-architecture", "APT::Get::Host-Architecture", CommandLine::HasArg);
+      addArg('P', "build-profiles", "APT::Build-Profiles", CommandLine::HasArg);
+      addArg(0, "purge", "APT::Get::Purge", 0);
       addArg(0, "solver", "APT::Solver", CommandLine::HasArg);
+      // this has no effect *but* sbuild is using it (see LP: #1255806)
+      // once sbuild is fixed, this option can be removed
+      addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0);
    }
-   else if (CmdMatches("clean", "autoclean", "check", "download", "changelog") ||
+   else if (CmdMatches("indextargets"))
+   {
+      addArg(0,"format","APT::Get::IndexTargets::Format", CommandLine::HasArg);
+      addArg(0,"release-info","APT::Get::IndexTargets::ReleaseInfo", 0);
+   }
+   else if (CmdMatches("clean", "autoclean", "auto-clean", "check", "download", "changelog") ||
            CmdMatches("markauto", "unmarkauto")) // deprecated commands
       ;
    else if (CmdMatches("moo"))
       addArg(0, "color", "APT::Moo::Color", 0);
 
    if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade",
-           "deselect-upgrade", "autoremove", "clean", "autoclean", "check",
-           "build-dep"))
+           "dselect-upgrade", "autoremove", "auto-remove", "clean", "autoclean", "auto-clean", "check",
+           "build-dep", "full-upgrade", "source"))
    {
       addArg('s', "simulate", "APT::Get::Simulate", 0);
       addArg('s', "just-print", "APT::Get::Simulate", 0);
@@ -163,6 +191,8 @@ bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const * const
       addArg('s', "no-act", "APT::Get::Simulate", 0);
    }
 
+   bool const found_something = Args.empty() == false;
+
    // FIXME: move to the correct command(s)
    addArg('d',"download-only","APT::Get::Download-Only",0);
    addArg('y',"yes","APT::Get::Assume-Yes",0);
@@ -177,6 +207,9 @@ bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const * const
    addArg(0,"ignore-hold","APT::Ignore-Hold",0);
    addArg(0,"upgrade","APT::Get::upgrade",0);
    addArg(0,"only-upgrade","APT::Get::Only-Upgrade",0);
+   addArg(0,"allow-change-held-packages","APT::Get::allow-change-held-packages",CommandLine::Boolean);
+   addArg(0,"allow-remove-essential","APT::Get::allow-remove-essential",CommandLine::Boolean);
+   addArg(0,"allow-downgrades","APT::Get::allow-downgrades",CommandLine::Boolean);
    addArg(0,"force-yes","APT::Get::force-yes",0);
    addArg(0,"print-uris","APT::Get::Print-URIs",0);
    addArg(0,"trivial-only","APT::Get::Trivial-Only",0);
@@ -184,40 +217,60 @@ bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const * const
    addArg(0,"only-source","APT::Get::Only-Source",0);
    addArg(0,"arch-only","APT::Get::Arch-Only",0);
    addArg(0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0);
+   addArg(0,"allow-insecure-repositories","Acquire::AllowInsecureRepositories",0);
    addArg(0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean);
    addArg(0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean);
    addArg(0,"fix-policy","APT::Get::Fix-Policy-Broken",0);
 
-   return true;
+   return found_something;
 }
                                                                        /*}}}*/
-bool addArgumentsAPTMark(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
+static bool addArgumentsAPTMark(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
 {
    if (CmdMatches("auto", "manual", "hold", "unhold", "showauto",
-           "showmanual", "showhold", "showholds", "install",
+           "showmanual", "showhold", "showholds",
            "markauto", "unmarkauto"))
+   {
+      addArg('f',"file","Dir::State::extended_states",CommandLine::HasArg);
+   }
+   else if (CmdMatches("install", "remove", "deinstall", "purge",
+           "showinstall", "showinstalls", "showremove", "showremoves",
+           "showdeinstall", "showdeinstalls", "showpurge", "showpurges"))
       ;
    else
       return false;
 
-   addArg('v',"verbose","APT::MarkAuto::Verbose",0);
-   addArg('s',"simulate","APT::Mark::Simulate",0);
-   addArg('s',"just-print","APT::Mark::Simulate",0);
-   addArg('s',"recon","APT::Mark::Simulate",0);
-   addArg('s',"dry-run","APT::Mark::Simulate",0);
-   addArg('s',"no-act","APT::Mark::Simulate",0);
-   addArg('f',"file","Dir::State::extended_states",CommandLine::HasArg);
+   if (CmdMatches("markauto", "unmarkauto"))
+   {
+      addArg('v',"verbose","APT::MarkAuto::Verbose",0);
+   }
+
+   if (strncmp(Cmd, "show", strlen("show")) != 0)
+   {
+      addArg('s',"simulate","APT::Mark::Simulate",0);
+      addArg('s',"just-print","APT::Mark::Simulate",0);
+      addArg('s',"recon","APT::Mark::Simulate",0);
+      addArg('s',"dry-run","APT::Mark::Simulate",0);
+      addArg('s',"no-act","APT::Mark::Simulate",0);
+   }
 
    return true;
 }
                                                                        /*}}}*/
-bool addArgumentsAPT(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
+static bool addArgumentsAPT(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/
 {
    if (CmdMatches("list"))
    {
-      addArg(0,"installed","APT::Cmd::Installed",0);
-      addArg(0,"upgradable","APT::Cmd::Upgradable",0);
-      addArg('a', "all-versions", "APT::Cmd::AllVersions", 0);
+      addArg('i',"installed","APT::Cmd::Installed",0);
+      addArg(0,"upgradeable","APT::Cmd::Upgradable",0);
+      addArg('u',"upgradable","APT::Cmd::Upgradable",0);
+      addArg(0,"manual-installed","APT::Cmd::Manual-Installed",0);
+      addArg('v', "verbose", "APT::Cmd::List-Include-Summary", 0);
+      addArg('a', "all-versions", "APT::Cmd::All-Versions", 0);
+   }
+   else if (CmdMatches("show"))
+   {
+      addArg('a', "all-versions", "APT::Cache::AllVersions", 0);
    }
    else if (addArgumentsAPTGet(Args, Cmd) || addArgumentsAPTCache(Args, Cmd))
    {
@@ -266,3 +319,59 @@ 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::Color", true);
+      _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->CndSet("Binary::apt::APT::Cache::Search::Version", 2);
+      _config->CndSet("Binary::apt::APT::Get::Upgrade-Allow-New", true);
+      _config->CndSet("Binary::apt::APT::Cmd::Show-Update-Stats", true);
+      _config->CndSet("Binary::apt::DPkg::Progress-Fancy", 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)
+   {
+      _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)
+        ShowHelp(CmdL);
+
+      _error->DumpErrors();
+      exit(100);
+   }
+
+   // See if the help should be shown
+   if (_config->FindB("help") == true || _config->FindB("version") == true)
+   {
+      ShowHelp(CmdL);
+      exit(0);
+   }
+   if (Cmds != NULL && CmdL.FileSize() == 0)
+   {
+      ShowHelp(CmdL);
+      exit(1);
+   }
+}
+                                                                       /*}}}*/