Add info command options to print dependencies.
authorMichael Andres <ma@suse.de>
Fri, 31 Jan 2014 16:49:58 +0000 (17:49 +0100)
committerMichael Andres <ma@suse.de>
Fri, 31 Jan 2014 16:49:58 +0000 (17:49 +0100)
(fixes #43)

doc/zypper.8
src/Zypper.cc
src/info.cc

index ce0f3b3..d5eb251 100644 (file)
@@ -192,13 +192,23 @@ option can be used multiple times.
 Type of package (default: package). See section \fBPackage Types\fR for list
 of available package types.
 .TP
+.I \ \ \ \ \-\-provides
+Show symbols the package provides.
+.TP
 .I \ \ \ \ \-\-requires
-Show also symbols required and pre-required by the package. Available for package and patch type
-only.
+Show symbols the package requires.
+.TP
+.I \ \ \ \ \-\-conflicts
+Show symbols the package conflits with.
+.TP
+.I \ \ \ \ \-\-obsoletes
+Show symbols the package obsoletes.
 .TP
 .I \ \ \ \ \-\-recommends
-Show also symbols recommended by the package. Available for package and patch
-type only.
+Show symbols the package recommends.
+.TP
+.I \ \ \ \ \-\-suggests
+Show symbols the package suggests.
 .TP
 Examples:
 
index 2cf8e65..98801b6 100644 (file)
@@ -2133,8 +2133,12 @@ void Zypper::processCommandOptions()
       {"repo", required_argument, 0, 'r'},
       // rug compatibility option, we have --repo
       {"catalog", required_argument, 0, 'c'},
+      {"provides", no_argument, 0, 0},
       {"requires", no_argument, 0, 0},
+      {"conflicts", no_argument, 0, 0},
+      {"obsoletes", no_argument, 0, 0},
       {"recommends", no_argument, 0, 0},
+      {"suggests", no_argument, 0, 0},
       {"help", no_argument, 0, 'h'},
       {0, 0, 0, 0}
     };
@@ -2152,8 +2156,12 @@ void Zypper::processCommandOptions()
         "-r, --repo <alias|#|URI>  Work only with the specified repository.\n"
         "-t, --type <type>         Type of package (%s).\n"
         "                          Default: %s.\n"
-        "    --requires            Show also requires and prerequires.\n"
-        "    --recommends          Show also recommends."
+        "    --provides            Show provides.\n"
+        "    --requires            Show requires and prerequires.\n"
+        "    --conflicts           Show conflicts.\n"
+        "    --obsoletes           Show obsoletes.\n"
+        "    --recommends          Show recommends."
+        "    --suggests            Show suggests.\n"
       ), "package, patch, pattern, product", "package");
 
     break;
@@ -4585,18 +4593,6 @@ void Zypper::doCommand()
       }
     }
 
-    // XXX: would requires/recommends make sense for pattern etc.?
-    if (copts.count("requires") || copts.count("recommends"))
-    {
-      if (kind != ResKind::package && kind != ResKind::patch)
-      {
-        out().error(boost::str(format(
-          _("Type '%s' does not support %s.")) % kind % "--requires/--recommends"));
-        setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
-        return;
-      }
-    }
-
     initRepoManager();
     init_target(*this);
     init_repos(*this);
index 7a6d854..8e1cde5 100644 (file)
@@ -36,6 +36,36 @@ using boost::format;
 
 extern ZYpp::Ptr God;
 
+///////////////////////////////////////////////////////////////////
+namespace
+{
+  inline std::string asCliOption( Dep dep_r )
+  { return dep_r.asString(); }
+
+  inline std::string asInfoTag( Dep dep_r )
+  { return dep_r.asUserString(); }
+
+  inline const std::vector<Dep> & cliSupportedDepTypes()
+  {
+    static const std::vector<Dep> _deps = {
+      Dep::PROVIDES,
+      Dep::REQUIRES,
+      Dep::CONFLICTS,
+      Dep::OBSOLETES,
+      Dep::RECOMMENDS,
+      Dep::SUGGESTS
+    };
+    return _deps;
+  }
+
+  inline void printDepList( const PoolItem & pi_r, Dep dep_r )
+  {
+    cout << asInfoTag( dep_r ) << ':' << endl;
+    for ( auto && cap : pi_r->dep( dep_r ) )
+    { cout << "  " << cap << endl; }
+  }
+} // namespace out
+///////////////////////////////////////////////////////////////////
 
 void printNVA(const ResObject::constPtr & res)
 {
@@ -119,43 +149,8 @@ void printInfo(Zypper & zypper, const ResKind & kind)
       }
     }
   }
-
-  if (false)
-  {
-    string s00 = _("None");
-    string s0 = _("Requires");
-    string s1 = _("Provides");
-    string s2 = _("Conflicts");
-    string s3 = _("Obsoletes");
-    // translators: package requirements table header
-    string s4 = _("Requirement");
-    // translators: package requirements table header
-    string s5 = _("Provided By");
-    // translators: package conflicts table header
-    string s6 = _("Conflict");
-  }
-}
-
-static void printRequires(const PoolItem & pi)
-{
-  cout << _("Requires:") << endl;
-  std::list<Capability> capList = std::list<Capability>(pi->prerequires().begin(), pi->prerequires().end());
-  capList.assign(pi->requires().begin(), pi->requires().end());
-  for (std::list<Capability>::const_iterator it = capList.begin(); it != capList.end(); ++it)
-  {
-    cout << *it << endl;
-  }
 }
 
-static void printRecommends(const PoolItem & pi)
-{
-  cout << _("Recommends:") << endl;
-  Capabilities capSet = pi->recommends();
-  for (Capabilities::const_iterator it = capSet.begin(); it != capSet.end(); ++it)
-  {
-    cout << *it << endl;
-  }
-}
 
 /**
  * Print package information.
@@ -229,19 +224,9 @@ void printPkgInfo(Zypper & zypper, const ui::Selectable & s)
 
   printSummaryDesc(theone.resolvable());
 
-  bool requires = zypper.cOpts().count("requires");
-  bool recommends = zypper.cOpts().count("recommends");
-
-  if (requires)
-    printRequires(theone);
-
-  if (recommends)
-  {
-    if (requires)
-      cout << endl; // visual separator
-
-    printRecommends(theone);
-  }
+  // Print dependency lists if CLI requests it
+  for ( auto && dep : cliSupportedDepTypes() )
+  { if ( zypper.cOpts().count( asCliOption( dep ) ) ) printDepList( theone, dep ); }
 }
 
 /**
@@ -296,28 +281,19 @@ void printPatchInfo(Zypper & zypper, const ui::Selectable & s )
 
   printSummaryDesc(pool_item.resolvable());
 
-  cout << _("Provides:") << endl;
-  Capabilities capSet = pool_item.resolvable()->dep(zypp::Dep::PROVIDES);
-  // WhatProvides can be used here. The result can be represented as a table of
-  // a "Capability" (it->asString()) | "Provided By" (WhatProvides(c))
-  for (Capabilities::const_iterator it = capSet.begin(); it != capSet.end(); ++it)
-    cout << *it << endl;
-
-  cout << endl << _("Conflicts:") << endl;
-  capSet = pool_item.resolvable()->dep(zypp::Dep::CONFLICTS);
-  for (Capabilities::const_iterator it = capSet.begin(); it != capSet.end(); ++it)
-    cout << *it << endl;
-
-  if (zypper.cOpts().count("requires"))
-  {
-    cout << endl; // visual separator
-    printRequires(pool_item);
-  }
-
-  if (zypper.cOpts().count("recommends"))
+  // Print dependency lists if CLI requests it
+  for ( auto && dep : cliSupportedDepTypes() )
   {
-    cout << endl; // visual separator
-    printRecommends(pool_item);
+    switch ( dep.inSwitch() )
+    {
+      case Dep::PROVIDES_e:
+      case Dep::CONFLICTS_e:
+       printDepList( pool_item, dep ); // These dependency lists are always printed
+       break;
+      default:
+       if ( zypper.cOpts().count( asCliOption( dep ) ) ) printDepList( pool_item, dep );
+       break;
+    }
   }
 }
 
@@ -370,6 +346,10 @@ void printPatternInfo(Zypper & zypper, const ui::Selectable & s)
   if (zypper.globalOpts().is_rug_compatible)
     return;
 
+  // Print dependency lists if CLI requests it
+  for ( auto && dep : cliSupportedDepTypes() )
+  { if ( zypper.cOpts().count( asCliOption( dep ) ) ) printDepList( pool_item, dep ); }
+
   // show contents
   Table t;
   TableHeader th;
@@ -459,6 +439,10 @@ void printProductInfo(Zypper & zypper, const ui::Selectable & s)
     cout << _("Short Name") << ": " << product->shortName() << endl;
 
     printSummaryDesc(pool_item.resolvable());
+
+    // Print dependency lists if CLI requests it
+    for ( auto && dep : cliSupportedDepTypes() )
+    { if ( zypper.cOpts().count( asCliOption( dep ) ) ) printDepList( pool_item, dep ); }
   }
 }