} // anonymous namespace
-std::vector<Shell::Action *> Shell::s_actions;
-std::set<std::string> Shell::s_switch_arguments;
+std::vector<Shell::Action *>& Shell::get_actions() {
+ static std::vector<Action *> actions;
+
+ return actions;
+}
+
+std::set<std::string>& Shell::get_switch_arguments() {
+ static std::set<std::string> switch_arguments;
+
+ return switch_arguments;
+}
int Shell::execute(int arg_count, const char **arg_values) {
} else if (arg[0] == '-') {
// if the option is not a switch, skip its value
if (arg.size() >= 2 &&
- (arg[1] == '-' || s_switch_arguments.count(arg.substr(1, 1)) == 0) &&
+ (arg[1] == '-' ||
+ get_switch_arguments().count(arg.substr(1, 1)) == 0) &&
(arg[1] != '-' ||
- s_switch_arguments.count(arg.substr(2, std::string::npos)) == 0) &&
+ get_switch_arguments().count(arg.substr(2, std::string::npos)) == 0) &&
at::SWITCH_ARGUMENTS.count(arg.substr(2, std::string::npos)) == 0 &&
arg.find('=') == std::string::npos) {
++i;
Shell::Action *Shell::find_action(const CommandSpec &command_spec,
CommandSpec **matching_spec) {
- for (size_t i = 0; i < s_actions.size(); ++i) {
- Action *action = s_actions[i];
+ for (size_t i = 0; i < get_actions().size(); ++i) {
+ Action *action = get_actions()[i];
if (action->command_spec.size() <= command_spec.size()) {
if (std::includes(action->command_spec.begin(),
action->command_spec.end(),
<< "Command-line interface for managing Ceph RBD images."
<< std::endl << std::endl;
- std::vector<Action *> actions(s_actions);
+ std::vector<Action *> actions(get_actions());
std::sort(actions.begin(), actions.end(),
[](Action *lhs, Action *rhs) { return lhs->command_spec <
rhs->command_spec; });
print_bash_completion_options(command_opts);
} else {
std::cout << "|help";
- for (size_t i = 0; i < s_actions.size(); ++i) {
- Action *action = s_actions[i];
+ for (size_t i = 0; i < get_actions().size(); ++i) {
+ Action *action = get_actions()[i];
std::cout << "|"
<< joinify<std::string>(action->command_spec.begin(),
action->command_spec.end(), " ");
: command_spec(command_spec), alias_command_spec(alias_command_spec),
description(description), help(help), get_arguments(args),
execute(execute) {
- Shell::s_actions.push_back(this);
+ Shell::get_actions().push_back(this);
}
};
struct SwitchArguments {
SwitchArguments(const std::initializer_list<std::string> &arguments) {
- Shell::s_switch_arguments.insert(arguments.begin(), arguments.end());
+ Shell::get_switch_arguments().insert(arguments.begin(), arguments.end());
}
};
int execute(int arg_count, const char **arg_values);
private:
- static std::vector<Action *> s_actions;
- static std::set<std::string> s_switch_arguments;
+ static std::vector<Action *>& get_actions();
+ static std::set<std::string>& get_switch_arguments();
void get_command_spec(const std::vector<std::string> &arguments,
std::vector<std::string> *command_spec);