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++;
}
fp.close();
if (vm.count("count")) {
+ if (!first)
+ std::cout << "\n";
+
PrintTypeCounts(std::cout, type_count);
std::cout << "\n";
}
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);
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");
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";
}
}
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);