Commit 23a5117b authored by aligungr's avatar aligungr

Options parser improvement

parent a3248cc4
...@@ -120,22 +120,22 @@ static std::optional<opt::OptionsResult> ParseCliCommandCommon(OrderedMap<std::s ...@@ -120,22 +120,22 @@ static std::optional<opt::OptionsResult> ParseCliCommandCommon(OrderedMap<std::s
static opt::OptionsDescription DefaultDesc(const std::string &subCommand, const CmdEntry &entry) static opt::OptionsDescription DefaultDesc(const std::string &subCommand, const CmdEntry &entry)
{ {
return {{}, {}, entry.descriptionText, {}, subCommand, {entry.usageText}, entry.helpIfEmpty, true}; return {{}, {}, entry.descriptionText, {}, subCommand, {entry.usageText}, {}, entry.helpIfEmpty, true};
} }
static opt::OptionsDescription DescForPsEstablish(const std::string &subCommand, const CmdEntry &entry) static opt::OptionsDescription DescForPsEstablish(const std::string &subCommand, const CmdEntry &entry)
{ {
std::string usage1 = "<session-type> [options]"; std::string example1 = "IPv4 --sst 1 --sd 1 --dnn internet";
std::string usage2 = "IPv4 --sst 1 --sd 1 --dnn internet"; std::string example2 = "IPv4 --emergency";
std::string usage3 = "IPv4 --emergency";
auto res = opt::OptionsDescription{ auto res = opt::OptionsDescription{
{}, {}, entry.descriptionText, {}, subCommand, {usage1, usage2, usage3}, entry.helpIfEmpty, true}; {}, {}, entry.descriptionText, {}, subCommand, {entry.usageText}, {example1, example2}, entry.helpIfEmpty,
true};
res.items.emplace_back(std::nullopt, "sst", "SST value of the PDU session (Optional)", "value"); res.items.emplace_back(std::nullopt, "sst", "SST value of the PDU session", "value");
res.items.emplace_back(std::nullopt, "sd", "SD value of the PDU session (Optional)", "value"); res.items.emplace_back(std::nullopt, "sd", "SD value of the PDU session", "value");
res.items.emplace_back('n', "dnn", "DNN/APN value of the PDU session (Optional)", "apn"); res.items.emplace_back('n', "dnn", "DNN/APN value of the PDU session", "apn");
res.items.emplace_back('e', "emergency", "Request as an emergency session (Optional)", std::nullopt); res.items.emplace_back('e', "emergency", "Request as an emergency session", std::nullopt);
return res; return res;
} }
...@@ -158,7 +158,8 @@ static OrderedMap<std::string, CmdEntry> g_ueCmdEntries = { ...@@ -158,7 +158,8 @@ static OrderedMap<std::string, CmdEntry> g_ueCmdEntries = {
{"timers", {"Dump current status of the timers in the UE", "", DefaultDesc, false}}, {"timers", {"Dump current status of the timers in the UE", "", DefaultDesc, false}},
{"deregister", {"deregister",
{"Perform a de-registration by the UE", "<normal|disable-5g|switch-off|remove-sim>", DefaultDesc, true}}, {"Perform a de-registration by the UE", "<normal|disable-5g|switch-off|remove-sim>", DefaultDesc, true}},
{"ps-establish", {"Trigger a PDU session establishment procedure", "", DescForPsEstablish, true}}, {"ps-establish",
{"Trigger a PDU session establishment procedure", "<session-type> [options]", DescForPsEstablish, true}},
{"ps-release", {"Trigger a PDU session release procedure", "<pdu-session-id>...", DefaultDesc, true}}, {"ps-release", {"Trigger a PDU session release procedure", "<pdu-session-id>...", DefaultDesc, true}},
{"ps-release-all", {"Trigger PDU session release procedures for all active sessions", "", DefaultDesc, false}}, {"ps-release-all", {"Trigger PDU session release procedures for all active sessions", "", DefaultDesc, false}},
}; };
......
...@@ -134,7 +134,7 @@ static void ReadOptions(int argc, char **argv) ...@@ -134,7 +134,7 @@ static void ReadOptions(int argc, char **argv)
{ {
opt::OptionsDescription desc{"UERANSIM", cons::Tag, "Command Line Interface", opt::OptionsDescription desc{"UERANSIM", cons::Tag, "Command Line Interface",
cons::Owner, "nr-cli", {"<node-name> [option...]", "--dump"}, cons::Owner, "nr-cli", {"<node-name> [option...]", "--dump"},
true, false}; {}, true, false};
opt::OptionItem itemDump = {'d', "dump", "List all UE and gNBs in the environment", std::nullopt}; opt::OptionItem itemDump = {'d', "dump", "List all UE and gNBs in the environment", std::nullopt};
opt::OptionItem itemExec = {'e', "exec", "Execute the given command directly without an interactive shell", opt::OptionItem itemExec = {'e', "exec", "Execute the given command directly without an interactive shell",
......
...@@ -78,9 +78,15 @@ static nr::gnb::GnbConfig *ReadConfigYaml() ...@@ -78,9 +78,15 @@ static nr::gnb::GnbConfig *ReadConfigYaml()
static void ReadOptions(int argc, char **argv) static void ReadOptions(int argc, char **argv)
{ {
opt::OptionsDescription desc{cons::Project, cons::Tag, "5G-SA gNB implementation", opt::OptionsDescription desc{cons::Project,
cons::Owner, "nr-gnb", {"-c <config-file> [option...]"}, cons::Tag,
true, false}; "5G-SA gNB implementation",
cons::Owner,
"nr-gnb",
{"-c <config-file> [option...]"},
{},
true,
false};
opt::OptionItem itemConfigFile = {'c', "config", "Use specified configuration file for gNB", "config-file"}; opt::OptionItem itemConfigFile = {'c', "config", "Use specified configuration file for gNB", "config-file"};
opt::OptionItem itemDisableCmd = {'l', "disable-cmd", "Disable command line functionality for this instance", opt::OptionItem itemDisableCmd = {'l', "disable-cmd", "Disable command line functionality for this instance",
......
...@@ -220,8 +220,8 @@ static nr::ue::UeConfig *ReadConfigYaml() ...@@ -220,8 +220,8 @@ static nr::ue::UeConfig *ReadConfigYaml()
static void ReadOptions(int argc, char **argv) static void ReadOptions(int argc, char **argv)
{ {
opt::OptionsDescription desc{cons::Project, cons::Tag, "5G-SA UE implementation", opt::OptionsDescription desc{
cons::Owner, "nr-ue", {"-c <config-file> [option...]"}, cons::Project, cons::Tag, "5G-SA UE implementation", cons::Owner, "nr-ue", {"-c <config-file> [option...]"}, {},
true, false}; true, false};
opt::OptionItem itemConfigFile = {'c', "config", "Use specified configuration file for UE", "config-file"}; opt::OptionItem itemConfigFile = {'c', "config", "Use specified configuration file for UE", "config-file"};
......
...@@ -264,10 +264,21 @@ void opt::OptionsResult::showHelp() const ...@@ -264,10 +264,21 @@ void opt::OptionsResult::showHelp() const
ostream << std::endl; ostream << std::endl;
if (!m_description.usages.empty())
{
ostream << "Usage:" << std::endl; ostream << "Usage:" << std::endl;
for (auto &usage : m_description.usages) for (auto &usage : m_description.usages)
ostream << " " << m_description.programName << " " << usage << std::endl; ostream << " " << m_description.programName << " " << usage << std::endl;
ostream << std::endl; ostream << std::endl;
}
if (!m_description.examples.empty())
{
ostream << (m_description.examples.size() > 1 ? "Examples:" : "Example:") << std::endl;
for (auto &example : m_description.examples)
ostream << " " << m_description.programName << " " << example << std::endl;
ostream << std::endl;
}
std::vector<OptionItem> items = m_description.items; std::vector<OptionItem> items = m_description.items;
if (!m_description.hideDefaultOptionsInUsage) if (!m_description.hideDefaultOptionsInUsage)
......
...@@ -72,15 +72,16 @@ struct OptionsDescription ...@@ -72,15 +72,16 @@ struct OptionsDescription
std::string programName{}; std::string programName{};
std::vector<OptionItem> items{}; std::vector<OptionItem> items{};
std::vector<std::string> usages{}; std::vector<std::string> usages{};
std::vector<std::string> examples{};
bool helpIfEmpty{}; bool helpIfEmpty{};
bool hideDefaultOptionsInUsage{}; bool hideDefaultOptionsInUsage{};
OptionsDescription(std::string projectName, std::string version, std::string appDescription, std::string copyright, OptionsDescription(std::string projectName, std::string version, std::string appDescription, std::string copyright,
std::string programName, std::vector<std::string> usages, bool helpIfEmpty, std::string programName, std::vector<std::string> usages, std::vector<std::string> examples,
bool hideDefaultOptionsInUsage) bool helpIfEmpty, bool hideDefaultOptionsInUsage)
: projectName(std::move(projectName)), version(std::move(version)), appDescription(std::move(appDescription)), : projectName(std::move(projectName)), version(std::move(version)), appDescription(std::move(appDescription)),
copyright(std::move(copyright)), programName(std::move(programName)), usages(std::move(usages)), copyright(std::move(copyright)), programName(std::move(programName)), usages(std::move(usages)),
helpIfEmpty(helpIfEmpty), hideDefaultOptionsInUsage(hideDefaultOptionsInUsage) examples(std::move(examples)), helpIfEmpty(helpIfEmpty), hideDefaultOptionsInUsage(hideDefaultOptionsInUsage)
{ {
} }
}; };
......
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