From 94fcad155dd2b1d35264e628309b67977146dfff Mon Sep 17 00:00:00 2001 From: songweibin Date: Tue, 1 Aug 2017 19:48:04 +0800 Subject: [PATCH] rbd: '--pretty-format' should return error if '--format' not used Signed-off-by: songweibin (cherry picked from commit 47e7549826b55905e7f298717fedf0e8f220940a) Conflicts: src/test/cli/rbd/help.t (master has several new commands compared to luminous: omit these) --- src/test/cli/rbd/help.t | 32 ++++++++++++++++---------------- src/tools/rbd/ArgumentTypes.cc | 2 +- src/tools/rbd/Utils.cc | 4 ++++ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index a509ffd4e2d3d..06cfa294f814b 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -141,7 +141,7 @@ Skip test on FreeBSD as it generates different output there. -p [ --pool ] arg pool name --image arg image name --snap arg snapshot name - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help clone @@ -301,7 +301,7 @@ Skip test on FreeBSD as it generates different output there. --snap arg snapshot name --from-snap arg snapshot starting point --whole-object compare whole object - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help disk-usage @@ -320,7 +320,7 @@ Skip test on FreeBSD as it generates different output there. -p [ --pool ] arg pool name --image arg image name --snap arg snapshot name - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) --from-snap arg snapshot starting point @@ -453,7 +453,7 @@ Skip test on FreeBSD as it generates different output there. Optional arguments -p [ --pool ] arg pool name --image arg image name - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help image-meta remove @@ -575,7 +575,7 @@ Skip test on FreeBSD as it generates different output there. --image arg image name --snap arg snapshot name --image-id arg image id - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help journal client disconnect @@ -654,7 +654,7 @@ Skip test on FreeBSD as it generates different output there. -p [ --pool ] arg pool name --image arg image name --journal arg journal name - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help journal inspect @@ -706,7 +706,7 @@ Skip test on FreeBSD as it generates different output there. -p [ --pool ] arg pool name --image arg image name --journal arg journal name - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help list @@ -721,7 +721,7 @@ Skip test on FreeBSD as it generates different output there. Optional arguments -l [ --long ] long listing format -p [ --pool ] arg pool name - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help lock add @@ -754,7 +754,7 @@ Skip test on FreeBSD as it generates different output there. Optional arguments -p [ --pool ] arg pool name --image arg image name - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help lock remove @@ -893,7 +893,7 @@ Skip test on FreeBSD as it generates different output there. Optional arguments -p [ --pool ] arg pool name --image arg image name - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help mirror pool demote @@ -945,7 +945,7 @@ Skip test on FreeBSD as it generates different output there. Optional arguments -p [ --pool ] arg pool name - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help mirror pool peer add @@ -1019,7 +1019,7 @@ Skip test on FreeBSD as it generates different output there. Optional arguments -p [ --pool ] arg pool name - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) --verbose be verbose @@ -1165,7 +1165,7 @@ Skip test on FreeBSD as it generates different output there. Show the rbd images mapped by the kernel. Optional arguments - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help snap create @@ -1227,7 +1227,7 @@ Skip test on FreeBSD as it generates different output there. -p [ --pool ] arg pool name --image arg image name --image-id arg image id - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help snap protect @@ -1351,7 +1351,7 @@ Skip test on FreeBSD as it generates different output there. Optional arguments -p [ --pool ] arg pool name --image arg image name - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help trash list @@ -1368,7 +1368,7 @@ Skip test on FreeBSD as it generates different output there. -p [ --pool ] arg pool name -a [ --all ] list images from all sources -l [ --long ] long listing format - --format arg output format [plain, json, or xml] + --format arg output format (plain, json, or xml) [default: plain] --pretty-format pretty formatting (json and xml) rbd help trash move diff --git a/src/tools/rbd/ArgumentTypes.cc b/src/tools/rbd/ArgumentTypes.cc index c6c9264fd06a1..42b42a6fb37a9 100644 --- a/src/tools/rbd/ArgumentTypes.cc +++ b/src/tools/rbd/ArgumentTypes.cc @@ -332,7 +332,7 @@ void add_no_progress_option(boost::program_options::options_description *opt) { void add_format_options(boost::program_options::options_description *opt) { opt->add_options() - (FORMAT.c_str(), po::value(), "output format [plain, json, or xml]") + (FORMAT.c_str(), po::value(), "output format (plain, json, or xml) [default: plain]") (PRETTY_FORMAT.c_str(), po::bool_switch(), "pretty formatting (json and xml)"); } diff --git a/src/tools/rbd/Utils.cc b/src/tools/rbd/Utils.cc index db248e34a1b72..ccb850e876aba 100644 --- a/src/tools/rbd/Utils.cc +++ b/src/tools/rbd/Utils.cc @@ -832,6 +832,10 @@ int get_formatter(const po::variables_map &vm, << "is json or xml" << std::endl; return -EINVAL; } + } else if (vm[at::PRETTY_FORMAT].as()) { + std::cerr << "rbd: --pretty-format only works when --format " + << "is json or xml" << std::endl; + return -EINVAL; } return 0; } -- 2.39.5