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