Skip to content

Commit

Permalink
Use the Ignition custom CLI formatter (#69)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <michael@openrobotics.org>
Signed-off-by: Louise Poubel <louise@openrobotics.org>
Signed-off-by: ahcorde <ahcorde@gmail.com>

Co-authored-by: Carlos Agüero <cen.aguero@gmail.com>
Co-authored-by: Louise Poubel <louise@openrobotics.org>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
  • Loading branch information
4 people authored Jul 6, 2022
1 parent 3262c92 commit cc8233f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
#============================================================================
Expand Down
23 changes: 12 additions & 11 deletions loader/src/cmd/plugin_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/
#include <gz/utils/cli/CLI.hpp>
#include <gz/utils/cli/GzFormatter.hpp>

#include "gz.hh"

Expand Down Expand Up @@ -52,6 +53,7 @@ void runPluginCommand(const PluginOptions &_opt)
}
}

//////////////////////////////////////////////////
void addPluginFlags(CLI::App &_app)
{
auto opt = std::make_shared<PluginOptions>();
Expand All @@ -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);
Expand All @@ -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<IgnitionFormatter>(&app));
CLI11_PARSE(app, argc, argv);
}
8 changes: 4 additions & 4 deletions loader/src/gz_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit cc8233f

Please sign in to comment.