summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2020-03-24 09:16:42 +0000
committerJulian Andres Klode <jak@debian.org>2020-03-24 09:16:42 +0000
commite078cfbcd6eef2906b7661fc4822b93126f076d4 (patch)
treee22b48fe850cf32dfa79bf08f8240912ff55722c
parent1cfa1f3954373cc27adafa03a318c50bdc161bfe (diff)
parente93dbf2800bca2a6b8319826b7ad2243b4067faa (diff)
Merge branch 'pu/analyze-pattern' into 'master'
apt-helper: Add analyze-pattern helper See merge request apt-team/apt!113
-rw-r--r--cmdline/apt-helper.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/cmdline/apt-helper.cc b/cmdline/apt-helper.cc
index 97a4342f5..3d6a692e0 100644
--- a/cmdline/apt-helper.cc
+++ b/cmdline/apt-helper.cc
@@ -10,6 +10,7 @@
#include <apt-pkg/acquire-item.h>
#include <apt-pkg/acquire.h>
#include <apt-pkg/cmndline.h>
+#include <apt-pkg/cachefilter-patterns.h>
#include <apt-pkg/configuration.h>
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
@@ -257,6 +258,35 @@ static bool DropPrivsAndRun(CommandLine &CmdL) /*{{{*/
return ExecWait(pid, CmdL.FileList[1]);
}
/*}}}*/
+static bool AnalyzePattern(CommandLine &CmdL) /*{{{*/
+{
+ if (CmdL.FileSize() != 2)
+ return _error->Error("Expect one argument, a pattern");
+
+ try
+ {
+ auto top = APT::Internal::PatternTreeParser(CmdL.FileList[1]).parseTop();
+ top->render(std::cout) << "\n";
+ }
+ catch (APT::Internal::PatternTreeParser::Error &e)
+ {
+ std::stringstream ss;
+ ss << "input:" << e.location.start << "-" << e.location.end << ": error: " << e.message << "\n";
+ ss << CmdL.FileList[1] << "\n";
+ for (size_t i = 0; i < e.location.start; i++)
+ ss << " ";
+ for (size_t i = e.location.start; i < e.location.end; i++)
+ ss << "^";
+
+ ss << "\n";
+
+ _error->Error("%s", ss.str().c_str());
+ return false;
+ }
+
+ return true;
+}
+ /*}}}*/
static bool ShowHelp(CommandLine &) /*{{{*/
{
std::cout <<
@@ -278,6 +308,8 @@ static std::vector<aptDispatchWithHelp> GetCommands() /*{{{*/
{"auto-detect-proxy", &DoAutoDetectProxy, _("detect proxy using apt.conf")},
{"wait-online", &DoWaitOnline, _("wait for system to be online")},
{"drop-privs", &DropPrivsAndRun, _("drop privileges before running given command")},
+ {"analyze-pattern", &AnalyzePattern, _("analyse a pattern")},
+ {"analyse-pattern", &AnalyzePattern, nullptr},
{nullptr, nullptr, nullptr}};
}
/*}}}*/