Commit c2374dd8 authored by aligungr's avatar aligungr

gNB CLI improvements

parent 6a292462
......@@ -115,11 +115,13 @@ void GnbCmdHandler::HandleCmdImpl(TaskBase &base, NwGnbCliCommand &msg)
auto amf = base.ngapTask->m_amfCtx[msg.cmd->amfId];
Printer printer{};
printer.appendKeyValue("address", amf->address);
printer.appendKeyValue("port", amf->port);
printer.appendKeyValue("name", amf->amfName);
printer.appendKeyValue("relative-capacity", amf->relativeCapacity);
printer.appendKeyValue("state", EnumToString(amf->state));
printer.appendKeyValue({
{"address", amf->address},
{"port", std::to_string(amf->port)},
{"name", amf->amfName},
{"capacity", std::to_string(amf->relativeCapacity)},
{"state", EnumToString(amf->state)},
});
printer.trim();
msg.sendResult(printer.makeString());
}
......
......@@ -30,32 +30,18 @@ void Printer::trim()
utils::Trim(m_ss);
}
void Printer::appendKeyValue(const std::string &key, int16_t value)
{
appendKeyValue(key, std::to_string(value));
}
void Printer::appendKeyValue(const std::string &key, uint16_t value)
{
appendKeyValue(key, std::to_string(value));
}
void Printer::appendKeyValue(const std::string &key, int32_t value)
{
appendKeyValue(key, std::to_string(value));
}
void Printer::appendKeyValue(const std::string &key, uint32_t value)
{
appendKeyValue(key, std::to_string(value));
}
void Printer::appendKeyValue(const std::string &key, int64_t value)
{
appendKeyValue(key, std::to_string(value));
}
void Printer::appendKeyValue(const std::string &key, uint64_t value)
{
appendKeyValue(key, std::to_string(value));
void Printer::appendKeyValue(const std::initializer_list<std::pair<std::string, std::string>> &pairs)
{
size_t maxKey = 0;
for (auto &pair : pairs)
maxKey = std::max(maxKey, pair.first.size());
for (auto &pair : pairs)
{
appendIndentation();
m_ss << pair.first;
m_ss << std::string(maxKey - pair.first.size(), ' ');
m_ss << " : ";
m_ss << pair.second;
m_ss << "\n";
}
}
......@@ -10,6 +10,7 @@
#include <sstream>
#include <string>
#include <utility>
class Printer
{
......@@ -21,13 +22,7 @@ class Printer
public:
void appendKeyValue(const std::string &key, const std::string &value);
void appendKeyValue(const std::string &key, int16_t value);
void appendKeyValue(const std::string &key, uint16_t value);
void appendKeyValue(const std::string &key, int32_t value);
void appendKeyValue(const std::string &key, uint32_t value);
void appendKeyValue(const std::string &key, int64_t value);
void appendKeyValue(const std::string &key, uint64_t value);
void appendKeyValue(const std::initializer_list<std::pair<std::string, std::string>> &pairs);
std::string makeString() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment