From: Gunnar Beutner Date: Thu, 16 Oct 2014 13:24:41 +0000 (+0200) Subject: Improve "object list" output some more X-Git-Tag: v2.2.0~360 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36233cdc774ce6ad4ad5cda2492c1dcb9074dc27;p=icinga2 Improve "object list" output some more refs #7251 --- diff --git a/lib/cli/objectlistcommand.cpp b/lib/cli/objectlistcommand.cpp index 6f6d3666a..08a57e73d 100644 --- a/lib/cli/objectlistcommand.cpp +++ b/lib/cli/objectlistcommand.cpp @@ -99,12 +99,7 @@ int ObjectListCommand::Run(const boost::program_options::variables_map& vm, cons bool first = true; while (NetString::ReadStringFromStream(sfp, &message)) { - if (first) - first = false; - else - std::cout << "\n"; - - PrintObject(std::cout, message, type_count, name_filter, type_filter); + PrintObject(std::cout, first, message, type_count, name_filter, type_filter); objects_count++; } @@ -112,6 +107,9 @@ int ObjectListCommand::Run(const boost::program_options::variables_map& vm, cons fp.close(); if (vm.count("count")) { + if (!first) + std::cout << "\n"; + PrintTypeCounts(std::cout, type_count); std::cout << "\n"; } @@ -121,7 +119,7 @@ int ObjectListCommand::Run(const boost::program_options::variables_map& vm, cons return 0; } -void ObjectListCommand::PrintObject(std::ostream& fp, const String& message, std::map& type_count, const String& name_filter, const String& type_filter) +void ObjectListCommand::PrintObject(std::ostream& fp, bool& first, const String& message, std::map& type_count, const String& name_filter, const String& type_filter) { Dictionary::Ptr object = JsonDeserialize(message); @@ -136,6 +134,11 @@ void ObjectListCommand::PrintObject(std::ostream& fp, const String& message, std if (!type_filter.IsEmpty() && !Utility::Match(type_filter, type)) return; + if (first) + first = false; + else + fp << "\n"; + bool abstract = object->Get("abstract"); Dictionary::Ptr debug_hints = object->Get("debug_hints"); @@ -210,7 +213,12 @@ void ObjectListCommand::PrintTypeCounts(std::ostream& fp, const std::map::value_type TypeCount; BOOST_FOREACH(const TypeCount& kv, type_count) { - fp << "Found " << kv.second << " " << kv.first << " objects.\n"; + fp << "Found " << kv.second << " " << kv.first << " object"; + + if (kv.second != 1) + fp << "s"; + + fp << ".\n"; } } diff --git a/lib/cli/objectlistcommand.hpp b/lib/cli/objectlistcommand.hpp index b56fe1053..fdcca070a 100644 --- a/lib/cli/objectlistcommand.hpp +++ b/lib/cli/objectlistcommand.hpp @@ -47,7 +47,7 @@ public: virtual int Run(const boost::program_options::variables_map& vm, const std::vector& ap) const; private: - static void PrintObject(std::ostream& fp, const String& message, std::map& type_count, const String& name_filter, const String& type_filter); + static void PrintObject(std::ostream& fp, bool& first, const String& message, std::map& type_count, const String& name_filter, const String& type_filter); static void PrintProperties(std::ostream& fp, const Dictionary::Ptr& props, const Dictionary::Ptr& debug_hints, int indent = 0); static void PrintHints(std::ostream& fp, const Dictionary::Ptr& hints, int indent = 0); static void PrintHint(std::ostream& fp, const Array::Ptr& msg, int indent = 0);