// // cli.h // tax-manager // // Created by Sam Jaffe on 10/8/20. // Copyright © 2020 Sam Jaffe. All rights reserved. // #pragma once #include #include #include #include #include #include "lambda_cast.h" namespace cli { class cli { public: using args_t = std::vector; using callback = std::function; private: std::unordered_map callbacks_; bool eof_; public: cli(); template cli & register_callback(std::string const & handle, std::function const & cb); template cli & register_callback(std::string const & handle, F && cb) { return register_callback(handle, lambdas::FFL(cb)); } void run() const; template static T from_string(std::string const &); }; template void cli_invoke(std::function cb, cli::args_t const & args, std::index_sequence) { using tuple = std::tuple; cb(cli::from_string>(args[Is])...); } template cli & cli::register_callback(std::string const & handle, std::function const & cb) { callbacks_.emplace(handle, [cb](args_t const & args) { if (sizeof...(Args) > args.size()) return; // TODO: Error message cli_invoke(cb, args, std::make_index_sequence()); }); return *this; } }