Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the Ignition custom CLI formatter #69

Merged
merged 6 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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