From 28ac027f6f86635d320f0f5e25582452011d9bed Mon Sep 17 00:00:00 2001 From: YongQiang Date: Fri, 22 Apr 2016 11:20:31 -0400 Subject: [PATCH] rbd:make a distinction of help message between ''rbd snap rollback" and "rbd snap revert" Fixes: https://tracker.ceph.com/issues/15521 Signed-off-by: Yongqiang He (cherry picked from commit 1bf26509c6efd06a8facc0e45ab42255592ca74d) --- src/tools/rbd/Shell.cc | 27 ++++++++++++++++----------- src/tools/rbd/Shell.h | 4 ++-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/tools/rbd/Shell.cc b/src/tools/rbd/Shell.cc index 5fba993ae4d46..6e3431bed9081 100644 --- a/src/tools/rbd/Shell.cc +++ b/src/tools/rbd/Shell.cc @@ -84,6 +84,7 @@ int Shell::execute(const Arguments& cmdline_arguments) { cmdline_arguments.end()); std::vector command_spec; get_command_spec(arguments, &command_spec); + bool is_alias = true; if (command_spec.empty() || command_spec == CommandSpec({"help"})) { // list all available actions @@ -92,12 +93,12 @@ int Shell::execute(const Arguments& cmdline_arguments) { } else if (command_spec[0] == HELP_SPEC) { // list help for specific action command_spec.erase(command_spec.begin()); - Action *action = find_action(command_spec, NULL); + Action *action = find_action(command_spec, NULL, &is_alias); if (action == NULL) { print_unknown_action(command_spec); return EXIT_FAILURE; } else { - print_action_help(action); + print_action_help(action, is_alias); return 0; } } else if (command_spec[0] == BASH_COMPLETION_SPEC) { @@ -107,7 +108,7 @@ int Shell::execute(const Arguments& cmdline_arguments) { } CommandSpec *matching_spec; - Action *action = find_action(command_spec, &matching_spec); + Action *action = find_action(command_spec, &matching_spec, &is_alias); if (action == NULL) { print_unknown_action(command_spec); return EXIT_FAILURE; @@ -210,7 +211,7 @@ void Shell::get_command_spec(const std::vector &arguments, } Shell::Action *Shell::find_action(const CommandSpec &command_spec, - CommandSpec **matching_spec) { + CommandSpec **matching_spec, bool *is_alias) { for (size_t i = 0; i < get_actions().size(); ++i) { Action *action = get_actions()[i]; if (action->command_spec.size() <= command_spec.size()) { @@ -221,6 +222,7 @@ Shell::Action *Shell::find_action(const CommandSpec &command_spec, if (matching_spec != NULL) { *matching_spec = &action->command_spec; } + *is_alias = false; return action; } } @@ -234,6 +236,7 @@ Shell::Action *Shell::find_action(const CommandSpec &command_spec, if (matching_spec != NULL) { *matching_spec = &action->alias_command_spec; } + *is_alias = true; return action; } } @@ -302,14 +305,13 @@ void Shell::print_help() { std::cout << std::endl << global_opts << std::endl << "See '" << APP_NAME << " help ' for help on a specific " << "command." << std::endl; -} - -void Shell::print_action_help(Action *action) { + } +void Shell::print_action_help(Action *action, bool is_alias) { std::stringstream ss; - ss << "usage: " << APP_NAME << " " - << format_command_spec(action->command_spec); - std::cout << ss.str(); + ss << "usage: " << APP_NAME << " " + << format_command_spec(is_alias ? action->alias_command_spec : action->command_spec); + std::cout << ss.str(); po::options_description positional; po::options_description options; @@ -339,7 +341,10 @@ void Shell::print_unknown_action(const std::vector &command_spec) { } void Shell::print_bash_completion(const CommandSpec &command_spec) { - Action *action = find_action(command_spec, NULL); + + bool is_alias = true; + + Action *action = find_action(command_spec, NULL, &is_alias); po::options_description global_opts; get_global_options(&global_opts); print_bash_completion_options(global_opts); diff --git a/src/tools/rbd/Shell.h b/src/tools/rbd/Shell.h index 679213051f064..7437828747114 100644 --- a/src/tools/rbd/Shell.h +++ b/src/tools/rbd/Shell.h @@ -57,12 +57,12 @@ private: void get_command_spec(const std::vector &arguments, std::vector *command_spec); Action *find_action(const CommandSpec &command_spec, - CommandSpec **matching_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); + 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); -- 2.39.5