+ struct Select
{
- template
+ template
static void Exec(const F& f, InputIt first, InputIt last)
{
assert( first != last );
assert( std::distance(first, last) == 1+sizeof...(Args) );
const P p = detail::from_string::type>(*first);
auto g = [&](auto ... pars){ f(p, pars...); };
- Select::Exec(g, std::next(first), last);
+ Select::Exec(g, std::next(first), last);
}
};
- template
- struct Select
+ template <>
+ struct Select<>
{
- template
+ template
static void Exec(const F& f, InputIt first, InputIt last)
{
// silence the unused warning in release mode when assert is disabled
@@ -646,7 +649,7 @@ namespace cli
try
{
auto g = [&](auto ... pars){ func( session.OutStream(), pars... ); };
- Select::Exec(g, std::next(cmdLine.begin()), cmdLine.end());
+ Select::Exec(g, std::next(cmdLine.begin()), cmdLine.end());
}
catch (std::bad_cast&)
{
@@ -823,6 +826,13 @@ namespace cli
// Menu implementation
+ template
+ CmdHandler Menu::Insert(const std::string& cmdName, R (*f)(std::ostream&, Args...), const std::string& help, const std::vector& parDesc)
+ {
+ using F = R (*)(std::ostream&, Args...);
+ return Insert(std::make_unique>(cmdName, f, help, parDesc));
+ }
+
template
CmdHandler Menu::Insert(const std::string& cmdName, const std::string& help, const std::vector& parDesc, F& f, R (F::*)(std::ostream& out, Args...) const )
{
diff --git a/include/cli/detail/genericasioremotecli.h b/include/cli/detail/genericasioremotecli.h
index 5d6488c..a006a1d 100644
--- a/include/cli/detail/genericasioremotecli.h
+++ b/include/cli/detail/genericasioremotecli.h
@@ -77,13 +77,13 @@ class TelnetSession : public Session
// https://www.ibm.com/support/knowledgecenter/SSLTBW_1.13.0/com.ibm.zos.r13.hald001/telcmds.htm
- std::string iacDoLineMode{ "\x0FF\x0FD\x022", 3 };
+ static const std::string iacDoLineMode{ "\x0FF\x0FD\x022", 3 };
this -> OutStream() << iacDoLineMode << std::flush;
- std::string iacSbLineMode0IacSe{ "\x0FF\x0FA\x022\x001\x000\x0FF\x0F0", 7 };
+ static const std::string iacSbLineMode0IacSe{ "\x0FF\x0FA\x022\x001\x000\x0FF\x0F0", 7 };
this -> OutStream() << iacSbLineMode0IacSe << std::flush;
- std::string iacWillEcho{ "\x0FF\x0FB\x001", 3 };
+ static const std::string iacWillEcho{ "\x0FF\x0FB\x001", 3 };
this -> OutStream() << iacWillEcho << std::flush;
/*
constexpr char IAC = '\x0FF'; // 255
From bb916eb4b206f5e1af9f2105bc1e749454020f51 Mon Sep 17 00:00:00 2001
From: Daniele Pallastrelli <5451767+daniele77@users.noreply.github.com>
Date: Wed, 30 Mar 2022 19:55:37 +0200
Subject: [PATCH 002/223] Remove nocolor command at start in example
---
examples/complete.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/examples/complete.cpp b/examples/complete.cpp
index 8aa4657..9d1c3d4 100644
--- a/examples/complete.cpp
+++ b/examples/complete.cpp
@@ -171,6 +171,7 @@ int main()
nocolorCmd.Disable();
},
"Disable colors in the cli" );
+ nocolorCmd.Disable(); // start w/o colors, so we disable this command
rootMenu->Insert(
"removecmds",
[&](std::ostream&)
From 9d398548f60a1b1e77c8211f3bd5856d8843fbd1 Mon Sep 17 00:00:00 2001
From: Daniele Pallastrelli <5451767+daniele77@users.noreply.github.com>
Date: Wed, 30 Mar 2022 19:57:30 +0200
Subject: [PATCH 003/223] Add section "Menus and commands" in readme file
---
README.md | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)
diff --git a/README.md b/README.md
index 2018aa2..53894da 100644
--- a/README.md
+++ b/README.md
@@ -253,6 +253,97 @@ ioc.run();
...
```
+## Adding menus and commands
+
+You must provide at least a root menu for your cli:
+
+```
+// create a menu (this is the root menu of our cli)
+auto rootMenu = make_unique