1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_RBD_SHELL_H
5 #define CEPH_RBD_SHELL_H
7 #include "include/int_types.h"
11 #include <boost/program_options.hpp>
17 typedef std::vector<const char *> Arguments;
18 typedef std::vector<std::string> CommandSpec;
21 typedef void (*GetArguments)(boost::program_options::options_description *,
22 boost::program_options::options_description *);
23 typedef int (*Execute)(const boost::program_options::variables_map &);
25 CommandSpec command_spec;
26 CommandSpec alias_command_spec;
27 const std::string description;
28 const std::string help;
29 GetArguments get_arguments;
33 template <typename Args, typename Execute>
34 Action(const std::initializer_list<std::string> &command_spec,
35 const std::initializer_list<std::string> &alias_command_spec,
36 const std::string &description, const std::string &help,
37 Args args, Execute execute, bool visible = true)
38 : command_spec(command_spec), alias_command_spec(alias_command_spec),
39 description(description), help(help), get_arguments(args),
40 execute(execute), visible(visible) {
41 Shell::get_actions().push_back(this);
46 struct SwitchArguments {
47 SwitchArguments(const std::initializer_list<std::string> &arguments) {
48 Shell::get_switch_arguments().insert(arguments.begin(), arguments.end());
52 int execute(const Arguments &argument);
55 static std::vector<Action *>& get_actions();
56 static std::set<std::string>& get_switch_arguments();
58 void get_command_spec(const std::vector<std::string> &arguments,
59 std::vector<std::string> *command_spec);
60 Action *find_action(const CommandSpec &command_spec,
61 CommandSpec **matching_spec, bool *is_alias);
63 void get_global_options(boost::program_options::options_description *opts);
66 void print_action_help(Action *action, bool is_alias);
67 void print_unknown_action(const CommandSpec &command_spec);
69 void print_bash_completion(const CommandSpec &command_spec);
70 void print_bash_completion_options(
71 const boost::program_options::options_description &ops);
76 #endif // CEPH_RBD_SHELL_H