Improve "object list" output some more

refs #7251
This commit is contained in:
Gunnar Beutner 2014-10-16 15:24:41 +02:00
parent ea685b5e55
commit 36233cdc77
2 changed files with 17 additions and 9 deletions

View 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";
}
}

View 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);