Browse Source

deal with --version more centrally

Git-Dch: Ignore
David Kalnischkies 10 years ago
parent
commit
41d39345bd

+ 27 - 3
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;

+ 1 - 0
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);

+ 2 - 14
cmdline/apt-cache.cc

@@ -1524,26 +1524,14 @@ static bool GenCaches(CommandLine &)
 									/*}}}*/
 bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds)		/*{{{*/
 {
-   ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-
-   if (_config->FindB("version") == true)
-     return true;
-
    std::cout <<
     _("Usage: apt-cache [options] command\n"
       "       apt-cache [options] show pkg1 [pkg2 ...]\n"
       "\n"
       "apt-cache is a low-level tool used to query information\n"
       "from APT's binary cache files\n")
-    << std::endl
-    << _("Commands:") << std::endl;
-   for (; Cmds->Handler != nullptr; ++Cmds)
-   {
-      if (Cmds->Help == nullptr)
-	 continue;
-      std::cout << "  " << Cmds->Match << " - " << Cmds->Help << std::endl;
-   }
-
+    << std::endl;
+   ShowHelpListCommands(Cmds);
    std::cout << std::endl
     << _("Options:\n"
       "  -h   This help text.\n"

+ 2 - 14
cmdline/apt-cdrom.cc

@@ -205,26 +205,14 @@ static bool DoIdent(CommandLine &)
 									/*}}}*/
 bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds)		/*{{{*/
 {
-   ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-
-   if (_config->FindB("version") == true)
-      return true;
-
    std::cout <<
       _("Usage: apt-cdrom [options] command\n"
       "\n"
       "apt-cdrom is a tool to add CDROM's to APT's source list. The\n"
       "CDROM mount point and device information is taken from apt.conf,\n"
       "udev and /etc/fstab.\n")
-      << std::endl
-      << _("Commands:") << std::endl;
-   for (; Cmds->Handler != nullptr; ++Cmds)
-   {
-      if (Cmds->Help == nullptr)
-	 continue;
-      std::cout << "  " << Cmds->Match << " - " << Cmds->Help << std::endl;
-   }
-
+      << std::endl;
+   ShowHelpListCommands(Cmds);
    std::cout << std::endl <<
       _("Options:\n"
       "  -h   This help text\n"

+ 2 - 13
cmdline/apt-config.cc

@@ -78,23 +78,12 @@ static bool DoDump(CommandLine &CmdL)
 									/*}}}*/
 bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds)		/*{{{*/
 {
-   ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-   if (_config->FindB("version") == true)
-      return true;
-
    std::cout <<
       _("Usage: apt-config [options] command\n"
       "\n"
       "apt-config is a simple tool to read the APT config file\n")
-      << std::endl
-      << _("Commands:") << std::endl;
-   for (; Cmds->Handler != nullptr; ++Cmds)
-   {
-      if (Cmds->Help == nullptr)
-	 continue;
-      std::cout << "  " << Cmds->Match << " - " << Cmds->Help << std::endl;
-   }
-
+      << std::endl;
+   ShowHelpListCommands(Cmds);
    std::cout << std::endl <<
       _("Options:\n"
       "  -h   This help text.\n"

+ 0 - 5
cmdline/apt-extracttemplates.cc

@@ -217,11 +217,6 @@ bool DebFile::ParseInfo()
 									/*}}}*/
 bool ShowHelp(CommandLine &, aptDispatchWithHelp const *)		/*{{{*/
 {
-	ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-
-	if (_config->FindB("version") == true)
-		return true;
-
 	cout <<
 		_("Usage: apt-extracttemplates file1 [file2 ...]\n"
 		"\n"

+ 2 - 11
cmdline/apt-get.cc

@@ -1528,8 +1528,6 @@ static bool DoIndexTargets(CommandLine &CmdL)
 									/*}}}*/
 bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds)		/*{{{*/
 {
-   ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-
    if (_config->FindB("version") == true)
    {
       cout << _("Supported modules:") << endl;
@@ -1580,15 +1578,8 @@ bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds)		/*{{{*/
       "apt-get is a simple command line interface for downloading and\n"
       "installing packages. The most frequently used commands are update\n"
       "and install.\n")
-      << std::endl
-      << _("Commands:") << std::endl;
-   for (; Cmds->Handler != nullptr; ++Cmds)
-   {
-      if (Cmds->Help == nullptr)
-	 continue;
-      std::cout << "  " << Cmds->Match << " - " << Cmds->Help << std::endl;
-   }
-
+      << std::endl;
+   ShowHelpListCommands(Cmds);
    std::cout << std::endl <<
       _("Options:\n"
       "  -h  This help text.\n"

+ 2 - 15
cmdline/apt-helper.cc

@@ -107,26 +107,13 @@ static bool DoSrvLookup(CommandLine &CmdL)				/*{{{*/
 									/*}}}*/
 bool ShowHelp(CommandLine &, aptDispatchWithHelp const  * Cmds)		/*{{{*/
 {
-   ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-
-   if (_config->FindB("version") == true)
-     return true;
-
    std::cout <<
     _("Usage: apt-helper [options] command\n"
       "       apt-helper [options] download-file uri target-path\n"
       "\n"
       "apt-helper is a internal helper for apt\n")
-    << std::endl
-    << _("Commands:") << std::endl;
-
-   for (; Cmds->Handler != nullptr; ++Cmds)
-   {
-      if (Cmds->Help == nullptr)
-	 continue;
-      std::cout << "  " << Cmds->Match << " - " << Cmds->Help << std::endl;
-   }
-
+    << std::endl;
+   ShowHelpListCommands(Cmds);
    std::cout << std::endl <<
       _("This APT helper has Super Meep Powers.") << std::endl;
    return true;

+ 0 - 2
cmdline/apt-internal-solver.cc

@@ -43,8 +43,6 @@
 
 bool ShowHelp(CommandLine &, aptDispatchWithHelp const *)		/*{{{*/
 {
-	ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-
 	std::cout <<
 		_("Usage: apt-internal-solver\n"
 		"\n"

+ 2 - 12
cmdline/apt-mark.cc

@@ -282,23 +282,13 @@ static bool ShowSelection(CommandLine &CmdL)				/*{{{*/
 									/*}}}*/
 bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds)		/*{{{*/
 {
-   ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-
    std::cout <<
     _("Usage: apt-mark [options] {auto|manual} pkg1 [pkg2 ...]\n"
       "\n"
       "apt-mark is a simple command line interface for marking packages\n"
       "as manually or automatically installed. It can also list marks.\n")
-    << std::endl
-    << _("Commands:") << std::endl;
-
-   for (; Cmds->Handler != nullptr; ++Cmds)
-   {
-      if (Cmds->Help == nullptr)
-	 continue;
-      std::cout << "   " << Cmds->Match << " - " << Cmds->Help << std::endl;
-   }
-
+    << std::endl;
+   ShowHelpListCommands(Cmds);
    std::cout << std::endl
    << _("Options:\n"
       "  -h  This help text.\n"

+ 1 - 6
cmdline/apt-sortpkgs.cc

@@ -134,11 +134,7 @@ static bool DoIt(string InFile)
 									/*}}}*/
 bool ShowHelp(CommandLine &, aptDispatchWithHelp const *)		/*{{{*/
 {
-   ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-   if (_config->FindB("version") == true)
-      return true;
-   
-   cout <<
+   std::cout <<
     _("Usage: apt-sortpkgs [options] file1 [file2 ...]\n"
       "\n"
       "apt-sortpkgs is a simple tool to sort package files. The -s option is used\n"
@@ -149,7 +145,6 @@ bool ShowHelp(CommandLine &, aptDispatchWithHelp const *)		/*{{{*/
       "  -s   Use source file sorting\n"
       "  -c=? Read this configuration file\n"
       "  -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n");
-
    return true;
 }
 									/*}}}*/

+ 2 - 12
cmdline/apt.cc

@@ -39,22 +39,12 @@
 
 bool ShowHelp(CommandLine &, aptDispatchWithHelp const * Cmds)		/*{{{*/
 {
-   ioprintf(std::cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-
-   // FIXME: generate from CommandLine
    std::cout <<
     _("Usage: apt [options] command\n"
       "\n"
       "CLI for apt.\n")
-    << std::endl
-    << _("Commands:") << std::endl;
-   for (; Cmds->Handler != nullptr; ++Cmds)
-   {
-      if (Cmds->Help == nullptr)
-	 continue;
-      std::cout << "  " << Cmds->Match << " - " << Cmds->Help << std::endl;
-   }
-
+    << std::endl;
+   ShowHelpListCommands(Cmds);
    return true;
 }
 									/*}}}*/

+ 1 - 6
ftparchive/apt-ftparchive.cc

@@ -606,11 +606,7 @@ static void LoadBinDir(vector<PackageMap> &PkgList,Configuration &Setup)
 
 bool ShowHelp(CommandLine &, aptDispatchWithHelp const *)		/*{{{*/
 {
-   ioprintf(cout, "%s %s (%s)\n", PACKAGE, PACKAGE_VERSION, COMMON_ARCH);
-   if (_config->FindB("version") == true)
-      return true;
-
-   cout << 
+   std::cout <<
     _("Usage: apt-ftparchive [options] command\n"
       "Commands: packages binarypath [overridefile [pathprefix]]\n"
       "          sources srcpath [overridefile [pathprefix]]\n"
@@ -649,7 +645,6 @@ bool ShowHelp(CommandLine &, aptDispatchWithHelp const *)		/*{{{*/
       "  --contents  Control contents file generation\n"
       "  -c=?  Read this configuration file\n"
       "  -o=?  Set an arbitrary configuration option") << endl;
-   
    return true;
 }
 									/*}}}*/