Skip to content

Commit

Permalink
tools/rbd: adding newline operation when only '--format' used
Browse files Browse the repository at this point in the history
Signed-off-by: songweibin <song.weibin@zte.com.cn>
  • Loading branch information
Songweibin committed Aug 1, 2017
1 parent a8c2b10 commit cda83be
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/common/Formatter.cc
Expand Up @@ -322,6 +322,8 @@ void XMLFormatter::flush(std::ostream& os)
finish_pending_string();
std::string m_ss_str = m_ss.str();
os << m_ss_str;
if (!m_pretty)
os << "\n";
/* There is a small catch here. If the rest of the formatter had NO output,
* we should NOT output a newline. This primarily triggers on HTTP redirects */
if (m_pretty && !m_ss_str.empty())
Expand Down
3 changes: 3 additions & 0 deletions src/tools/rbd/action/Children.cc
Expand Up @@ -86,6 +86,9 @@ int execute(const po::variables_map &vm) {
<< std::endl;
return r;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions src/tools/rbd/action/Diff.cc
Expand Up @@ -127,6 +127,9 @@ int execute(const po::variables_map &vm) {
std::cerr << "rbd: diff error: " << cpp_strerror(r) << std::endl;
return -r;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;
}

Expand Down
5 changes: 4 additions & 1 deletion src/tools/rbd/action/DiskUsage.cc
Expand Up @@ -283,9 +283,12 @@ 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;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;
}

Expand Down
4 changes: 4 additions & 0 deletions src/tools/rbd/action/Group.cc
Expand Up @@ -83,6 +83,8 @@ int execute_list(const po::variables_map &vm) {
if (f) {
f->close_section();
f->flush(std::cout);
if (!vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
}

return 0;
Expand Down Expand Up @@ -306,6 +308,8 @@ int execute_list_images(const po::variables_map &vm) {
if (f) {
f->close_section();
f->flush(std::cout);
if (!vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
}

return 0;
Expand Down
3 changes: 3 additions & 0 deletions src/tools/rbd/action/ImageMeta.cc
Expand Up @@ -156,6 +156,9 @@ int execute_list(const po::variables_map &vm) {
<< std::endl;
return r;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions src/tools/rbd/action/Info.cc
Expand Up @@ -373,6 +373,9 @@ int execute(const po::variables_map &vm) {
std::cerr << "rbd: info: " << cpp_strerror(r) << std::endl;
return r;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions src/tools/rbd/action/Journal.cc
Expand Up @@ -838,6 +838,9 @@ int execute_info(const po::variables_map &vm) {
std::cerr << "rbd: journal info: " << cpp_strerror(r) << std::endl;
return r;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;

}
Expand Down Expand Up @@ -876,6 +879,9 @@ int execute_status(const po::variables_map &vm) {
std::cerr << "rbd: journal status: " << cpp_strerror(r) << std::endl;
return r;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions src/tools/rbd/action/Kernel.cc
Expand Up @@ -380,6 +380,9 @@ int execute_show(const po::variables_map &vm) {
std::cerr << "rbd: showmapped failed: " << cpp_strerror(r) << std::endl;
return r;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions src/tools/rbd/action/List.cc
Expand Up @@ -217,6 +217,8 @@ int execute(const po::variables_map &vm) {
return r;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions src/tools/rbd/action/Lock.cc
Expand Up @@ -141,6 +141,9 @@ int execute_list(const po::variables_map &vm) {
std::cerr << "rbd: listing locks failed: " << cpp_strerror(r) << std::endl;
return r;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions src/tools/rbd/action/MirrorImage.cc
Expand Up @@ -241,6 +241,8 @@ int execute_status(const po::variables_map &vm) {
formatter->dump_string("last_update", last_update);
formatter->close_section(); // image
formatter->flush(std::cout);
if (!vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
} else {
std::cout << image_name << ":\n"
<< " global_id: " << status.info.global_id << "\n"
Expand Down
4 changes: 4 additions & 0 deletions src/tools/rbd/action/MirrorPool.cc
Expand Up @@ -803,6 +803,8 @@ int execute_info(const po::variables_map &vm) {
if (formatter != nullptr) {
formatter->close_section();
formatter->flush(std::cout);
if (!vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
}
return 0;
}
Expand Down Expand Up @@ -907,6 +909,8 @@ int execute_status(const po::variables_map &vm) {
if (formatter != nullptr) {
formatter->close_section(); // status
formatter->flush(std::cout);
if (!vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
}

return ret;
Expand Down
3 changes: 3 additions & 0 deletions src/tools/rbd/action/Snap.cc
Expand Up @@ -242,6 +242,9 @@ int execute_list(const po::variables_map &vm) {
<< std::endl;
return r;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;
}

Expand Down
3 changes: 3 additions & 0 deletions src/tools/rbd/action/Status.cc
Expand Up @@ -117,6 +117,9 @@ int execute(const po::variables_map &vm) {
std::cerr << "rbd: show status failed: " << cpp_strerror(r) << std::endl;
return r;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions src/tools/rbd/action/Trash.cc
Expand Up @@ -297,6 +297,8 @@ int execute_list(const po::variables_map &vm) {
return r;
}

if (formatter.get() && !vm[at::PRETTY_FORMAT].as<bool>())
std::cout << std::endl;
return 0;
}

Expand Down

0 comments on commit cda83be

Please sign in to comment.