]>
git.saurik.com Git - apt.git/blob - apt-private/private-cmndline.cc
1 // Include Files /*{{{*/
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>
12 #include <apt-private/private-cmndline.h>
13 #include <apt-private/private-main.h>
25 APT_SENTINEL
static bool strcmp_match_in_list(char const * const Cmd
, ...) /*{{{*/
32 char const * Match
= NULL
;
33 while ((Match
= va_arg(args
, char const *)) != NULL
)
35 if (strcmp(Cmd
, Match
) != 0)
44 #define addArg(w,x,y,z) Args.push_back(CommandLine::MakeArgs(w,x,y,z))
45 #define CmdMatches(...) strcmp_match_in_list(Cmd, __VA_ARGS__, NULL)
46 static bool addArgumentsAPTCache(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
48 if (CmdMatches("depends", "rdepends", "xvcg", "dotty"))
50 addArg('i', "important", "APT::Cache::Important", 0);
51 addArg(0, "installed", "APT::Cache::Installed", 0);
52 addArg(0, "pre-depends", "APT::Cache::ShowPre-Depends", 0);
53 addArg(0, "depends", "APT::Cache::ShowDepends", 0);
54 addArg(0, "recommends", "APT::Cache::ShowRecommends", 0);
55 addArg(0, "suggests", "APT::Cache::ShowSuggests", 0);
56 addArg(0, "replaces", "APT::Cache::ShowReplaces", 0);
57 addArg(0, "breaks", "APT::Cache::ShowBreaks", 0);
58 addArg(0, "conflicts", "APT::Cache::ShowConflicts", 0);
59 addArg(0, "enhances", "APT::Cache::ShowEnhances", 0);
60 addArg(0, "recurse", "APT::Cache::RecurseDepends", 0);
61 addArg(0, "implicit", "APT::Cache::ShowImplicit", 0);
63 else if (CmdMatches("search"))
65 addArg('n', "names-only", "APT::Cache::NamesOnly", 0);
66 addArg('f', "full", "APT::Cache::ShowFull", 0);
68 else if (CmdMatches("show"))
70 addArg('a', "all-versions", "APT::Cache::AllVersions", 0);
72 else if (CmdMatches("pkgnames"))
74 addArg(0, "all-names", "APT::Cache::AllNames", 0);
76 else if (CmdMatches("unmet"))
78 addArg('i', "important", "APT::Cache::Important", 0);
80 else if (CmdMatches("showsrc"))
82 addArg(0,"only-source","APT::Cache::Only-Source",0);
84 else if (CmdMatches("gencaches", "showpkg", "stats", "dump",
85 "dumpavail", "showauto", "policy", "madison"))
90 bool const found_something
= Args
.empty() == false;
92 // FIXME: move to the correct command(s)
93 addArg('g', "generate", "APT::Cache::Generate", 0);
94 addArg('t', "target-release", "APT::Default-Release", CommandLine::HasArg
);
95 addArg('t', "default-release", "APT::Default-Release", CommandLine::HasArg
);
97 addArg('p', "pkg-cache", "Dir::Cache::pkgcache", CommandLine::HasArg
);
98 addArg('s', "src-cache", "Dir::Cache::srcpkgcache", CommandLine::HasArg
);
99 addArg(0, "with-source", "APT::Sources::With::", CommandLine::HasArg
);
101 return found_something
;
104 static bool addArgumentsAPTCDROM(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
106 if (CmdMatches("add", "ident") == false)
109 // FIXME: move to the correct command(s)
110 addArg(0, "auto-detect", "Acquire::cdrom::AutoDetect", CommandLine::Boolean
);
111 addArg('d', "cdrom", "Acquire::cdrom::mount", CommandLine::HasArg
);
112 addArg('r', "rename", "APT::CDROM::Rename", 0);
113 addArg('m', "no-mount", "APT::CDROM::NoMount", 0);
114 addArg('f', "fast", "APT::CDROM::Fast", 0);
115 addArg('n', "just-print", "APT::CDROM::NoAct", 0);
116 addArg('n', "recon", "APT::CDROM::NoAct", 0);
117 addArg('n', "no-act", "APT::CDROM::NoAct", 0);
118 addArg('a', "thorough", "APT::CDROM::Thorough", 0);
122 static bool addArgumentsAPTConfig(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
124 if (CmdMatches("dump"))
126 addArg(0,"empty","APT::Config::Dump::EmptyValue",CommandLine::Boolean
);
127 addArg(0,"format","APT::Config::Dump::Format",CommandLine::HasArg
);
129 else if (CmdMatches("shell"))
137 static bool addArgumentsAPTDumpSolver(std::vector
<CommandLine::Args
> &Args
, char const * const)/*{{{*/
139 addArg(0,"user","APT::Solver::RunAsUser",CommandLine::HasArg
);
143 static bool addArgumentsAPTExtractTemplates(std::vector
<CommandLine::Args
> &Args
, char const * const)/*{{{*/
145 addArg('t',"tempdir","APT::ExtractTemplates::TempDir",CommandLine::HasArg
);
149 static bool addArgumentsAPTFTPArchive(std::vector
<CommandLine::Args
> &Args
, char const * const)/*{{{*/
151 addArg(0,"md5","APT::FTPArchive::MD5",0);
152 addArg(0,"sha1","APT::FTPArchive::SHA1",0);
153 addArg(0,"sha256","APT::FTPArchive::SHA256",0);
154 addArg(0,"sha512","APT::FTPArchive::SHA512",0);
155 addArg('d',"db","APT::FTPArchive::DB",CommandLine::HasArg
);
156 addArg('s',"source-override","APT::FTPArchive::SourceOverride",CommandLine::HasArg
);
157 addArg(0,"delink","APT::FTPArchive::DeLinkAct",0);
158 addArg(0,"readonly","APT::FTPArchive::ReadOnlyDB",0);
159 addArg(0,"contents","APT::FTPArchive::Contents",0);
160 addArg('a',"arch","APT::FTPArchive::Architecture",CommandLine::HasArg
);
164 static bool addArgumentsAPTInternalPlanner(std::vector
<CommandLine::Args
> &, char const * const)/*{{{*/
169 static bool addArgumentsAPTInternalSolver(std::vector
<CommandLine::Args
> &, char const * const)/*{{{*/
174 static bool addArgumentsAPTHelper(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
176 if (CmdMatches("cat-file"))
178 addArg('C', "compress", "Apt-Helper::Cat-File::Compress",CommandLine::HasArg
);
183 static bool addArgumentsAPTGet(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
185 if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade",
186 "dselect-upgrade", "autoremove", "full-upgrade"))
188 addArg(0, "show-progress", "DpkgPM::Progress", 0);
189 addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0);
190 addArg(0, "purge", "APT::Get::Purge", 0);
191 addArg('V',"verbose-versions","APT::Get::Show-Versions",0);
192 addArg(0, "auto-remove", "APT::Get::AutomaticRemove", 0);
193 addArg(0, "reinstall", "APT::Get::ReInstall", 0);
194 addArg(0, "solver", "APT::Solver", CommandLine::HasArg
);
195 addArg(0, "planner", "APT::Planner", CommandLine::HasArg
);
196 if (CmdMatches("upgrade"))
198 addArg(0, "new-pkgs", "APT::Get::Upgrade-Allow-New",
199 CommandLine::Boolean
);
202 else if (CmdMatches("update"))
204 addArg(0, "list-cleanup", "APT::Get::List-Cleanup", 0);
206 else if (CmdMatches("source"))
208 addArg('b', "compile", "APT::Get::Compile", 0);
209 addArg('b', "build", "APT::Get::Compile", 0);
210 addArg('P', "build-profiles", "APT::Build-Profiles", CommandLine::HasArg
);
211 addArg(0, "diff-only", "APT::Get::Diff-Only", 0);
212 addArg(0, "debian-only", "APT::Get::Diff-Only", 0);
213 addArg(0, "tar-only", "APT::Get::Tar-Only", 0);
214 addArg(0, "dsc-only", "APT::Get::Dsc-Only", 0);
216 else if (CmdMatches("build-dep"))
218 addArg('a', "host-architecture", "APT::Get::Host-Architecture", CommandLine::HasArg
);
219 addArg('P', "build-profiles", "APT::Build-Profiles", CommandLine::HasArg
);
220 addArg(0, "purge", "APT::Get::Purge", 0);
221 addArg(0, "solver", "APT::Solver", CommandLine::HasArg
);
222 // this has no effect *but* sbuild is using it (see LP: #1255806)
223 // once sbuild is fixed, this option can be removed
224 addArg('f', "fix-broken", "APT::Get::Fix-Broken", 0);
226 else if (CmdMatches("indextargets"))
228 addArg(0,"format","APT::Get::IndexTargets::Format", CommandLine::HasArg
);
229 addArg(0,"release-info","APT::Get::IndexTargets::ReleaseInfo", 0);
231 else if (CmdMatches("clean", "autoclean", "auto-clean", "check", "download", "changelog") ||
232 CmdMatches("markauto", "unmarkauto")) // deprecated commands
234 else if (CmdMatches("moo"))
235 addArg(0, "color", "APT::Moo::Color", 0);
237 if (CmdMatches("install", "remove", "purge", "upgrade", "dist-upgrade",
238 "dselect-upgrade", "autoremove", "auto-remove", "clean", "autoclean", "auto-clean", "check",
239 "build-dep", "full-upgrade", "source"))
241 addArg('s', "simulate", "APT::Get::Simulate", 0);
242 addArg('s', "just-print", "APT::Get::Simulate", 0);
243 addArg('s', "recon", "APT::Get::Simulate", 0);
244 addArg('s', "dry-run", "APT::Get::Simulate", 0);
245 addArg('s', "no-act", "APT::Get::Simulate", 0);
248 bool const found_something
= Args
.empty() == false;
250 // FIXME: move to the correct command(s)
251 addArg('d',"download-only","APT::Get::Download-Only",0);
252 addArg('y',"yes","APT::Get::Assume-Yes",0);
253 addArg('y',"assume-yes","APT::Get::Assume-Yes",0);
254 addArg(0,"assume-no","APT::Get::Assume-No",0);
255 addArg('u',"show-upgraded","APT::Get::Show-Upgraded",0);
256 addArg('m',"ignore-missing","APT::Get::Fix-Missing",0);
257 addArg('t',"target-release","APT::Default-Release",CommandLine::HasArg
);
258 addArg('t',"default-release","APT::Default-Release",CommandLine::HasArg
);
259 addArg(0,"download","APT::Get::Download",0);
260 addArg(0,"fix-missing","APT::Get::Fix-Missing",0);
261 addArg(0,"ignore-hold","APT::Ignore-Hold",0);
262 addArg(0,"upgrade","APT::Get::upgrade",0);
263 addArg(0,"only-upgrade","APT::Get::Only-Upgrade",0);
264 addArg(0,"allow-change-held-packages","APT::Get::allow-change-held-packages",CommandLine::Boolean
);
265 addArg(0,"allow-remove-essential","APT::Get::allow-remove-essential",CommandLine::Boolean
);
266 addArg(0,"allow-downgrades","APT::Get::allow-downgrades",CommandLine::Boolean
);
267 addArg(0,"force-yes","APT::Get::force-yes",0);
268 addArg(0,"print-uris","APT::Get::Print-URIs",0);
269 addArg(0,"trivial-only","APT::Get::Trivial-Only",0);
270 addArg(0,"remove","APT::Get::Remove",0);
271 addArg(0,"only-source","APT::Get::Only-Source",0);
272 addArg(0,"arch-only","APT::Get::Arch-Only",0);
273 addArg(0,"allow-unauthenticated","APT::Get::AllowUnauthenticated",0);
274 addArg(0,"allow-insecure-repositories","Acquire::AllowInsecureRepositories",0);
275 addArg(0,"allow-weak-repositories","Acquire::AllowWeakRepositories",0);
276 addArg(0,"install-recommends","APT::Install-Recommends",CommandLine::Boolean
);
277 addArg(0,"install-suggests","APT::Install-Suggests",CommandLine::Boolean
);
278 addArg(0,"fix-policy","APT::Get::Fix-Policy-Broken",0);
279 addArg(0, "with-source", "APT::Sources::With::", CommandLine::HasArg
);
281 return found_something
;
284 static bool addArgumentsAPTMark(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
286 if (CmdMatches("auto", "manual", "hold", "unhold", "showauto",
287 "showmanual", "showhold", "showholds",
288 "markauto", "unmarkauto"))
290 addArg('f',"file","Dir::State::extended_states",CommandLine::HasArg
);
292 else if (CmdMatches("install", "remove", "deinstall", "purge",
293 "showinstall", "showinstalls", "showremove", "showremoves",
294 "showdeinstall", "showdeinstalls", "showpurge", "showpurges"))
299 if (CmdMatches("markauto", "unmarkauto"))
301 addArg('v',"verbose","APT::MarkAuto::Verbose",0);
304 if (strncmp(Cmd
, "show", strlen("show")) != 0)
306 addArg('s',"simulate","APT::Mark::Simulate",0);
307 addArg('s',"just-print","APT::Mark::Simulate",0);
308 addArg('s',"recon","APT::Mark::Simulate",0);
309 addArg('s',"dry-run","APT::Mark::Simulate",0);
310 addArg('s',"no-act","APT::Mark::Simulate",0);
312 addArg(0, "with-source", "APT::Sources::With::", CommandLine::HasArg
);
317 static bool addArgumentsAPTSortPkgs(std::vector
<CommandLine::Args
> &Args
, char const * const)/*{{{*/
319 addArg('s',"source","APT::SortPkgs::Source",0);
323 static bool addArgumentsAPT(std::vector
<CommandLine::Args
> &Args
, char const * const Cmd
)/*{{{*/
325 if (CmdMatches("list"))
327 addArg('i',"installed","APT::Cmd::Installed",0);
328 addArg(0,"upgradeable","APT::Cmd::Upgradable",0);
329 addArg('u',"upgradable","APT::Cmd::Upgradable",0);
330 addArg(0,"manual-installed","APT::Cmd::Manual-Installed",0);
331 addArg('v', "verbose", "APT::Cmd::List-Include-Summary", 0);
332 addArg('a', "all-versions", "APT::Cmd::All-Versions", 0);
334 else if (CmdMatches("show"))
336 addArg('a', "all-versions", "APT::Cache::AllVersions", 0);
338 else if (addArgumentsAPTGet(Args
, Cmd
) || addArgumentsAPTCache(Args
, Cmd
))
340 // we have no (supported) command-name overlaps so far, so we call
341 // specifics in order until we find one which adds arguments
346 addArg(0, "with-source", "APT::Sources::With::", CommandLine::HasArg
);
351 std::vector
<CommandLine::Args
> getCommandArgs(APT_CMD
const Program
, char const * const Cmd
)/*{{{*/
353 std::vector
<CommandLine::Args
> Args
;
355 if (Cmd
!= nullptr && strcmp(Cmd
, "help") == 0)
356 ; // no options for help so no need to implement it in each
360 case APT_CMD::APT
: addArgumentsAPT(Args
, Cmd
); break;
361 case APT_CMD::APT_GET
: addArgumentsAPTGet(Args
, Cmd
); break;
362 case APT_CMD::APT_CACHE
: addArgumentsAPTCache(Args
, Cmd
); break;
363 case APT_CMD::APT_CDROM
: addArgumentsAPTCDROM(Args
, Cmd
); break;
364 case APT_CMD::APT_CONFIG
: addArgumentsAPTConfig(Args
, Cmd
); break;
365 case APT_CMD::APT_DUMP_SOLVER
: addArgumentsAPTDumpSolver(Args
, Cmd
); break;
366 case APT_CMD::APT_EXTRACTTEMPLATES
: addArgumentsAPTExtractTemplates(Args
, Cmd
); break;
367 case APT_CMD::APT_FTPARCHIVE
: addArgumentsAPTFTPArchive(Args
, Cmd
); break;
368 case APT_CMD::APT_HELPER
: addArgumentsAPTHelper(Args
, Cmd
); break;
369 case APT_CMD::APT_INTERNAL_PLANNER
: addArgumentsAPTInternalPlanner(Args
, Cmd
); break;
370 case APT_CMD::APT_INTERNAL_SOLVER
: addArgumentsAPTInternalSolver(Args
, Cmd
); break;
371 case APT_CMD::APT_MARK
: addArgumentsAPTMark(Args
, Cmd
); break;
372 case APT_CMD::APT_SORTPKG
: addArgumentsAPTSortPkgs(Args
, Cmd
); break;
375 // options without a command
376 addArg('h', "help", "help", 0);
377 addArg('v', "version", "version", 0);
379 addArg('q', "quiet", "quiet", CommandLine::IntLevel
);
380 addArg('q', "silent", "quiet", CommandLine::IntLevel
);
381 addArg('c', "config-file", 0, CommandLine::ConfigFile
);
382 addArg('o', "option", 0, CommandLine::ArbItem
);
383 addArg(0, NULL
, NULL
, 0);
389 static void ShowHelpListCommands(std::vector
<aptDispatchWithHelp
> const &Cmds
)/*{{{*/
391 if (Cmds
.empty() || Cmds
[0].Match
== nullptr)
393 std::cout
<< std::endl
<< _("Most used commands:") << std::endl
;
394 for (auto const &c
: Cmds
)
396 if (c
.Help
== nullptr)
398 std::cout
<< " " << c
.Match
<< " - " << c
.Help
<< std::endl
;
402 static bool ShowCommonHelp(APT_CMD
const Binary
, CommandLine
&CmdL
, std::vector
<aptDispatchWithHelp
> const &Cmds
,/*{{{*/
403 bool (*ShowHelp
)(CommandLine
&))
405 std::cout
<< PACKAGE
<< " " << PACKAGE_VERSION
<< " (" << COMMON_ARCH
<< ")" << std::endl
;
406 if (_config
->FindB("version") == true && Binary
!= APT_CMD::APT_GET
)
408 if (ShowHelp(CmdL
) == false)
410 if (_config
->FindB("version") == true || Binary
== APT_CMD::APT_FTPARCHIVE
)
412 ShowHelpListCommands(Cmds
);
413 std::cout
<< std::endl
;
414 char const * cmd
= nullptr;
417 case APT_CMD::APT
: cmd
= "apt(8)"; break;
418 case APT_CMD::APT_CACHE
: cmd
= "apt-cache(8)"; break;
419 case APT_CMD::APT_CDROM
: cmd
= "apt-cdrom(8)"; break;
420 case APT_CMD::APT_CONFIG
: cmd
= "apt-config(8)"; break;
421 case APT_CMD::APT_DUMP_SOLVER
: cmd
= nullptr; break;
422 case APT_CMD::APT_EXTRACTTEMPLATES
: cmd
= "apt-extracttemplates(1)"; break;
423 case APT_CMD::APT_FTPARCHIVE
: cmd
= "apt-ftparchive(1)"; break;
424 case APT_CMD::APT_GET
: cmd
= "apt-get(8)"; break;
425 case APT_CMD::APT_HELPER
: cmd
= nullptr; break;
426 case APT_CMD::APT_INTERNAL_PLANNER
: cmd
= nullptr; break;
427 case APT_CMD::APT_INTERNAL_SOLVER
: cmd
= nullptr; break;
428 case APT_CMD::APT_MARK
: cmd
= "apt-mark(8)"; break;
429 case APT_CMD::APT_SORTPKG
: cmd
= "apt-sortpkgs(1)"; break;
432 ioprintf(std::cout
, _("See %s for more information about the available commands."), cmd
);
433 if (Binary
!= APT_CMD::APT_DUMP_SOLVER
&& Binary
!= APT_CMD::APT_INTERNAL_SOLVER
&&
434 Binary
!= APT_CMD::APT_INTERNAL_PLANNER
)
435 std::cout
<< std::endl
<<
436 _("Configuration options and syntax is detailed in apt.conf(5).\n"
437 "Information about how to configure sources can be found in sources.list(5).\n"
438 "Package and version choices can be expressed via apt_preferences(5).\n"
439 "Security details are available in apt-secure(8).\n");
440 if (Binary
== APT_CMD::APT_GET
|| Binary
== APT_CMD::APT
)
441 std::cout
<< std::right
<< std::setw(70) << _("This APT has Super Cow Powers.") << std::endl
;
442 else if (Binary
== APT_CMD::APT_HELPER
|| Binary
== APT_CMD::APT_DUMP_SOLVER
)
443 std::cout
<< std::right
<< std::setw(70) << _("This APT helper has Super Meep Powers.") << std::endl
;
447 static void BinarySpecificConfiguration(char const * const Binary
) /*{{{*/
449 std::string
const binary
= flNotDir(Binary
);
450 if (binary
== "apt" || binary
== "apt-config")
452 _config
->CndSet("Binary::apt::APT::Color", true);
453 _config
->CndSet("Binary::apt::APT::Cache::Show::Version", 2);
454 _config
->CndSet("Binary::apt::APT::Cache::AllVersions", false);
455 _config
->CndSet("Binary::apt::APT::Cache::ShowVirtuals", true);
456 _config
->CndSet("Binary::apt::APT::Cache::Search::Version", 2);
457 _config
->CndSet("Binary::apt::APT::Cache::ShowDependencyType", true);
458 _config
->CndSet("Binary::apt::APT::Cache::ShowVersion", true);
459 _config
->CndSet("Binary::apt::APT::Get::Upgrade-Allow-New", true);
460 _config
->CndSet("Binary::apt::APT::Cmd::Show-Update-Stats", true);
461 _config
->CndSet("Binary::apt::DPkg::Progress-Fancy", true);
462 _config
->CndSet("Binary::apt::APT::Keep-Downloaded-Packages", false);
464 if (binary
== "apt-config")
465 _config
->CndSet("Binary::apt-get::Acquire::AllowInsecureRepositories", true);
467 _config
->Set("Binary", binary
);
470 static void BinaryCommandSpecificConfiguration(char const * const Binary
, char const * const Cmd
)/*{{{*/
472 std::string
const binary
= flNotDir(Binary
);
473 if (binary
== "apt-get" && CmdMatches("update"))
474 _config
->CndSet("Binary::apt-get::Acquire::AllowInsecureRepositories", true);
478 std::vector
<CommandLine::Dispatch
> ParseCommandLine(CommandLine
&CmdL
, APT_CMD
const Binary
,/*{{{*/
479 Configuration
* const * const Cnf
, pkgSystem
** const Sys
, int const argc
, const char *argv
[],
480 bool (*ShowHelp
)(CommandLine
&), std::vector
<aptDispatchWithHelp
> (*GetCommands
)(void))
483 if (Cnf
!= NULL
&& pkgInitConfig(**Cnf
) == false)
485 _error
->DumpErrors();
489 if (likely(argc
!= 0 && argv
[0] != NULL
))
490 BinarySpecificConfiguration(argv
[0]);
492 std::vector
<aptDispatchWithHelp
> const CmdsWithHelp
= GetCommands();
493 std::vector
<CommandLine::Dispatch
> Cmds
;
494 if (CmdsWithHelp
.empty() == false)
496 CommandLine::Dispatch
const help
= { "help", [](CommandLine
&){return false;} };
497 Cmds
.push_back(std::move(help
));
499 for (auto const& cmd
: CmdsWithHelp
)
500 Cmds
.push_back({cmd
.Match
, cmd
.Handler
});
502 // Args running out of scope invalidates the pointer stored in CmdL,
503 // but we don't use the pointer after this function, so we ignore
504 // this problem for now and figure something out if we have to.
505 char const * CmdCalled
= nullptr;
506 if (Cmds
.empty() == false && Cmds
[0].Handler
!= nullptr)
507 CmdCalled
= CommandLine::GetCommand(Cmds
.data(), argc
, argv
);
508 if (CmdCalled
!= nullptr)
509 BinaryCommandSpecificConfiguration(argv
[0], CmdCalled
);
510 std::string
const conf
= "Binary::" + _config
->Find("Binary");
511 _config
->MoveSubTree(conf
.c_str(), nullptr);
512 auto Args
= getCommandArgs(Binary
, CmdCalled
);
513 CmdL
= CommandLine(Args
.data(), _config
);
515 if (CmdL
.Parse(argc
,argv
) == false ||
516 (Sys
!= NULL
&& pkgInitSystem(*_config
, *Sys
) == false))
518 if (_config
->FindB("version") == true)
519 ShowCommonHelp(Binary
, CmdL
, CmdsWithHelp
, ShowHelp
);
521 _error
->DumpErrors();
525 // See if the help should be shown
526 if (_config
->FindB("help") == true || _config
->FindB("version") == true ||
527 (CmdL
.FileSize() > 0 && strcmp(CmdL
.FileList
[0], "help") == 0))
529 ShowCommonHelp(Binary
, CmdL
, CmdsWithHelp
, ShowHelp
);
532 if (Cmds
.empty() == false && CmdL
.FileSize() == 0)
534 ShowCommonHelp(Binary
, CmdL
, CmdsWithHelp
, ShowHelp
);
540 unsigned short DispatchCommandLine(CommandLine
&CmdL
, std::vector
<CommandLine::Dispatch
> const &Cmds
) /*{{{*/
542 // Match the operation
543 bool const returned
= Cmds
.empty() ? true : CmdL
.DispatchArg(Cmds
.data());
545 // Print any errors or warnings found during parsing
546 bool const Errors
= _error
->PendingError();
547 if (_config
->FindI("quiet",0) > 0)
548 _error
->DumpErrors();
550 _error
->DumpErrors(GlobalError::DEBUG
);
551 if (returned
== false)
553 return Errors
== true ? 100 : 0;