Commit c2374dd8 authored by aligungr's avatar aligungr

gNB CLI improvements

parent 6a292462
...@@ -115,11 +115,13 @@ void GnbCmdHandler::HandleCmdImpl(TaskBase &base, NwGnbCliCommand &msg) ...@@ -115,11 +115,13 @@ void GnbCmdHandler::HandleCmdImpl(TaskBase &base, NwGnbCliCommand &msg)
auto amf = base.ngapTask->m_amfCtx[msg.cmd->amfId]; auto amf = base.ngapTask->m_amfCtx[msg.cmd->amfId];
Printer printer{}; Printer printer{};
printer.appendKeyValue("address", amf->address); printer.appendKeyValue({
printer.appendKeyValue("port", amf->port); {"address", amf->address},
printer.appendKeyValue("name", amf->amfName); {"port", std::to_string(amf->port)},
printer.appendKeyValue("relative-capacity", amf->relativeCapacity); {"name", amf->amfName},
printer.appendKeyValue("state", EnumToString(amf->state)); {"capacity", std::to_string(amf->relativeCapacity)},
{"state", EnumToString(amf->state)},
});
printer.trim(); printer.trim();
msg.sendResult(printer.makeString()); msg.sendResult(printer.makeString());
} }
......
...@@ -30,32 +30,18 @@ void Printer::trim() ...@@ -30,32 +30,18 @@ void Printer::trim()
utils::Trim(m_ss); utils::Trim(m_ss);
} }
void Printer::appendKeyValue(const std::string &key, int16_t value) void Printer::appendKeyValue(const std::initializer_list<std::pair<std::string, std::string>> &pairs)
{ {
appendKeyValue(key, std::to_string(value)); size_t maxKey = 0;
} for (auto &pair : pairs)
maxKey = std::max(maxKey, pair.first.size());
void Printer::appendKeyValue(const std::string &key, uint16_t value) for (auto &pair : pairs)
{ {
appendKeyValue(key, std::to_string(value)); appendIndentation();
} m_ss << pair.first;
m_ss << std::string(maxKey - pair.first.size(), ' ');
void Printer::appendKeyValue(const std::string &key, int32_t value) m_ss << " : ";
{ m_ss << pair.second;
appendKeyValue(key, std::to_string(value)); m_ss << "\n";
} }
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));
} }
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <utility>
class Printer class Printer
{ {
...@@ -21,13 +22,7 @@ class Printer ...@@ -21,13 +22,7 @@ class Printer
public: public:
void appendKeyValue(const std::string &key, const std::string &value); void appendKeyValue(const std::string &key, const std::string &value);
void appendKeyValue(const std::initializer_list<std::pair<std::string, std::string>> &pairs);
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);
std::string makeString() const; 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