]> granicus.if.org Git - icinga2/commitdiff
Improve "object list" output some more
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 16 Oct 2014 13:24:41 +0000 (15:24 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 16 Oct 2014 13:24:41 +0000 (15:24 +0200)
refs #7251

lib/cli/objectlistcommand.cpp
lib/cli/objectlistcommand.hpp

index 6f6d3666a3ee8a829a098e2412f32b1681c4242c..08a57e73d6f1c4daf8a817ffbbe4a96eade0b8a4 100644 (file)
@@ -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<String, int>& type_count, const String& name_filter, const String& type_filter)
+void ObjectListCommand::PrintObject(std::ostream& fp, bool& first, const String& message, std::map<String, int>& 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<String,
        typedef std::map<String, int>::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";
        }
 }
 
index b56fe1053edb27e8a7cd90309cfff0679fa0bcec..fdcca070a7aaa56414f863ab511c70a163c6ec3d 100644 (file)
@@ -47,7 +47,7 @@ public:
         virtual int Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const;
 
 private:
-        static void PrintObject(std::ostream& fp, const String& message, std::map<String, int>& type_count, const String& name_filter, const String& type_filter);
+        static void PrintObject(std::ostream& fp, bool& first, const String& message, std::map<String, int>& 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);