|
|
@@ -19,6 +19,23 @@
|
|
|
|
|
|
namespace cli {
|
|
|
|
|
|
+template <typename T> struct is_string : std::false_type {};
|
|
|
+template <typename T>
|
|
|
+struct is_string<T*> : std::is_same<std::remove_cv_t<T>, char> {};
|
|
|
+template <typename T>
|
|
|
+struct is_string<T[]> : std::is_same<std::remove_cv_t<T>, char> {};
|
|
|
+template <typename...Ts>
|
|
|
+struct is_string<std::basic_string<Ts...>> : std::true_type {};
|
|
|
+
|
|
|
+template <typename T, typename = void> struct is_container : std::false_type {};
|
|
|
+template <typename T>
|
|
|
+struct is_container<T, std::enable_if_t<!std::is_void_v<typename T::value_type>>> : std::true_type {};
|
|
|
+
|
|
|
+template <typename T>
|
|
|
+static constexpr bool const is_string_v = is_string<T>::value;
|
|
|
+template <typename T>
|
|
|
+static constexpr bool const is_container_v = is_container<T>::value;
|
|
|
+
|
|
|
class cli {
|
|
|
public:
|
|
|
using args_t = std::vector<std::string>;
|
|
|
@@ -83,7 +100,16 @@ cli & cli::register_callback(std::string const & handle,
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
|
-template <typename T> void cli_print(T const & value) { std::cout << value; }
|
|
|
+template <typename T> void cli_print(T const & value) {
|
|
|
+ if constexpr (is_container_v<T> && !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) {
|