summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2025-05-19 15:21:03 +0000
committerJulian Andres Klode <jak@debian.org>2025-05-19 15:21:03 +0000
commitd0ecc3286b4487d3b3f2809c95233863bffdada5 (patch)
tree9f76923fbd5b856904a414fa615116940d2afff6 /cmdline
parent2ddc16b9f8edff1329f5ac3e46b0c0cf9bde661d (diff)
parent7724d170751b3dc1717ba7a08881437cf7151996 (diff)
Merge branch 'feature/why' into 'main'
Introduce apt why, apt why-not See merge request apt-team/apt!479
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/apt.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/cmdline/apt.cc b/cmdline/apt.cc
index af8a95fa5..a876085ce 100644
--- a/cmdline/apt.cc
+++ b/cmdline/apt.cc
@@ -16,6 +16,7 @@
#include <apt-pkg/error.h>
#include <apt-pkg/init.h>
#include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/solver3.h>
#include <apt-pkg/strutl.h>
#include <apt-private/private-cmndline.h>
@@ -53,6 +54,20 @@ static bool ShowHelp(CommandLine &) /*{{{*/
return true;
}
/*}}}*/
+
+static bool DoWhy(CommandLine &CmdL) /*{{{*/
+{
+ pkgCacheFile CacheFile;
+ APT::PackageList pkgset = APT::PackageList::FromCommandLine(CacheFile, CmdL.FileList + 1);
+ bool const decision = strcmp(CmdL.FileList[0], "why") == 0;
+ if (pkgset.size() != 1)
+ return _error->PendingError() ? false : _error->Error("Only a single argument is supported at this time.");
+ if (unlikely(not CacheFile.BuildDepCache()))
+ return false;
+ for (auto pkg : pkgset)
+ std::cout << APT::Solver::InternalCliWhy(CacheFile, pkg, decision) << std::flush;
+ return not _error->PendingError();
+}
static std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/
{
// advanced commands are left undocumented on purpose
@@ -81,6 +96,8 @@ static std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/
{"modernize-sources", &ModernizeSources, _("modernize .list files to .sources files")},
{"moo", &DoMoo, nullptr},
{"satisfy", &DoBuildDep, _("satisfy dependency strings")},
+ {"why", &DoWhy, _("produce a reason trace for the current state of the package")},
+ {"why-not", &DoWhy, _("produce a reason trace for the current state of the package")},
// for compat with muscle memory
{"dist-upgrade", &DoDistUpgrade, nullptr},