String Arguments to Multi-File Subcommand #1040
Unanswered
tornupnegatives
asked this question in
Q&A
Replies: 2 comments
-
When I want to define a subcommand or even option group in a separate file I usually just have a function call that generates a There are a number of issues with the way you are doing it right now. EncoderCommand::EncoderCommand(CLI::App& app) {
auto input_path_ptr = std::make_shared<std::string>(input_path_); //This is a local variable it be destroyed when the method returns
auto output_path_ptr = std::make_shared<std::string>(output_path_); //really you probably don't want the shared_ptr here, just use input_path_ directly in the add_option.
auto* sub =
app.add_subcommand("encode", "Converts audio file to bitstream");
add_option("-i,--input,input", input_path_ptr, "Path to audio file")
->required()
->check(CLI::ExistingFile); // CLI11 doesn't know what to do with a shared_ptr directly this should be `*input_path_ptr` (ignoring lifetime issues here)
add_option("-o,--output,output", output_path_ptr, "Path to output file")
->required();
sub->callback([this]() { this->run(); });
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for getting back to me! The issue with not de-referencing the pointer makes total sense... I will provide some updates later in the week when I get a chance to work on this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to build a CLI application with multiple subcommands, where each subcommmand is defined in its own file. Currently, my subcommand class looks something like:
In the constructor, I attach the subcommand to its parent and then configure arguments, but I am running into an issue binding the string arguments due to them lacking the stream operator. See the function snipped and error below.
Can anyone suggest a better way to handle this case?
Beta Was this translation helpful? Give feedback.
All reactions