// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_RBD_SHELL_H #define CEPH_RBD_SHELL_H #include "include/int_types.h" #include #include #include #include namespace rbd { class Shell { public: typedef std::vector Arguments; typedef std::vector CommandSpec; struct Action { typedef void (*GetArguments)(boost::program_options::options_description *, boost::program_options::options_description *); typedef int (*Execute)(const boost::program_options::variables_map &); CommandSpec command_spec; CommandSpec alias_command_spec; const std::string description; const std::string help; GetArguments get_arguments; Execute execute; bool visible; template Action(const std::initializer_list &command_spec, const std::initializer_list &alias_command_spec, const std::string &description, const std::string &help, Args args, Execute execute, bool visible = true) : command_spec(command_spec), alias_command_spec(alias_command_spec), description(description), help(help), get_arguments(args), execute(execute), visible(visible) { Shell::get_actions().push_back(this); } }; struct SwitchArguments { SwitchArguments(const std::initializer_list &arguments) { Shell::get_switch_arguments().insert(arguments.begin(), arguments.end()); } }; int execute(const Arguments &argument); private: static std::vector& get_actions(); static std::set& get_switch_arguments(); void get_command_spec(const std::vector &arguments, std::vector *command_spec); Action *find_action(const CommandSpec &command_spec, CommandSpec **matching_spec, bool *is_alias); void get_global_options(boost::program_options::options_description *opts); void print_help(); void print_action_help(Action *action, bool is_alias); void print_unknown_action(const CommandSpec &command_spec); void print_bash_completion(const CommandSpec &command_spec); void print_bash_completion_options( const boost::program_options::options_description &ops); }; } // namespace rbd #endif // CEPH_RBD_SHELL_H