|
|
@@ -26,10 +26,13 @@ public:
|
|
|
|
|
|
private:
|
|
|
std::istream &in_;
|
|
|
+ std::string prompt_;
|
|
|
+ std::unordered_map<std::string, size_t> arguments_;
|
|
|
std::unordered_map<std::string, callback> callbacks_;
|
|
|
bool eof_;
|
|
|
|
|
|
public:
|
|
|
+ cli(std::string const & prompt, std::istream &in = std::cin);
|
|
|
cli(std::istream &in = std::cin);
|
|
|
template <typename... Args>
|
|
|
cli & register_callback(std::string const & handle,
|
|
|
@@ -38,14 +41,18 @@ public:
|
|
|
cli & register_callback(std::string const & handle, F && cb) {
|
|
|
return register_callback(handle, lambdas::FFL(cb));
|
|
|
}
|
|
|
+
|
|
|
void run() const;
|
|
|
- template <typename T> static T from_string(std::string const &);
|
|
|
template <typename T, size_t I>
|
|
|
static auto from_string(std::string const & value) {
|
|
|
using E = std::tuple_element_t<I, T>;
|
|
|
using V = std::remove_cv_t<std::remove_reference_t<E>>;
|
|
|
return from_string<V>(value);
|
|
|
}
|
|
|
+
|
|
|
+private:
|
|
|
+ bool active() const;
|
|
|
+ template <typename T> static T from_string(std::string const &);
|
|
|
};
|
|
|
|
|
|
template <typename... Args, size_t... Is>
|
|
|
@@ -58,6 +65,7 @@ void cli_invoke(std::function<void(Args...)> cb, cli::args_t const & args,
|
|
|
template <typename... Args>
|
|
|
cli & cli::register_callback(std::string const & handle,
|
|
|
std::function<void(Args...)> cb) {
|
|
|
+ arguments_.emplace(handle, sizeof...(Args));
|
|
|
callbacks_.emplace(handle, [=](args_t const & args) {
|
|
|
if (sizeof...(Args) > args.size()) {
|
|
|
std::cerr << "Missing Args in command '" << handle << "', " <<
|