From: zhengyin Date: Tue, 31 Mar 2020 15:30:26 +0000 (+0800) Subject: tools: remove all deprecated options from the help output X-Git-Tag: v16.1.0~2607^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=09f1da60a6d2b0eaa26815697478ad96b8988706;p=ceph.git tools: remove all deprecated options from the help output Signed-off-by: Zheng Yin --- diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 2107c55425f5..1f9aff38fb95 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -151,15 +151,13 @@ watch Watch events on image. Optional arguments: - -c [ --conf ] arg path to cluster configuration - --cluster arg cluster name - --id arg client id (without 'client.' prefix) - --user arg client id (without 'client.' prefix) - -n [ --name ] arg client name - -m [ --mon_host ] arg monitor host - --secret arg path to secret key (deprecated) - -K [ --keyfile ] arg path to secret key - -k [ --keyring ] arg path to keyring + -c [ --conf ] arg path to cluster configuration + --cluster arg cluster name + --id arg client id (without 'client.' prefix) + -n [ --name ] arg client name + -m [ --mon_host ] arg monitor host + -K [ --keyfile ] arg path to secret key + -k [ --keyring ] arg path to keyring See 'rbd help ' for help on a specific command. $ rbd help | grep '^ [a-z]' | sed 's/^ \([a-z -]*[a-z]\).*/\1/g' | while read -r line; do echo rbd help $line ; rbd help $line; done @@ -243,7 +241,6 @@ --dest-pool arg destination pool name --dest-namespace arg destination namespace name --dest arg destination image name - --order arg object order [12 <= order <= 25] (deprecated) --object-size arg object size in B/K/M [4K <= object size <= 32M] --image-feature arg image features [layering(+), exclusive-lock(+*), object-map(+*), @@ -447,7 +444,6 @@ --dest-pool arg destination pool name --dest-namespace arg destination namespace name --dest arg destination image name - --order arg object order [12 <= order <= 25] (deprecated) --object-size arg object size in B/K/M [4K <= object size <= 32M] --image-feature arg image features [layering(+), exclusive-lock(+*), @@ -490,10 +486,7 @@ -p [ --pool ] arg pool name --namespace arg namespace name --image arg image name - --image-format arg image format [1 (deprecated) or 2] - --new-format use image format 2 - (deprecated) - --order arg object order [12 <= order <= 25] (deprecated) + --image-format arg image format [default: 2] --object-size arg object size in B/K/M [4K <= object size <= 32M] --image-feature arg image features [layering(+), exclusive-lock(+*), object-map(+*), @@ -548,7 +541,6 @@ --dest-pool arg destination pool name --dest-namespace arg destination namespace name --dest arg destination image name - --order arg object order [12 <= order <= 25] (deprecated) --object-size arg object size in B/K/M [4K <= object size <= 32M] --image-feature arg image features [layering(+), exclusive-lock(+*), @@ -1119,10 +1111,7 @@ --dest-pool arg destination pool name --dest-namespace arg destination namespace name --dest arg destination image name - --image-format arg image format [1 (deprecated) or 2] - --new-format use image format 2 - (deprecated) - --order arg object order [12 <= order <= 25] (deprecated) + --image-format arg image format [default: 2] --object-size arg object size in B/K/M [4K <= object size <= 32M] --image-feature arg image features [layering(+), exclusive-lock(+*), object-map(+*), @@ -1137,8 +1126,6 @@ --sparse-size arg sparse size in B/K/M [default: 4K] --no-progress disable progress output --export-format arg format of image file - -p [ --pool ] arg pool name (deprecated) - --image arg image name (deprecated) Image Features: (*) supports enabling/disabling on existing images @@ -1497,10 +1484,7 @@ --dest-pool arg destination pool name --dest-namespace arg destination namespace name --dest arg destination image name - --image-format arg image format [1 (deprecated) or 2] - --new-format use image format 2 - (deprecated) - --order arg object order [12 <= order <= 25] (deprecated) + --image-format arg image format [default: 2] --object-size arg object size in B/K/M [4K <= object size <= 32M] --image-feature arg image features [layering(+), exclusive-lock(+*), object-map(+*), diff --git a/src/tools/rbd/ArgumentTypes.cc b/src/tools/rbd/ArgumentTypes.cc index fbf9c62831da..e21c60aa3f7d 100644 --- a/src/tools/rbd/ArgumentTypes.cc +++ b/src/tools/rbd/ArgumentTypes.cc @@ -227,15 +227,15 @@ void add_create_image_options(po::options_description *opt, if (include_format) { opt->add_options() (IMAGE_FORMAT.c_str(), po::value(), - "image format [1 (deprecated) or 2]") + "image format [default: 2]") (IMAGE_NEW_FORMAT.c_str(), po::value()->zero_tokens(), - "use image format 2\n(deprecated)"); + "deprecated[:image-format 2]"); } opt->add_options() (IMAGE_ORDER.c_str(), po::value(), - "object order [12 <= order <= 25] (deprecated)") + "deprecated[:object-size]") (IMAGE_OBJECT_SIZE.c_str(), po::value(), "object size in B/K/M [4K <= object size <= 32M]") (IMAGE_FEATURES.c_str(), po::value()->composing(), @@ -431,8 +431,6 @@ void validate(boost::any& v, const std::vector& values, void validate(boost::any& v, const std::vector& values, ImageNewFormat *target_type, int dummy) { - std::cout << "rbd: --new-format is deprecated, use --image-format" - << std::endl; v = boost::any(true); } @@ -504,7 +502,6 @@ void validate(boost::any& v, const std::vector& values, void validate(boost::any& v, const std::vector& values, Secret *target_type, int) { - std::cerr << "rbd: --secret is deprecated, use --keyfile" << std::endl; po::validators::check_first_occurrence(v); const std::string &s = po::validators::get_single_string(values); diff --git a/src/tools/rbd/OptionPrinter.cc b/src/tools/rbd/OptionPrinter.cc index 14affb0b3bb8..a1874a769dcf 100644 --- a/src/tools/rbd/OptionPrinter.cc +++ b/src/tools/rbd/OptionPrinter.cc @@ -56,6 +56,28 @@ void OptionPrinter::print_short(std::ostream &os, size_t initial_offset) { } } +void OptionPrinter::print_optional(const OptionsDescription &global_opts, + size_t &name_width, std::ostream &os) { + std::string indent2(2, ' '); + + for (size_t i = 0; i < global_opts.options().size(); ++i) { + std::string description = global_opts.options()[i]->description(); + auto result = boost::find_first(description, "deprecated"); + if (!result.empty()) { + continue; + } + std::stringstream ss; + ss << indent2 + << global_opts.options()[i]->format_name() << " " + << global_opts.options()[i]->format_parameter(); + + std::cout << ss.str(); + IndentStream indent_stream(name_width, ss.str().size(), LINE_WIDTH, std::cout); + indent_stream << global_opts.options()[i]->description() << std::endl; + } + +} + void OptionPrinter::print_detailed(std::ostream &os) { std::string indent_prefix(2, ' '); size_t name_width = compute_name_width(indent_prefix.size()); @@ -76,16 +98,7 @@ void OptionPrinter::print_detailed(std::ostream &os) { if (m_optional.options().size() > 0) { std::cout << OPTIONAL_ARGUMENTS << std::endl; - for (size_t i = 0; i < m_optional.options().size(); ++i) { - std::stringstream ss; - ss << indent_prefix - << m_optional.options()[i]->format_name() << " " - << m_optional.options()[i]->format_parameter(); - - std::cout << ss.str(); - IndentStream indent_stream(name_width, ss.str().size(), LINE_WIDTH, os); - indent_stream << m_optional.options()[i]->description() << std::endl; - } + print_optional(m_optional, name_width, os); std::cout << std::endl; } } diff --git a/src/tools/rbd/OptionPrinter.h b/src/tools/rbd/OptionPrinter.h index 02bb8e1c2742..06d3a3c99141 100644 --- a/src/tools/rbd/OptionPrinter.h +++ b/src/tools/rbd/OptionPrinter.h @@ -7,6 +7,7 @@ #include "include/int_types.h" #include #include +#include #include namespace rbd { @@ -27,6 +28,8 @@ public: void print_short(std::ostream &os, size_t initial_offset); void print_detailed(std::ostream &os); + static void print_optional(const OptionsDescription &global_opts, + size_t &name_width, std::ostream &os); private: const OptionsDescription &m_positional; diff --git a/src/tools/rbd/Shell.cc b/src/tools/rbd/Shell.cc index 9993c691b410..15080f372b01 100644 --- a/src/tools/rbd/Shell.cc +++ b/src/tools/rbd/Shell.cc @@ -122,6 +122,15 @@ std::set& Shell::get_switch_arguments() { return switch_arguments; } +void print_deprecated_warning(po::option_description option, std::string description) { + auto pos = description.find_first_of(":"); + if (pos != std::string::npos) { + std::string param = description.substr(pos + 1, description.size() - pos - 2); + std::cout << "rbd: " << option.format_name() << " is deprecated, use --" + << param << std::endl; + } +} + int Shell::execute(int argc, const char **argv) { std::vector arguments; std::vector ceph_global_init_args; @@ -202,6 +211,46 @@ int Shell::execute(int argc, const char **argv) { } int r = (*action->execute)(vm, ceph_global_init_args); + + if (vm.size() > 0) { + for (auto opt : vm) { + try { + auto option = command_opts.find(opt.first, false); + auto description = option.description(); + auto result = boost::find_first(description, "deprecated"); + if (!result.empty()) { + print_deprecated_warning(option, description); + } + } catch (exception& e) { + continue; + } + } + } + + po::options_description global_opts; + get_global_options(&global_opts); + auto it = ceph_global_init_args.begin(); + for ( ; it != ceph_global_init_args.end(); ++it) { + auto pos = (*it).find_last_of("-"); + auto prefix_style = po::command_line_style::allow_long; + if (pos == 0) { + prefix_style = po::command_line_style::allow_dash_for_short; + } else if (pos == std::string::npos) { + continue; + } + + for (size_t i = 0; i < global_opts.options().size(); ++i) { + std::string param_name = global_opts.options()[i]->canonical_display_name( + prefix_style); + auto description = global_opts.options()[i]->description(); + auto result = boost::find_first(description, "deprecated"); + if (!result.empty() && *it == param_name) { + print_deprecated_warning(*global_opts.options()[i], description); + break; + } + } + } + if (r != 0) { return std::abs(r); } @@ -290,10 +339,10 @@ void Shell::get_global_options(po::options_description *opts) { ((at::CONFIG_PATH + ",c").c_str(), po::value(), "path to cluster configuration") ("cluster", po::value(), "cluster name") ("id", po::value(), "client id (without 'client.' prefix)") - ("user", po::value(), "client id (without 'client.' prefix)") + ("user", po::value(), "deprecated[:id]") ("name,n", po::value(), "client name") ("mon_host,m", po::value(), "monitor host") - ("secret", po::value(), "path to secret key (deprecated)") + ("secret", po::value(), "deprecated[:keyfile]") ("keyfile,K", po::value(), "path to secret key") ("keyring,k", po::value(), "path to keyring"); } @@ -343,9 +392,13 @@ void Shell::print_help() { } } - po::options_description global_opts(OptionPrinter::OPTIONAL_ARGUMENTS); + po::options_description global_opts; get_global_options(&global_opts); - std::cout << std::endl << global_opts << std::endl + + std::cout << std::endl << OptionPrinter::OPTIONAL_ARGUMENTS << ":" << std::endl; + OptionPrinter::print_optional(global_opts, name_width, std::cout); + + std::cout << std::endl << "See '" << APP_NAME << " help ' for help on a specific " << "command." << std::endl; } diff --git a/src/tools/rbd/Utils.cc b/src/tools/rbd/Utils.cc index 520b654714b8..f02adb8a32ee 100644 --- a/src/tools/rbd/Utils.cc +++ b/src/tools/rbd/Utils.cc @@ -439,8 +439,6 @@ int get_image_options(const boost::program_options::variables_map &vm, if (vm.count(at::IMAGE_ORDER)) { order = vm[at::IMAGE_ORDER].as(); - std::cerr << "rbd: --order is deprecated, use --object-size" - << std::endl; } else if (vm.count(at::IMAGE_OBJECT_SIZE)) { object_size = vm[at::IMAGE_OBJECT_SIZE].as(); order = std::round(std::log2(object_size)); diff --git a/src/tools/rbd/action/Import.cc b/src/tools/rbd/action/Import.cc index b4292b336ea6..d1eb84a82f52 100644 --- a/src/tools/rbd/action/Import.cc +++ b/src/tools/rbd/action/Import.cc @@ -945,8 +945,8 @@ void get_arguments(po::options_description *positional, // TODO legacy rbd allowed import to accept both 'image'/'dest' and // 'pool'/'dest-pool' - at::add_pool_option(options, at::ARGUMENT_MODIFIER_NONE, " (deprecated)"); - at::add_image_option(options, at::ARGUMENT_MODIFIER_NONE, " (deprecated)"); + at::add_pool_option(options, at::ARGUMENT_MODIFIER_NONE, " deprecated[:dest-pool]"); + at::add_image_option(options, at::ARGUMENT_MODIFIER_NONE, " deprecated[:dest]"); } int execute(const po::variables_map &vm, @@ -962,15 +962,11 @@ int execute(const po::variables_map &vm, std::string deprecated_pool_name; if (vm.count(at::POOL_NAME)) { deprecated_pool_name = vm[at::POOL_NAME].as(); - std::cerr << "rbd: --pool is deprecated for import, use --dest-pool" - << std::endl; } std::string deprecated_image_name; if (vm.count(at::IMAGE_NAME)) { deprecated_image_name = vm[at::IMAGE_NAME].as(); - std::cerr << "rbd: --image is deprecated for import, use --dest" - << std::endl; } else { deprecated_image_name = path.substr(path.find_last_of("/") + 1); }