]> git.saurik.com Git - apt.git/commitdiff
deal with --version more centrally
authorDavid Kalnischkies <david@kalnischkies.de>
Mon, 26 Oct 2015 15:50:21 +0000 (16:50 +0100)
committerDavid Kalnischkies <david@kalnischkies.de>
Wed, 4 Nov 2015 17:04:04 +0000 (18:04 +0100)
Git-Dch: Ignore

13 files changed:
apt-private/private-cmndline.cc
apt-private/private-cmndline.h
cmdline/apt-cache.cc
cmdline/apt-cdrom.cc
cmdline/apt-config.cc
cmdline/apt-extracttemplates.cc
cmdline/apt-get.cc
cmdline/apt-helper.cc
cmdline/apt-internal-solver.cc
cmdline/apt-mark.cc
cmdline/apt-sortpkgs.cc
cmdline/apt.cc
ftparchive/apt-ftparchive.cc

index d80168fda6fe54c7529453dfe7a21382073a17d1..348b698cadf7a4f3deb9479b42b1c31d0ad19480 100644 (file)
@@ -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;
index ac17e2e8a47b15f63317c36f2f0c163d6da2046c..6a6885a330968a0d7908199d24e540f4bb3f57e2 100644 (file)
@@ -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);
index 50af3f3292689a0835dcc97e3cafbc3808dd5aba..4e8a515831efc0e56e46b768ea79f26f634f9f3f 100644 (file)
@@ -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"
index 699cc550cf32aaaeeedb8f645425b43dd2cf3dda..00895863b2e43031e8b64f7338e49c0a570334b7 100644 (file)
@@ -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"
index 47e37c2f72aedd2bc024774c1aa22762f44141ae..eb096440a2fca88448896b7e974979c536c27988 100644 (file)
@@ -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"
index 1b16542fe2762c24da884cfbbb17c10839c17240..b63f2ff1610f092c2dc2ab39a782c4e044a4e49b 100644 (file)
@@ -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"
index 69b12b2c7dedf3883445c72b88f4d10bd93157ea..474ed31593f411bc3c48d079c084d79d74defb64 100644 (file)
@@ -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"
index b0c1ddacf4a53c6ddf7664195ff27958ac87effd..be6c2881a70a45626fdddc3e80c62783f7e4e957 100644 (file)
@@ -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;
index 28989f6cd6805767f16cff6b23229a88740aa393..ae8c08bba99e6394f691109d6e005f4b1efa1ab6 100644 (file)
@@ -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"
index d02e80beb44a4b50f6cdc9bae5fd844c0b761000..b06fcc0ccbeef13b0307ea6b93271120f719fb56 100644 (file)
@@ -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"
index b5a2c12df1155bd00ffe337d8dc9df1d73330e6c..f9aa7d728a7f8b5eeef8157b43dd13f0930a4593 100644 (file)
@@ -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;
 }
                                                                        /*}}}*/
index be2f7663ec8957a4d72b09923ca15efb36852372..3eae221992d1830581a06e1a5ec06b9387f3a3a7 100644 (file)
 
 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;
 }
                                                                        /*}}}*/
index 0abb3e2dd03f81b95640a3b47bb680fa681c576d..99d5627f0d7062e64e4c115d99f469250c58a088 100644 (file)
@@ -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;
 }
                                                                        /*}}}*/