Skip to content

Commit

Permalink
Improve "object list" output some more
Browse files Browse the repository at this point in the history
refs #7251
  • Loading branch information
gunnarbeutner committed Oct 16, 2014
1 parent ea685b5 commit 36233cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 16 additions & 8 deletions lib/cli/objectlistcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,17 @@ 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++;
}

sfp->Close();
fp.close();

if (vm.count("count")) {
if (!first)
std::cout << "\n";

PrintTypeCounts(std::cout, type_count);
std::cout << "\n";
}
Expand All @@ -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);

Expand All @@ -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");

Expand Down Expand Up @@ -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";
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/cli/objectlistcommand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ObjectListCommand : public CLICommand
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);
Expand Down

0 comments on commit 36233cd

Please sign in to comment.