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