You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. I've run into a strange issue. When I use the parse_complete_callback() function, values for options specified in a config file are not assigned to their respective variables. In this case, the flag_sub variable is always set to false, despite the fact that the config_to_str() function shows that --flag-sub=true.
./app sub
config.toml:
[sub]
flag-sub=true
#include<CLI/CLI.hpp>structOptions
{
bool flag_sub = false;
};
voidSetupSub(CLI::App& app)
{
auto opt = std::make_shared<Options>();
auto* sub = app.add_subcommand("sub", "A subcommand");
sub->add_flag("--flag-sub,!--no-flag-sub", opt->flag_sub, "flag sub")->default_val(false);
//flag_sub is false//comment out this to fix the issue
sub->parse_complete_callback([opt]()
{
std::cout << "Running the parse complete callback for the sub; flag-sub: " << opt->flag_sub << std::endl;
});
//flag_sub is still false unless you remove parse_complete_callback
sub->callback([opt]()
{
std::cout << "Running the callback for the sub; flag-sub: " << opt->flag_sub << std::endl;
});
}
intmain(int argc, char** argv)
{
CLI::App app{"My app"};
//Specify your path to the config
app.set_config("--conf", "/home/user/config.toml", "Set a config for the app");
argv = app.ensure_utf8(argv);
app.fallthrough();
app.require_subcommand(0, 1);
SetupSub(app);
try
{
app.parse(argc, argv);
std::cout << app.config_to_str() << std::endl;
}
catch(const CLI::ParseError &e)
{
return app.exit(e);
}
}
The following is mentioned in README:
If the main app or subcommand has a config file, no data from the config file will be reflected in parse_complete_callback
Is it the case? Is it also expected that in a regular callback() no data from a config is available? The reason for such behavior is not immediately clear.
The text was updated successfully, but these errors were encountered:
The difference is that parse complete is run as soon as parsing the command line is completed. For some subcommands this means it can be called multiple times if multiple duplicate subcommands. This occurs prior to any processing of config file.
The regular callback is completed after all processing is completed, in which case all processing of config files will have been completed.
The difference is that parse complete is run as soon as parsing the command line is completed. For some subcommands this means it can be called multiple times if multiple duplicate subcommands. This occurs prior to any processing of config file.
This clarifies some things. This detail should probably be mentioned in the code documentation.
The regular callback is completed after all processing is completed, in which case all processing of config files will have been completed.
In the code example I provided, the value of flag_sub does not match the value that is used in the config file when regular callback is evoked.
Hello. I've run into a strange issue. When I use the parse_complete_callback() function, values for options specified in a config file are not assigned to their respective variables. In this case, the flag_sub variable is always set to false, despite the fact that the config_to_str() function shows that --flag-sub=true.
config.toml:
The following is mentioned in README:
Is it the case? Is it also expected that in a regular callback() no data from a config is available? The reason for such behavior is not immediately clear.
The text was updated successfully, but these errors were encountered: