]>
Commit | Line | Data |
---|---|---|
b9179170 MV |
1 | // Include Files /*{{{*/ |
2 | #include <config.h> | |
3 | ||
4 | #include <apt-pkg/cmndline.h> | |
ad7e0941 | 5 | #include <apt-pkg/configuration.h> |
c3ded84c | 6 | #include <apt-pkg/fileutl.h> |
ad7e0941 DK |
7 | #include <apt-pkg/pkgsystem.h> |
8 | #include <apt-pkg/init.h> | |
9 | #include <apt-pkg/error.h> | |
8561c2fe | 10 | #include <apt-pkg/strutl.h> |
b9179170 | 11 | |
453b82a3 | 12 | #include <apt-private/private-cmndline.h> |
570ec96d | 13 | #include <apt-private/private-main.h> |
b9179170 MV |
14 | |
15 | #include <stdarg.h> | |
16 | #include <string.h> | |
ad7e0941 | 17 | #include <stdlib.h> |
b9179170 | 18 | |
8561c2fe DK |
19 | #include <vector> |
20 | #include <iomanip> | |
21 | ||
b9179170 MV |
22 | #include <apti18n.h> |
23 | /*}}}*/ | |
24 | ||
a02db58f | 25 | APT_SENTINEL static bool strcmp_match_in_list(char const * const Cmd, ...) /*{{{*/ |
b9179170 MV |
26 | { |
27 | va_list args; | |
28 | bool found = false; | |
29 | va_start(args, Cmd); | |
30 | char const * Match = NULL; | |
31 | while ((Match = va_arg(args, char const *)) != NULL) | |
32 | { | |
33 | if (strcmp(Cmd, Match) != 0) | |
34 | continue; | |
35 | found = true; | |
36 | break; | |
37 | } | |
38 | va_end(args); | |
39 | return found; | |
40 | } | |
41 | /*}}}*/ | |
42 | #define addArg(w,x,y,z) Args.push_back(CommandLine::MakeArgs(w,x,y,z)) | |
43 | #define CmdMatches(...) strcmp_match_in_list(Cmd, __VA_ARGS__, NULL) | |
c3ccac92 | 44 | static bool addArgumentsAPTCache(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/ |
b9179170 MV |
45 | { |
46 | if (CmdMatches("depends", "rdepends", "xvcg", "dotty")) | |
47 | { | |
48 | addArg('i', "important", "APT::Cache::Important", 0); | |
49 | addArg(0, "installed", "APT::Cache::Installed", 0); | |
50 | addArg(0, "pre-depends", "APT::Cache::ShowPre-Depends", 0); | |
51 | addArg(0, "depends", "APT::Cache::ShowDepends", 0); | |
52 | addArg(0, "recommends", "APT::Cache::ShowRecommends", 0); | |
53 | addArg(0, "suggests", "APT::Cache::ShowSuggests", 0); | |
54 | addArg(0, "replaces", "APT::Cache::ShowReplaces", 0); | |
55 | addArg(0, "breaks", "APT::Cache::ShowBreaks", 0); | |
56 | addArg(0, "conflicts", "APT::Cache::ShowConflicts", 0); | |
57 | addArg(0, "enhances", "APT::Cache::ShowEnhances", 0); | |
58 | addArg(0, "recurse", "APT::Cache::RecurseDepends", 0); | |
8c7af4d4 | 59 | addArg(0, "implicit", "APT::Cache::ShowImplicit", 0); |
b9179170 MV |
60 | } |
61 | else if (CmdMatches("search")) | |
62 | { | |
63 | addArg('n', "names-only", "APT::Cache::NamesOnly", 0); | |
64 | addArg('f', "full", "APT::Cache::ShowFull", 0); | |
65 | } | |
66 | else if (CmdMatches("show")) | |
67 | { | |
68 | addArg('a', "all-versions", "APT::Cache::AllVersions", 0); | |
69 | } | |
70 | else if (CmdMatches("pkgnames")) | |
71 | { | |
72 | addArg(0, "all-names", "APT::Cache::AllNames", 0); | |
73 | } | |
58c2833f MV |
74 | else if (CmdMatches("unmet")) |
75 | { | |
76 | addArg('i', "important", "APT::Cache::Important", 0); | |
77 | } | |
a8275acf MV |
78 | else if (CmdMatches("showsrc")) |
79 | { | |
80 | addArg(0,"only-source","APT::Cache::Only-Source",0); | |
81 | } | |
82 | else if (CmdMatches("gencaches", "showpkg", "stats", "dump", | |
58c2833f | 83 | "dumpavail", "showauto", "policy", "madison")) |
b9179170 MV |
84 | ; |
85 | else | |
86 | return false; | |
87 | ||
859093da DK |
88 | bool const found_something = Args.empty() == false; |
89 | ||
b9179170 MV |
90 | // FIXME: move to the correct command(s) |
91 | addArg('g', "generate", "APT::Cache::Generate", 0); | |
92 | addArg('t', "target-release", "APT::Default-Release", CommandLine::HasArg); | |
93 | addArg('t', "default-release", "APT::Default-Release", CommandLine::HasArg); | |
94 | ||
95 | addArg('p', "pkg-cache", "Dir::Cache::pkgcache", CommandLine::HasArg); | |
96 | addArg('s', "src-cache", "Dir::Cache::srcpkgcache", CommandLine::HasArg); | |
859093da DK |
97 | |
98 | return found_something; | |
b9179170 MV |
99 | } |
100 | /*}}}*/ | |
c3ccac92 | 101 | static bool addArgumentsAPTCDROM(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/ |
b9179170 MV |
102 | { |
103 | if (CmdMatches("add", "ident") == false) | |
104 | return false; | |
105 | ||
106 | // FIXME: move to the correct command(s) | |
107 | addArg(0, "auto-detect", "Acquire::cdrom::AutoDetect", CommandLine::Boolean); | |
108 | addArg('d', "cdrom", "Acquire::cdrom::mount", CommandLine::HasArg); | |
109 | addArg('r', "rename", "APT::CDROM::Rename", 0); | |
110 | addArg('m', "no-mount", "APT::CDROM::NoMount", 0); | |
111 | addArg('f', "fast", "APT::CDROM::Fast", 0); | |
112 | addArg('n', "just-print", "APT::CDROM::NoAct", 0); | |
113 | addArg('n', "recon", "APT::CDROM::NoAct", 0); | |
114 | addArg('n', "no-act", "APT::CDROM::NoAct", 0); | |
115 | addArg('a', "thorough", "APT::CDROM::Thorough", 0); | |
116 | return true; | |
117 | } | |
118 | /*}}}*/ | |
c3ccac92 | 119 | static bool addArgumentsAPTConfig(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/ |
b9179170 MV |
120 | { |
121 | if (CmdMatches("dump")) | |
122 | { | |
123 | addArg(0,"empty","APT::Config::Dump::EmptyValue",CommandLine::Boolean); | |
124 | addArg(0,"format","APT::Config::Dump::Format",CommandLine::HasArg); | |
125 | } | |
126 | else if (CmdMatches("shell")) | |
127 | ; | |
128 | else | |
129 | return false; | |
130 | ||
385d9f2f DK |
131 | return true; |
132 | } | |
133 | /*}}}*/ | |
134 | static bool addArgumentsAPTDumpSolver(std::vector<CommandLine::Args> &, char const * const)/*{{{*/ | |
135 | { | |
e7e10e47 DK |
136 | return true; |
137 | } | |
138 | /*}}}*/ | |
139 | static bool addArgumentsAPTExtractTemplates(std::vector<CommandLine::Args> &Args, char const * const)/*{{{*/ | |
140 | { | |
141 | addArg('t',"tempdir","APT::ExtractTemplates::TempDir",CommandLine::HasArg); | |
142 | return true; | |
143 | } | |
144 | /*}}}*/ | |
145 | static bool addArgumentsAPTFTPArchive(std::vector<CommandLine::Args> &Args, char const * const)/*{{{*/ | |
146 | { | |
147 | addArg(0,"md5","APT::FTPArchive::MD5",0); | |
148 | addArg(0,"sha1","APT::FTPArchive::SHA1",0); | |
149 | addArg(0,"sha256","APT::FTPArchive::SHA256",0); | |
150 | addArg(0,"sha512","APT::FTPArchive::SHA512",0); | |
151 | addArg('d',"db","APT::FTPArchive::DB",CommandLine::HasArg); | |
152 | addArg('s',"source-override","APT::FTPArchive::SourceOverride",CommandLine::HasArg); | |
153 | addArg(0,"delink","APT::FTPArchive::DeLinkAct",0); | |
154 | addArg(0,"readonly","APT::FTPArchive::ReadOnlyDB",0); | |
155 | addArg(0,"contents","APT::FTPArchive::Contents",0); | |
156 | addArg('a',"arch","APT::FTPArchive::Architecture",CommandLine::HasArg); | |
157 | return true; | |
158 | } | |
159 | /*}}}*/ | |
160 | static bool addArgumentsAPTInternalSolver(std::vector<CommandLine::Args> &, char const * const)/*{{{*/ | |
011188e3 DK |
161 | { |
162 | return true; | |
163 | } | |
164 | /*}}}*/ | |
df46a87a | 165 | static bool addArgumentsAPTHelper(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/ |
e7e10e47 | 166 | { |
df46a87a JAK |
167 | if (CmdMatches("cat-file")) |
168 | { | |
169 | addArg('C', "compress", "Apt-Helper::Cat-File::Compress",CommandLine::HasArg); | |
170 | } | |
b9179170 MV |
171 | return true; |
172 | } | |
173 | /*}}}*/ | |
c3ccac92 | 174 | static bool addArgumentsAPTGet(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/ |
b9179170 MV |
175 | { |
176 | if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade", | |
ebe24b7a | 177 | "dselect-upgrade", "autoremove", "full-upgrade")) |
b9179170 | 178 | { |
4fb66d87 | 179 | addArg(0, "show-progress", "DpkgPM::Progress", 0); |
b9179170 MV |
180 | addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0); |
181 | addArg(0, "purge", "APT::Get::Purge", 0); | |
182 | addArg('V',"verbose-versions","APT::Get::Show-Versions",0); | |
183 | addArg(0, "auto-remove", "APT::Get::AutomaticRemove", 0); | |
184 | addArg(0, "reinstall", "APT::Get::ReInstall", 0); | |
185 | addArg(0, "solver", "APT::Solver", CommandLine::HasArg); | |
186 | if (CmdMatches("upgrade")) | |
187 | { | |
2004d647 | 188 | addArg(0, "new-pkgs", "APT::Get::Upgrade-Allow-New", |
c678a044 | 189 | CommandLine::Boolean); |
b9179170 MV |
190 | } |
191 | } | |
192 | else if (CmdMatches("update")) | |
193 | { | |
194 | addArg(0, "list-cleanup", "APT::Get::List-Cleanup", 0); | |
195 | } | |
196 | else if (CmdMatches("source")) | |
197 | { | |
198 | addArg('b', "compile", "APT::Get::Compile", 0); | |
199 | addArg('b', "build", "APT::Get::Compile", 0); | |
ce7f128c | 200 | addArg('P', "build-profiles", "APT::Build-Profiles", CommandLine::HasArg); |
b9179170 MV |
201 | addArg(0, "diff-only", "APT::Get::Diff-Only", 0); |
202 | addArg(0, "debian-only", "APT::Get::Diff-Only", 0); | |
203 | addArg(0, "tar-only", "APT::Get::Tar-Only", 0); | |
204 | addArg(0, "dsc-only", "APT::Get::Dsc-Only", 0); | |
205 | } | |
206 | else if (CmdMatches("build-dep")) | |
207 | { | |
208 | addArg('a', "host-architecture", "APT::Get::Host-Architecture", CommandLine::HasArg); | |
ce7f128c | 209 | addArg('P', "build-profiles", "APT::Build-Profiles", CommandLine::HasArg); |
e4e5d47b | 210 | addArg(0, "purge", "APT::Get::Purge", 0); |
b9179170 | 211 | addArg(0, "solver", "APT::Solver", CommandLine::HasArg); |
c872ac50 MV |
212 | // this has no effect *but* sbuild is using it (see LP: #1255806) |
213 | // once sbuild is fixed, this option can be removed | |
214 | addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0); | |
b9179170 | 215 | } |
c2a4a8dd | 216 | else if (CmdMatches("indextargets")) |
8881b11e | 217 | { |
c2a4a8dd DK |
218 | addArg(0,"format","APT::Get::IndexTargets::Format", CommandLine::HasArg); |
219 | addArg(0,"release-info","APT::Get::IndexTargets::ReleaseInfo", 0); | |
8881b11e | 220 | } |
f66738d7 | 221 | else if (CmdMatches("clean", "autoclean", "auto-clean", "check", "download", "changelog") || |
b9179170 MV |
222 | CmdMatches("markauto", "unmarkauto")) // deprecated commands |
223 | ; | |
224 | else if (CmdMatches("moo")) | |
225 | addArg(0, "color", "APT::Moo::Color", 0); | |
226 | ||
227 | if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade", | |
f66738d7 | 228 | "dselect-upgrade", "autoremove", "auto-remove", "clean", "autoclean", "auto-clean", "check", |
f83b5627 | 229 | "build-dep", "full-upgrade", "source")) |
b9179170 MV |
230 | { |
231 | addArg('s', "simulate", "APT::Get::Simulate", 0); | |
232 | addArg('s', "just-print", "APT::Get::Simulate", 0); | |
233 | addArg('s', "recon", "APT::Get::Simulate", 0); | |
234 | addArg('s', "dry-run", "APT::Get::Simulate", 0); | |
235 | addArg('s', "no-act", "APT::Get::Simulate", 0); | |
236 | } | |
237 | ||
859093da DK |
238 | bool const found_something = Args.empty() == false; |
239 | ||
b9179170 MV |
240 | // FIXME: move to the correct command(s) |
241 | addArg('d',"download-only","APT::Get::Download-Only",0); | |
242 | addArg('y',"yes","APT::Get::Assume-Yes",0); | |
243 | addArg('y',"assume-yes","APT::Get::Assume-Yes",0); | |
244 | addArg(0,"assume-no","APT::Get::Assume-No",0); | |
245 | addArg('u',"show-upgraded","APT::Get::Show-Upgraded",0); | |
246 | addArg('m',"ignore-missing","APT::Get::Fix-Missing",0); | |
247 | addArg('t',"target-release","APT::Default-Release",CommandLine::HasArg); | |
248 | addArg('t',"default-release","APT::Default-Release",CommandLine::HasArg); | |
249 | addArg(0,"download","APT::Get::Download",0); | |
250 | addArg(0,"fix-missing","APT::Get::Fix-Missing",0); | |
251 | addArg(0,"ignore-hold","APT::Ignore-Hold",0); | |
252 | addArg(0,"upgrade","APT::Get::upgrade",0); | |
253 | addArg(0,"only-upgrade","APT::Get::Only-Upgrade",0); | |
b381a482 JAK |
254 | addArg(0,"allow-change-held-packages","APT::Get::allow-change-held-packages",CommandLine::Boolean); |
255 | addArg(0,"allow-remove-essential","APT::Get::allow-remove-essential",CommandLine::Boolean); | |
256 | addArg(0,"allow-downgrades","APT::Get::allow-downgrades",CommandLine::Boolean); | |
b9179170 MV |
257 | addArg(0,"force-yes","APT::Get::force-yes",0); |
258 | addArg(0,"print-uris","APT::Get::Print-URIs",0); | |
259 | addArg(0,"trivial-only","APT::Get::Trivial-Only",0); | |
260 | addArg(0,"remove","APT::Get::Remove",0); | |
261 | addArg(0,"only-source","APT::Get::Only-Source",0); | |
262 | addArg(0,"arch-only","APT::Get::Arch-Only",0); | |
263 | addArg(0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0); | |
c99fe2e1 | 264 | addArg(0,"allow-insecure-repositories","Acquire::AllowInsecureRepositories",0); |
b9179170 MV |
265 | addArg(0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean); |
266 | addArg(0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean); | |
267 | addArg(0,"fix-policy","APT::Get::Fix-Policy-Broken",0); | |
268 | ||
859093da | 269 | return found_something; |
b9179170 MV |
270 | } |
271 | /*}}}*/ | |
c3ccac92 | 272 | static bool addArgumentsAPTMark(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/ |
b9179170 MV |
273 | { |
274 | if (CmdMatches("auto", "manual", "hold", "unhold", "showauto", | |
64e3414e | 275 | "showmanual", "showhold", "showholds", |
b9179170 | 276 | "markauto", "unmarkauto")) |
64e3414e DK |
277 | { |
278 | addArg('f',"file","Dir::State::extended_states",CommandLine::HasArg); | |
279 | } | |
280 | else if (CmdMatches("install", "remove", "deinstall", "purge", | |
281 | "showinstall", "showinstalls", "showremove", "showremoves", | |
282 | "showdeinstall", "showdeinstalls", "showpurge", "showpurges")) | |
b9179170 MV |
283 | ; |
284 | else | |
285 | return false; | |
286 | ||
64e3414e DK |
287 | if (CmdMatches("markauto", "unmarkauto")) |
288 | { | |
289 | addArg('v',"verbose","APT::MarkAuto::Verbose",0); | |
290 | } | |
291 | ||
292 | if (strncmp(Cmd, "show", strlen("show")) != 0) | |
293 | { | |
294 | addArg('s',"simulate","APT::Mark::Simulate",0); | |
295 | addArg('s',"just-print","APT::Mark::Simulate",0); | |
296 | addArg('s',"recon","APT::Mark::Simulate",0); | |
297 | addArg('s',"dry-run","APT::Mark::Simulate",0); | |
298 | addArg('s',"no-act","APT::Mark::Simulate",0); | |
299 | } | |
b9179170 | 300 | |
e7e10e47 DK |
301 | return true; |
302 | } | |
303 | /*}}}*/ | |
304 | static bool addArgumentsAPTSortPkgs(std::vector<CommandLine::Args> &Args, char const * const)/*{{{*/ | |
305 | { | |
306 | addArg('s',"source","APT::SortPkgs::Source",0); | |
b9179170 MV |
307 | return true; |
308 | } | |
309 | /*}}}*/ | |
c3ccac92 | 310 | static bool addArgumentsAPT(std::vector<CommandLine::Args> &Args, char const * const Cmd)/*{{{*/ |
b9179170 MV |
311 | { |
312 | if (CmdMatches("list")) | |
313 | { | |
d2c712a1 | 314 | addArg('i',"installed","APT::Cmd::Installed",0); |
df7c9fd2 | 315 | addArg(0,"upgradeable","APT::Cmd::Upgradable",0); |
d2c712a1 | 316 | addArg('u',"upgradable","APT::Cmd::Upgradable",0); |
3bdf7da5 | 317 | addArg(0,"manual-installed","APT::Cmd::Manual-Installed",0); |
e1dc051a | 318 | addArg('v', "verbose", "APT::Cmd::List-Include-Summary", 0); |
c1a61d1c | 319 | addArg('a', "all-versions", "APT::Cmd::All-Versions", 0); |
b9179170 | 320 | } |
06293aa7 MV |
321 | else if (CmdMatches("show")) |
322 | { | |
323 | addArg('a', "all-versions", "APT::Cache::AllVersions", 0); | |
324 | } | |
b9179170 MV |
325 | else if (addArgumentsAPTGet(Args, Cmd) || addArgumentsAPTCache(Args, Cmd)) |
326 | { | |
327 | // we have no (supported) command-name overlaps so far, so we call | |
328 | // specifics in order until we find one which adds arguments | |
329 | } | |
330 | else | |
331 | return false; | |
332 | ||
333 | return true; | |
334 | } | |
335 | /*}}}*/ | |
011188e3 | 336 | std::vector<CommandLine::Args> getCommandArgs(APT_CMD const Program, char const * const Cmd)/*{{{*/ |
b9179170 MV |
337 | { |
338 | std::vector<CommandLine::Args> Args; | |
339 | Args.reserve(50); | |
011188e3 DK |
340 | if (Cmd == nullptr) |
341 | { | |
342 | if (Program == APT_CMD::APT_EXTRACTTEMPLATES) | |
343 | addArgumentsAPTExtractTemplates(Args, Cmd); | |
344 | } | |
b9179170 MV |
345 | else if (strcmp(Cmd, "help") == 0) |
346 | ; // no options for help so no need to implement it in each | |
011188e3 DK |
347 | else |
348 | switch (Program) | |
349 | { | |
350 | case APT_CMD::APT: addArgumentsAPT(Args, Cmd); break; | |
351 | case APT_CMD::APT_GET: addArgumentsAPTGet(Args, Cmd); break; | |
352 | case APT_CMD::APT_CACHE: addArgumentsAPTCache(Args, Cmd); break; | |
353 | case APT_CMD::APT_CDROM: addArgumentsAPTCDROM(Args, Cmd); break; | |
354 | case APT_CMD::APT_CONFIG: addArgumentsAPTConfig(Args, Cmd); break; | |
385d9f2f | 355 | case APT_CMD::APT_DUMP_SOLVER: addArgumentsAPTDumpSolver(Args, Cmd); break; |
011188e3 DK |
356 | case APT_CMD::APT_EXTRACTTEMPLATES: addArgumentsAPTExtractTemplates(Args, Cmd); break; |
357 | case APT_CMD::APT_FTPARCHIVE: addArgumentsAPTFTPArchive(Args, Cmd); break; | |
358 | case APT_CMD::APT_HELPER: addArgumentsAPTHelper(Args, Cmd); break; | |
359 | case APT_CMD::APT_INTERNAL_SOLVER: addArgumentsAPTInternalSolver(Args, Cmd); break; | |
360 | case APT_CMD::APT_MARK: addArgumentsAPTMark(Args, Cmd); break; | |
361 | case APT_CMD::APT_SORTPKG: addArgumentsAPTSortPkgs(Args, Cmd); break; | |
362 | } | |
b9179170 MV |
363 | |
364 | // options without a command | |
365 | addArg('h', "help", "help", 0); | |
366 | addArg('v', "version", "version", 0); | |
367 | // general options | |
368 | addArg('q', "quiet", "quiet", CommandLine::IntLevel); | |
369 | addArg('q', "silent", "quiet", CommandLine::IntLevel); | |
370 | addArg('c', "config-file", 0, CommandLine::ConfigFile); | |
371 | addArg('o', "option", 0, CommandLine::ArbItem); | |
372 | addArg(0, NULL, NULL, 0); | |
373 | ||
374 | return Args; | |
375 | } | |
376 | /*}}}*/ | |
377 | #undef CmdMatches | |
378 | #undef addArg | |
8561c2fe | 379 | static void ShowHelpListCommands(std::vector<aptDispatchWithHelp> const &Cmds)/*{{{*/ |
41d39345 | 380 | { |
8561c2fe DK |
381 | if (Cmds.empty() || Cmds[0].Match == nullptr) |
382 | return; | |
383 | std::cout << std::endl << _("Most used commands:") << std::endl; | |
384 | for (auto const &c: Cmds) | |
385 | { | |
386 | if (c.Help == nullptr) | |
387 | continue; | |
388 | std::cout << " " << c.Match << " - " << c.Help << std::endl; | |
389 | } | |
41d39345 DK |
390 | } |
391 | /*}}}*/ | |
90986d4d DK |
392 | static bool ShowCommonHelp(APT_CMD const Binary, CommandLine &CmdL, std::vector<aptDispatchWithHelp> const &Cmds,/*{{{*/ |
393 | bool (*ShowHelp)(CommandLine &)) | |
41d39345 | 394 | { |
8561c2fe DK |
395 | std::cout << PACKAGE << " " << PACKAGE_VERSION << " (" << COMMON_ARCH << ")" << std::endl; |
396 | if (_config->FindB("version") == true && Binary != APT_CMD::APT_GET) | |
397 | return true; | |
398 | if (ShowHelp(CmdL) == false) | |
399 | return false; | |
400 | if (_config->FindB("version") == true || Binary == APT_CMD::APT_FTPARCHIVE) | |
401 | return true; | |
402 | ShowHelpListCommands(Cmds); | |
403 | std::cout << std::endl; | |
404 | char const * cmd = nullptr; | |
405 | switch (Binary) | |
41d39345 | 406 | { |
8561c2fe DK |
407 | case APT_CMD::APT: cmd = "apt(8)"; break; |
408 | case APT_CMD::APT_CACHE: cmd = "apt-cache(8)"; break; | |
409 | case APT_CMD::APT_CDROM: cmd = "apt-cdrom(8)"; break; | |
410 | case APT_CMD::APT_CONFIG: cmd = "apt-config(8)"; break; | |
385d9f2f | 411 | case APT_CMD::APT_DUMP_SOLVER: cmd = nullptr; break; |
8561c2fe DK |
412 | case APT_CMD::APT_EXTRACTTEMPLATES: cmd = "apt-extracttemplates(1)"; break; |
413 | case APT_CMD::APT_FTPARCHIVE: cmd = "apt-ftparchive(1)"; break; | |
414 | case APT_CMD::APT_GET: cmd = "apt-get(8)"; break; | |
415 | case APT_CMD::APT_HELPER: cmd = nullptr; break; | |
416 | case APT_CMD::APT_INTERNAL_SOLVER: cmd = nullptr; break; | |
417 | case APT_CMD::APT_MARK: cmd = "apt-mark(8)"; break; | |
418 | case APT_CMD::APT_SORTPKG: cmd = "apt-sortpkgs(1)"; break; | |
41d39345 | 419 | } |
8561c2fe DK |
420 | if (cmd != nullptr) |
421 | ioprintf(std::cout, _("See %s for more information about the available commands."), cmd); | |
385d9f2f DK |
422 | if (Binary != APT_CMD::APT_DUMP_SOLVER && Binary != APT_CMD::APT_INTERNAL_SOLVER) |
423 | std::cout << std::endl << | |
424 | _("Configuration options and syntax is detailed in apt.conf(5).\n" | |
425 | "Information about how to configure sources can be found in sources.list(5).\n" | |
426 | "Package and version choices can be expressed via apt_preferences(5).\n" | |
427 | "Security details are available in apt-secure(8).\n"); | |
8561c2fe DK |
428 | if (Binary == APT_CMD::APT_GET || Binary == APT_CMD::APT) |
429 | std::cout << std::right << std::setw(70) << _("This APT has Super Cow Powers.") << std::endl; | |
385d9f2f | 430 | else if (Binary == APT_CMD::APT_HELPER || Binary == APT_CMD::APT_DUMP_SOLVER) |
8561c2fe DK |
431 | std::cout << std::right << std::setw(70) << _("This APT helper has Super Meep Powers.") << std::endl; |
432 | return true; | |
41d39345 DK |
433 | } |
434 | /*}}}*/ | |
501cd23e DK |
435 | static void BinarySpecificConfiguration(char const * const Binary) /*{{{*/ |
436 | { | |
437 | std::string const binary = flNotDir(Binary); | |
438 | if (binary == "apt" || binary == "apt-config") | |
439 | { | |
631800b1 | 440 | _config->CndSet("Binary::apt::APT::Color", true); |
501cd23e DK |
441 | _config->CndSet("Binary::apt::APT::Cache::Show::Version", 2); |
442 | _config->CndSet("Binary::apt::APT::Cache::AllVersions", false); | |
443 | _config->CndSet("Binary::apt::APT::Cache::ShowVirtuals", true); | |
631800b1 | 444 | _config->CndSet("Binary::apt::APT::Cache::Search::Version", 2); |
c094c868 DK |
445 | _config->CndSet("Binary::apt::APT::Cache::ShowDependencyType", true); |
446 | _config->CndSet("Binary::apt::APT::Cache::ShowVersion", true); | |
631800b1 DK |
447 | _config->CndSet("Binary::apt::APT::Get::Upgrade-Allow-New", true); |
448 | _config->CndSet("Binary::apt::APT::Cmd::Show-Update-Stats", true); | |
449 | _config->CndSet("Binary::apt::DPkg::Progress-Fancy", true); | |
995a4bf6 | 450 | _config->CndSet("Binary::apt::Acquire::AllowInsecureRepositories", false); |
ee02b5b3 | 451 | _config->CndSet("Binary::apt::APT::Keep-Downloaded-Packages", false); |
501cd23e DK |
452 | } |
453 | ||
454 | _config->Set("Binary", binary); | |
455 | std::string const conf = "Binary::" + binary; | |
456 | _config->MoveSubTree(conf.c_str(), NULL); | |
457 | } | |
458 | /*}}}*/ | |
6079b276 | 459 | std::vector<CommandLine::Dispatch> ParseCommandLine(CommandLine &CmdL, APT_CMD const Binary,/*{{{*/ |
90986d4d DK |
460 | Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char *argv[], |
461 | bool (*ShowHelp)(CommandLine &), std::vector<aptDispatchWithHelp> (*GetCommands)(void)) | |
ad7e0941 | 462 | { |
570ec96d | 463 | InitLocale(Binary); |
c3ded84c DK |
464 | if (Cnf != NULL && pkgInitConfig(**Cnf) == false) |
465 | { | |
466 | _error->DumpErrors(); | |
467 | exit(100); | |
468 | } | |
469 | ||
470 | if (likely(argc != 0 && argv[0] != NULL)) | |
501cd23e | 471 | BinarySpecificConfiguration(argv[0]); |
c3ded84c | 472 | |
6079b276 DK |
473 | std::vector<aptDispatchWithHelp> const CmdsWithHelp = GetCommands(); |
474 | std::vector<CommandLine::Dispatch> Cmds; | |
41d39345 DK |
475 | if (CmdsWithHelp.empty() == false) |
476 | { | |
477 | CommandLine::Dispatch const help = { "help", [](CommandLine &){return false;} }; | |
478 | Cmds.push_back(std::move(help)); | |
479 | } | |
6079b276 DK |
480 | for (auto const& cmd : CmdsWithHelp) |
481 | Cmds.push_back({cmd.Match, cmd.Handler}); | |
482 | ||
011188e3 DK |
483 | // Args running out of scope invalidates the pointer stored in CmdL, |
484 | // but we don't use the pointer after this function, so we ignore | |
485 | // this problem for now and figure something out if we have to. | |
486 | std::vector<CommandLine::Args> Args; | |
487 | if (Cmds.empty() == false && Cmds[0].Handler != nullptr) | |
488 | Args = getCommandArgs(Binary, CommandLine::GetCommand(Cmds.data(), argc, argv)); | |
489 | else | |
490 | Args = getCommandArgs(Binary, nullptr); | |
491 | CmdL = CommandLine(Args.data(), _config); | |
492 | ||
c3ded84c | 493 | if (CmdL.Parse(argc,argv) == false || |
ad7e0941 DK |
494 | (Sys != NULL && pkgInitSystem(*_config, *Sys) == false)) |
495 | { | |
496 | if (_config->FindB("version") == true) | |
90986d4d | 497 | ShowCommonHelp(Binary, CmdL, CmdsWithHelp, ShowHelp); |
ad7e0941 DK |
498 | |
499 | _error->DumpErrors(); | |
500 | exit(100); | |
501 | } | |
502 | ||
503 | // See if the help should be shown | |
cbbee23e DK |
504 | if (_config->FindB("help") == true || _config->FindB("version") == true || |
505 | (CmdL.FileSize() > 0 && strcmp(CmdL.FileList[0], "help") == 0)) | |
ad7e0941 | 506 | { |
90986d4d | 507 | ShowCommonHelp(Binary, CmdL, CmdsWithHelp, ShowHelp); |
ad7e0941 DK |
508 | exit(0); |
509 | } | |
011188e3 | 510 | if (Cmds.empty() == false && CmdL.FileSize() == 0) |
ad7e0941 | 511 | { |
90986d4d | 512 | ShowCommonHelp(Binary, CmdL, CmdsWithHelp, ShowHelp); |
ad7e0941 DK |
513 | exit(1); |
514 | } | |
011188e3 | 515 | return Cmds; |
ad7e0941 DK |
516 | } |
517 | /*}}}*/ | |
6079b276 | 518 | unsigned short DispatchCommandLine(CommandLine &CmdL, std::vector<CommandLine::Dispatch> const &Cmds) /*{{{*/ |
e7e10e47 DK |
519 | { |
520 | // Match the operation | |
011188e3 | 521 | bool const returned = Cmds.empty() ? true : CmdL.DispatchArg(Cmds.data()); |
e7e10e47 DK |
522 | |
523 | // Print any errors or warnings found during parsing | |
524 | bool const Errors = _error->PendingError(); | |
525 | if (_config->FindI("quiet",0) > 0) | |
526 | _error->DumpErrors(); | |
527 | else | |
528 | _error->DumpErrors(GlobalError::DEBUG); | |
529 | if (returned == false) | |
530 | return 100; | |
531 | return Errors == true ? 100 : 0; | |
532 | } | |
533 | /*}}}*/ |