]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: adding newline operation when only '--format' used
authorsongweibin <song.weibin@zte.com.cn>
Wed, 9 Aug 2017 06:26:32 +0000 (14:26 +0800)
committersongweibin <song.weibin@zte.com.cn>
Fri, 18 Aug 2017 00:54:07 +0000 (08:54 +0800)
Signed-off-by: songweibin <song.weibin@zte.com.cn>
src/common/Formatter.cc
src/common/Formatter.h
src/mgr/PyFormatter.h
src/rgw/rgw_formats.h
src/test/cli-integration/rbd/formatted-output.t
src/tools/rbd/Utils.cc
src/tools/rbd/action/DiskUsage.cc

index 1a400aaa159bc27b7917cdeddba98d11a04b0b74..3b3589db805ca18ce52458ecb1de89f98ba8ead2 100644 (file)
@@ -127,6 +127,8 @@ void JSONFormatter::flush(std::ostream& os)
 {
   finish_pending_string();
   os << m_ss.str();
+  if (m_line_break_enabled)
+    os << "\n";
   m_ss.clear();
   m_ss.str("");
 }
@@ -326,6 +328,8 @@ void XMLFormatter::flush(std::ostream& os)
    * we should NOT output a newline. This primarily triggers on HTTP redirects */
   if (m_pretty && !m_ss_str.empty())
     os << "\n";
+  else if (m_line_break_enabled)
+    os << "\n";
   m_ss.clear();
   m_ss.str("");
 }
index aa695ba30f546e5ac54638de650e37a359f0a0e2..df6c0a99a5ebaf4743d850dc84369990cff3f9c9 100644 (file)
@@ -37,6 +37,7 @@ namespace ceph {
     Formatter();
     virtual ~Formatter();
 
+    virtual void enable_line_break() = 0;
     virtual void flush(std::ostream& os) = 0;
     void flush(bufferlist &bl);
     virtual void reset() = 0;
@@ -93,6 +94,7 @@ namespace ceph {
     void set_status(int status, const char* status_name) override {};
     void output_header() override {};
     void output_footer() override {};
+    void enable_line_break() override { m_line_break_enabled = true; }
     void flush(std::ostream& os) override;
     using Formatter::flush; // don't hide Formatter::flush(bufferlist &bl)
     void reset() override;
@@ -128,6 +130,7 @@ namespace ceph {
     std::stringstream m_ss, m_pending_string;
     std::list<json_formatter_stack_entry_d> m_stack;
     bool m_is_pending_string;
+    bool m_line_break_enabled = false;
   };
 
   class XMLFormatter : public Formatter {
@@ -139,6 +142,7 @@ namespace ceph {
     void output_header() override;
     void output_footer() override;
 
+    void enable_line_break() override { m_line_break_enabled = true; }
     void flush(std::ostream& os) override;
     using Formatter::flush; // don't hide Formatter::flush(bufferlist &bl)
     void reset() override;
@@ -176,6 +180,7 @@ namespace ceph {
     const bool m_underscored;
     std::string m_pending_string_name;
     bool m_header_done;
+    bool m_line_break_enabled = false;
   };
 
   class TableFormatter : public Formatter {
@@ -185,6 +190,7 @@ namespace ceph {
     void set_status(int status, const char* status_name) override {};
     void output_header() override {};
     void output_footer() override {};
+    void enable_line_break() override {};
     void flush(std::ostream& os) override;
     using Formatter::flush; // don't hide Formatter::flush(bufferlist &bl)
     void reset() override;
index 924f5822abe807b4a4594483e72bfb0d833e8954..ec4dad81c2901985a59070ae6916704591164b7d 100644 (file)
@@ -76,7 +76,7 @@ public:
   void set_status(int status, const char* status_name) override {}
   void output_header() override {};
   void output_footer() override {};
-
+  void enable_line_break() override {};
 
   void open_array_section(const char *name) override;
   void open_object_section(const char *name) override;
index 6c7d006282baf2d335d6538239ea542d86319661..a50965873836fe07a255a7d1a4d888f3159758ac 100644 (file)
@@ -29,6 +29,7 @@ public:
   void set_status(int status, const char* status_name) override {};
   void output_header() override {};
   void output_footer() override {};
+  void enable_line_break() override {};
   void flush(ostream& os) override;
   void reset() override;
 
index aefdbf91e344a7016c8c03d1df4a00fc39fa1051..b51326ac76d90e69ff337dda9cf1042c7bdfd935 100644 (file)
@@ -5,9 +5,9 @@ ls on empty pool never containing images
   $ rados -p rbd rm rbd_directory >/dev/null 2>&1 || true
   $ rbd ls
   $ rbd ls --format json
-  [] (no-eol)
+  []
   $ rbd ls --format xml
-  <images></images> (no-eol)
+  <images></images>
 
 create
 =======
index ccb850e876aba3ecc7b1ded434274f9036aac043..937dddb2126eaf48bee151f0603af75225cefcda 100644 (file)
@@ -831,6 +831,8 @@ int get_formatter(const po::variables_map &vm,
       std::cerr << "rbd: --pretty-format only works when --format "
                 << "is json or xml" << std::endl;
       return -EINVAL;
+    } else if (*formatter != nullptr && !pretty) {
+      formatter->get()->enable_line_break();
     }
   } else if (vm[at::PRETTY_FORMAT].as<bool>()) {
     std::cerr << "rbd: --pretty-format only works when --format "
index 3a38a052fb3d2eac107f8a6ddd5db9b639116c22..9934e81dd21fe43e4ab053ab0d0c580814b53bde 100644 (file)
@@ -283,7 +283,7 @@ int execute(const po::variables_map &vm) {
                     from_snap_name.empty() ? nullptr : from_snap_name.c_str(),
                     formatter.get());
   if (r < 0) {
-    std::cerr << "du failed: " << cpp_strerror(r) << std::endl;
+    std::cerr << "rbd: du failed: " << cpp_strerror(r) << std::endl;
     return r;
   }
   return 0;