Commit 6bc71edd authored by aligungr's avatar aligungr

CLI command dump order change

parent bed51374
......@@ -13,6 +13,7 @@
#include <utils/common.hpp>
#include <utils/constants.hpp>
#include <utils/options.hpp>
#include <utils/ordered_map.hpp>
#define CMD_ERR(x) \
{ \
......@@ -44,16 +45,17 @@ class OptionsHandler : public opt::IOptionsHandler
}
};
static std::string DumpCommands(const std::map<std::string, std::string> &descTable)
static std::string DumpCommands(const OrderedMap<std::string, std::string> &descTable)
{
size_t maxLength = 0;
for (auto &item : descTable)
maxLength = std::max(maxLength, item.first.size());
maxLength = std::max(maxLength, item.size());
std::stringstream ss{};
for (auto &item : descTable)
ss << item.first << std::string(maxLength - item.first.size(), ' ') << " | " << item.second << "\n";
ss << item << std::string(maxLength - item.size(), ' ') << " | " << descTable[item] << "\n";
std::string output = ss.str();
utils::Trim(output);
return output;
}
......@@ -61,7 +63,7 @@ static std::string DumpCommands(const std::map<std::string, std::string> &descTa
namespace app
{
static std::map<std::string, std::string> g_gnbCmdToDescription = {
static OrderedMap<std::string, std::string> g_gnbCmdToDescription = {
{"status", "Show some status information about the gNB"},
{"info", "Show some information about the gNB"},
{"amf-list", "List all AMFs associated with the gNB"},
......@@ -70,15 +72,15 @@ static std::map<std::string, std::string> g_gnbCmdToDescription = {
{"ue-count", "Print the total number of UEs connected the this gNB"},
};
static std::map<std::string, std::string> g_gnbCmdToUsage = {
static OrderedMap<std::string, std::string> g_gnbCmdToUsage = {
{"status", ""}, {"info", ""}, {"amf-list", ""}, {"amf-info", "<amf-id>"}, {"ue-list", ""}, {"ue-count", ""},
};
static std::map<std::string, bool> g_gnbCmdToHelpIfEmpty = {{"status", false}, {"info", false},
static OrderedMap<std::string, bool> g_gnbCmdToHelpIfEmpty = {{"status", false}, {"info", false},
{"amf-list", false}, {"amf-info", true},
{"ue-list", false}, {"ue-count", false}};
static std::map<std::string, std::string> g_ueCmdToDescription = {
static OrderedMap<std::string, std::string> g_ueCmdToDescription = {
{"info", "Show some information about the UE"},
{"status", "Show some status information about the UE"},
{"timers", "Dump current status of the timers in the UE"},
......
......@@ -306,6 +306,8 @@ bool utils::IsNumeric(const std::string &str)
void utils::Trim(std::string &s)
{
if (s.length() == 0)
return;
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); }));
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end());
}
......
//
// This file is a part of UERANSIM open source project.
// Copyright (c) 2021 ALİ GÜNGÖR.
//
// The software and all associated files are licensed under GPL-3.0
// and subject to the terms and conditions defined in LICENSE file.
//
#include "ordered_map.hpp"
//
// This file is a part of UERANSIM open source project.
// Copyright (c) 2021 ALİ GÜNGÖR.
//
// The software and all associated files are licensed under GPL-3.0
// and subject to the terms and conditions defined in LICENSE file.
//
#include <initializer_list>
#include <unordered_map>
#include <utility>
#include <vector>
template <typename TKey, typename TValue>
class OrderedMap
{
private:
std::unordered_map<TKey, TValue> m_map{};
std::vector<TKey> m_keyOrder{};
public:
OrderedMap() = default;
OrderedMap(std::initializer_list<std::pair<TKey, TValue>> initList)
{
for (auto &pair : initList)
{
if (!m_map.count(pair.first))
m_keyOrder.push_back(pair.first);
m_map[pair.first] = pair.second;
}
}
inline auto count(const TKey &key)
{
return m_map.count(key);
}
inline TValue &operator[](const TKey &key)
{
return m_map.at(key);
}
inline const TValue &operator[](const TKey &key) const
{
return m_map.at(key);
}
inline typename std::vector<TKey>::iterator begin()
{
return m_keyOrder.begin();
}
inline typename std::vector<TKey>::const_iterator begin() const
{
return m_keyOrder.begin();
}
inline typename std::vector<TKey>::iterator end()
{
return m_keyOrder.end();
}
inline typename std::vector<TKey>::const_iterator end() const
{
return m_keyOrder.end();
}
};
\ No newline at end of file
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