|
|
@@ -16,6 +16,7 @@
|
|
|
#include <vector>
|
|
|
|
|
|
#include "lambda_cast.h"
|
|
|
+#include "types.h"
|
|
|
|
|
|
namespace cli {
|
|
|
|
|
|
@@ -41,6 +42,12 @@ public:
|
|
|
cli & register_callback(std::string const & handle, F && cb) {
|
|
|
return register_callback(handle, lambdas::FFL(cb));
|
|
|
}
|
|
|
+ template <typename T>
|
|
|
+ cli & register_query(std::string const & handle, std::function<T()> cb);
|
|
|
+ template <typename F>
|
|
|
+ cli & register_query(std::string const & handle, F && cb) {
|
|
|
+ return register_query(handle, lambdas::FFL(cb));
|
|
|
+ }
|
|
|
|
|
|
void run() const;
|
|
|
template <typename T, size_t I>
|
|
|
@@ -77,4 +84,25 @@ cli & cli::register_callback(std::string const & handle,
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
|
+template <typename T> void cli_print(T const & value) {
|
|
|
+ if constexpr (detail::is_container_v<T> && !detail::is_string_v<T>) {
|
|
|
+ using ::cli::cli_print;
|
|
|
+ for (auto & elem : value) {
|
|
|
+ cli_print(elem);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ std::cout << " " << value << "\n";
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+cli & cli::register_query(std::string const & handle, std::function<T()> cb) {
|
|
|
+ arguments_.emplace(handle, 0);
|
|
|
+ callbacks_.emplace(handle, [=](args_t const & args) {
|
|
|
+ using ::cli::cli_print;
|
|
|
+ cli_print(cb());
|
|
|
+ });
|
|
|
+ return *this;
|
|
|
+}
|
|
|
+
|
|
|
}
|