summaryrefslogtreecommitdiff
path: root/apt-private
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-10-26 16:50:21 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2015-11-04 18:04:04 +0100
commit41d39345bdc31cb9b8be057cd678aa2890830437 (patch)
tree3aba387df084fca7bccc3838aabe7af92f819543 /apt-private
parent6079b276a959086ff18302cab752b6d7cfe5ad9f (diff)
deal with --version more centrally
Git-Dch: Ignore
Diffstat (limited to 'apt-private')
-rw-r--r--apt-private/private-cmndline.cc30
-rw-r--r--apt-private/private-cmndline.h1
2 files changed, 28 insertions, 3 deletions
diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc
index d80168fda..348b698ca 100644
--- a/apt-private/private-cmndline.cc
+++ b/apt-private/private-cmndline.cc
@@ -362,6 +362,25 @@ std::vector<CommandLine::Args> getCommandArgs(APT_CMD const Program, char const
/*}}}*/
#undef CmdMatches
#undef addArg
+static bool ShowCommonHelp(APT_CMD const Binary, CommandLine &CmdL, aptDispatchWithHelp const * Cmds)/*{{{*/
+{
+ std::cout << PACKAGE << " " << PACKAGE_VERSION << " (" << COMMON_ARCH << ")" << std::endl;
+ if (_config->FindB("version") == true && Binary != APT_CMD::APT_GET)
+ return true;
+ return ShowHelp(CmdL, Cmds);
+}
+ /*}}}*/
+void ShowHelpListCommands(aptDispatchWithHelp const * Cmds) /*{{{*/
+{
+ std::cout << _("Commands:") << std::endl;
+ for (; Cmds->Handler != nullptr; ++Cmds)
+ {
+ if (Cmds->Help == nullptr)
+ continue;
+ std::cout << " " << Cmds->Match << " - " << Cmds->Help << std::endl;
+ }
+}
+ /*}}}*/
static void BinarySpecificConfiguration(char const * const Binary) /*{{{*/
{
std::string const binary = flNotDir(Binary);
@@ -397,6 +416,11 @@ std::vector<CommandLine::Dispatch> ParseCommandLine(CommandLine &CmdL, APT_CMD c
std::vector<aptDispatchWithHelp> const CmdsWithHelp = GetCommands();
std::vector<CommandLine::Dispatch> Cmds;
+ if (CmdsWithHelp.empty() == false)
+ {
+ CommandLine::Dispatch const help = { "help", [](CommandLine &){return false;} };
+ Cmds.push_back(std::move(help));
+ }
for (auto const& cmd : CmdsWithHelp)
Cmds.push_back({cmd.Match, cmd.Handler});
@@ -414,7 +438,7 @@ std::vector<CommandLine::Dispatch> ParseCommandLine(CommandLine &CmdL, APT_CMD c
(Sys != NULL && pkgInitSystem(*_config, *Sys) == false))
{
if (_config->FindB("version") == true)
- ShowHelp(CmdL, CmdsWithHelp.data());
+ ShowCommonHelp(Binary, CmdL, CmdsWithHelp.data());
_error->DumpErrors();
exit(100);
@@ -424,12 +448,12 @@ std::vector<CommandLine::Dispatch> ParseCommandLine(CommandLine &CmdL, APT_CMD c
if (_config->FindB("help") == true || _config->FindB("version") == true ||
(CmdL.FileSize() > 0 && strcmp(CmdL.FileList[0], "help") == 0))
{
- ShowHelp(CmdL, CmdsWithHelp.data());
+ ShowCommonHelp(Binary, CmdL, CmdsWithHelp.data());
exit(0);
}
if (Cmds.empty() == false && CmdL.FileSize() == 0)
{
- ShowHelp(CmdL, CmdsWithHelp.data());
+ ShowCommonHelp(Binary, CmdL, CmdsWithHelp.data());
exit(1);
}
return Cmds;
diff --git a/apt-private/private-cmndline.h b/apt-private/private-cmndline.h
index ac17e2e8a..6a6885a33 100644
--- a/apt-private/private-cmndline.h
+++ b/apt-private/private-cmndline.h
@@ -32,6 +32,7 @@ struct aptDispatchWithHelp
std::vector<aptDispatchWithHelp> GetCommands();
bool ShowHelp(CommandLine &CmdL, aptDispatchWithHelp const * Cmds);
+APT_PUBLIC void ShowHelpListCommands(aptDispatchWithHelp const * Cmds);
APT_PUBLIC std::vector<CommandLine::Dispatch> ParseCommandLine(CommandLine &CmdL, APT_CMD const Binary,
Configuration * const * const Cnf, pkgSystem ** const Sys, int const argc, const char * argv[]);
APT_PUBLIC unsigned short DispatchCommandLine(CommandLine &CmdL, std::vector<CommandLine::Dispatch> const &Cmds);