From cc8233f3c2108ef2b416dd141106430dfb38e350 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Wed, 6 Jul 2022 12:31:52 -0500 Subject: [PATCH] Use the Ignition custom CLI formatter (#69) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Carroll Signed-off-by: Louise Poubel Signed-off-by: ahcorde Co-authored-by: Carlos Agüero Co-authored-by: Louise Poubel Co-authored-by: Alejandro Hernández Cordero --- CMakeLists.txt | 1 - loader/src/cmd/plugin_main.cc | 23 ++++++++++++----------- loader/src/gz_TEST.cc | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22dce7ae..a960b25e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,6 @@ find_program(GZ_TOOLS_PROGRAM gz) gz_find_package(gz-utils2 REQUIRED COMPONENTS cli) set(GZ_UTILS_VER ${gz-utils2_VERSION_MAJOR}) - #============================================================================ # Configure the build #============================================================================ diff --git a/loader/src/cmd/plugin_main.cc b/loader/src/cmd/plugin_main.cc index 9327ea71..f831c9d5 100644 --- a/loader/src/cmd/plugin_main.cc +++ b/loader/src/cmd/plugin_main.cc @@ -15,6 +15,7 @@ * */ #include +#include #include "gz.hh" @@ -52,6 +53,7 @@ void runPluginCommand(const PluginOptions &_opt) } } +////////////////////////////////////////////////// void addPluginFlags(CLI::App &_app) { auto opt = std::make_shared(); @@ -61,15 +63,14 @@ void addPluginFlags(CLI::App &_app) opt->verboseLevel = 1; }, "Print verbose info."); - auto info = _app.add_flag_callback("-i,--info", + auto plugin = _app.add_option("-p,--plugin", + opt->pluginName, + "Path to a plugin."); + + _app.add_flag_callback("-i,--info", [opt](){ opt->command = PluginCommand::kPluginInfo; - }, "Get info about a plugin.\nRequires the -p option."); - - _app.add_option("-p,--plugin", - opt->pluginName, - "Path to a plugin.\n" - "Required with -i.")->needs(info); + }, "Get info about a plugin.")->needs(plugin); _app.callback([&_app, opt](){ runPluginCommand(*opt); @@ -79,15 +80,15 @@ void addPluginFlags(CLI::App &_app) ////////////////////////////////////////////////// int main(int argc, char** argv) { - CLI::App app{"Introspect Ignition plugin"}; - - app.set_help_all_flag("--help-all", "Show all help"); + CLI::App app{"Print information about plugins.\n"}; app.add_flag_callback("--version", [](){ std::cout << gzVersion() << std::endl; throw CLI::Success(); - }); + }, "Print version number"); addPluginFlags(app); + + app.formatter(std::make_shared(&app)); CLI11_PARSE(app, argc, argv); } diff --git a/loader/src/gz_TEST.cc b/loader/src/gz_TEST.cc index 69d266ab..2cadce4b 100644 --- a/loader/src/gz_TEST.cc +++ b/loader/src/gz_TEST.cc @@ -61,18 +61,18 @@ TEST(gzTest, IgnPluginHelp) std::string gz = std::string(GZ_PATH); std::string output = custom_exec_str(gz + " plugin --help"); EXPECT_NE(std::string::npos, - output.find("-i,--info Get info about a plugin.")) + output.find("-i [--info] Get info about a plugin.")) << output; EXPECT_NE(std::string::npos, - output.find("-p,--plugin TEXT Needs: --info")) + output.find("-p [--plugin] TEXT Path to a plugin.")) << output; output = custom_exec_str(gz + " plugin"); EXPECT_NE(std::string::npos, - output.find("-i,--info Get info about a plugin.")) + output.find("-i [--info] Get info about a plugin.")) << output; EXPECT_NE(std::string::npos, - output.find("-p,--plugin TEXT Needs: --info")) + output.find("-p [--plugin] TEXT Path to a plugin.")) << output; }