Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

fix: modify the ouput format for configs http api #800

Merged
merged 1 commit into from
Mar 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/utils/flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,13 @@ class flag_data
void add_tag(const flag_tag &tag) { _tags.insert(tag); }
bool has_tag(const flag_tag &tag) const { return _tags.find(tag) != _tags.end(); }

std::string to_json() const
void to_table_printer(utils::table_printer &tp) const
{
#define TABLE_PRINTER_ADD_VALUE(type, type_enum) \
case type_enum: \
tp.add_row_name_and_data("value", value<type>()); \
break;

utils::table_printer tp;
tp.add_row_name_and_data("name", _name);
tp.add_row_name_and_data("section", _section);
tp.add_row_name_and_data("type", enum_to_string(_type));
Expand All @@ -130,7 +129,12 @@ class flag_data
TABLE_PRINTER_ADD_VALUE(double, FV_DOUBLE);
TABLE_PRINTER_ADD_VALUE(const char *, FV_STRING);
}
}

std::string to_json() const
{
utils::table_printer tp;
to_table_printer(tp);
std::ostringstream out;
tp.output(out, utils::table_printer::output_format::kJsonCompact);
return out.str();
Expand Down Expand Up @@ -227,13 +231,15 @@ class flag_registry : public utils::singleton<flag_registry>

std::string list_all_flags() const
{
utils::table_printer tp;
utils::multi_table_printer mtp;
for (const auto &flag : _flags) {
tp.add_row_name_and_data(flag.first, flag.second.to_json());
utils::table_printer tp(flag.first);
flag.second.to_table_printer(tp);
mtp.add(std::move(tp));
}

std::ostringstream out;
tp.output(out, utils::table_printer::output_format::kJsonCompact);
mtp.output(out, utils::table_printer::output_format::kJsonCompact);
return out.str();
}

Expand Down