summaryrefslogtreecommitdiff
path: root/apt-private
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2014-11-08 18:14:46 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2014-11-09 01:26:07 +0100
commitad7e0941b376d792911f240377094a2e78ca8756 (patch)
treea7e65478aa213bd7639cd45e8025989b6d413bfa /apt-private
parent20801f613690b330c79b4f7a30dc3ff52b722468 (diff)
streamline display of --help in all tools
By convention, if I run a tool with --help or --version I expect it to exit successfully with the usage, while if I do call it wrong (like without any parameters) I expect the usage message shown with a non-zero exit.
Diffstat (limited to 'apt-private')
-rw-r--r--apt-private/private-cmndline.cc33
-rw-r--r--apt-private/private-cmndline.h6
2 files changed, 39 insertions, 0 deletions
diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc
index aa01be757..bb9a00803 100644
--- a/apt-private/private-cmndline.cc
+++ b/apt-private/private-cmndline.cc
@@ -2,12 +2,17 @@
#include <config.h>
#include <apt-pkg/cmndline.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/pkgsystem.h>
+#include <apt-pkg/init.h>
+#include <apt-pkg/error.h>
#include <apt-private/private-cmndline.h>
#include <vector>
#include <stdarg.h>
#include <string.h>
+#include <stdlib.h>
#include <apti18n.h>
/*}}}*/
@@ -287,3 +292,31 @@ std::vector<CommandLine::Args> getCommandArgs(char const * const Program, char c
/*}}}*/
#undef CmdMatches
#undef addArg
+void ParseCommandLine(CommandLine &CmdL, CommandLine::Dispatch * const Cmds, CommandLine::Args * const Args,/*{{{*/
+ Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char *argv[], bool(*ShowHelp)(CommandLine &CmdL))
+{
+ CmdL = CommandLine(Args,_config);
+ if ((Cnf != NULL && pkgInitConfig(**Cnf) == false) ||
+ CmdL.Parse(argc,argv) == false ||
+ (Sys != NULL && pkgInitSystem(*_config, *Sys) == false))
+ {
+ if (_config->FindB("version") == true)
+ ShowHelp(CmdL);
+
+ _error->DumpErrors();
+ exit(100);
+ }
+
+ // See if the help should be shown
+ if (_config->FindB("help") == true || _config->FindB("version") == true)
+ {
+ ShowHelp(CmdL);
+ exit(0);
+ }
+ if (Cmds != NULL && CmdL.FileSize() == 0)
+ {
+ ShowHelp(CmdL);
+ exit(1);
+ }
+}
+ /*}}}*/
diff --git a/apt-private/private-cmndline.h b/apt-private/private-cmndline.h
index d0af16782..7b468456b 100644
--- a/apt-private/private-cmndline.h
+++ b/apt-private/private-cmndline.h
@@ -6,6 +6,12 @@
#include <vector>
+class Configuration;
+class pkgSystem;
+
APT_PUBLIC std::vector<CommandLine::Args> getCommandArgs(char const * const Program, char const * const Cmd);
+APT_PUBLIC void ParseCommandLine(CommandLine &CmdL, CommandLine::Dispatch * const Cmds, CommandLine::Args * const Args,
+ Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char * argv[],
+ bool(*ShowHelp)(CommandLine &CmdL));
#endif