Fix 'zypper search' xml output (bnc#687529)
authorMichael Andres <ma@suse.de>
Thu, 21 Jul 2011 09:55:31 +0000 (11:55 +0200)
committerMichael Andres <ma@suse.de>
Thu, 21 Jul 2011 10:03:38 +0000 (12:03 +0200)
src/Table.h
src/output/OutXML.cc
src/search.cc

index 13e5508..22ec8dd 100644 (file)
@@ -105,6 +105,8 @@ public:
   void allowAbbrev(unsigned column);
   void margin(unsigned margin);
 
+  const TableHeader & header() const
+  { return _header; }
   const container & rows() const
   { return _rows; }
 
index 0cc042e..7a7f825 100644 (file)
@@ -197,17 +197,26 @@ void OutXML::searchResult( const Table & table_r )
   if ( ! rows.empty() )
   {
     //
-    // *** CAUTION: It's a mess, but must mtch the header list defined
+    // *** CAUTION: It's a mess, but must match the header list defined
     //              in FillSearchTableSolvable ctor (search.cc)
-    //
-    static const char * header[] = {
-      "status",
-      "name",
-      "kind",
-      "edition",
-      "arch",
-      "repository"
-    };
+    // We derive the XML tag from the header, applying some translation
+    // hence and there.
+    std::vector<std::string> header;
+    {
+      const TableHeader & theader( table_r.header() );
+      for_( it, theader.columns().begin(), theader.columns().end() )
+      {
+       if ( *it == "S" )
+         header.push_back( "status" );
+       else if ( *it == "Type" )
+         header.push_back( "kind" );
+       else if ( *it == "Version" )
+         header.push_back( "edition" );
+       else
+         header.push_back( zypp::str::toLower( *it ) );
+      }
+    }
+
     for_( it, rows.begin(), rows.end() )
     {
       cout << "<solvable";
@@ -215,7 +224,7 @@ void OutXML::searchResult( const Table & table_r )
       unsigned cidx = 0;
       for_( cit, cols.begin(), cols.end() )
       {
-       cout << ' ' << (cidx < 6 ? header[cidx] : "?" ) << "=\"";
+       cout << ' ' << (cidx < header.size() ? header[cidx] : "?" ) << "=\"";
        if ( cidx == 0 )
        {
          if ( *cit == "i" )
index bb9bf63..f97208c 100644 (file)
@@ -251,6 +251,10 @@ FillSearchTableSelectable::FillSearchTableSelectable(
   }
 
   TableHeader header;
+  //
+  // *** CAUTION: It's a mess, but adding/changing colums here requires
+  //              adapting OutXML::searchResult !
+  //
   // translators: S for installed Status
   header << _("S");
   header << _("Name");