Hi,
I'm having some trouble with the example in README. This compiles correctly but gives a segfault when executed.
#include "cli/cli.h"
#include "cli/clifilesession.h"
using namespace cli;
using namespace std;
int main() {
// setup cli
auto rootMenu = make_unique<Menu>("myprompt");
auto menuA = make_unique<Menu>("a_prompt");
rootMenu->Insert(std::move(menuA));
auto menuAA = make_unique<Menu>("aa_prompt");
menuA->Insert(std::move(menuAA));
auto menuAB = make_unique<Menu>("ab_prompt");
menuA->Insert(std::move(menuAB));
auto menuAC = make_unique<Menu>("ac_prompt");
menuA->Insert(std::move(menuAC));
auto menuACA = make_unique<Menu>("aca_prompt");
menuAC->Insert(std::move(menuACA));
auto menuB = make_unique<Menu>("b_prompt");
rootMenu->Insert(std::move(menuB));
auto menuBA = make_unique<Menu>("ba_prompt");
menuB->Insert(std::move(menuBA));
auto menuBB = make_unique<Menu>("bb_prompt");
menuB->Insert(std::move(menuBB));
Cli cli(std::move(rootMenu));
// global exit action
cli.ExitAction(
[](auto &out) { out << "Goodbye and thanks for all the fish.\n"; });
CliFileSession input(cli);
input.Start();
return 0;
}
A way of making it work is the following:
int main() {
// setup cli
auto rootMenu = make_unique<Menu>("myprompt");
auto menuA = make_unique<Menu>("a_prompt");
auto menuAA = make_unique<Menu>("aa_prompt");
auto menuAB = make_unique<Menu>("ab_prompt");
auto menuAC = make_unique<Menu>("ac_prompt");
auto menuACA = make_unique<Menu>("aca_prompt");
auto menuB = make_unique<Menu>("b_prompt");
auto menuBA = make_unique<Menu>("ba_prompt");
auto menuBB = make_unique<Menu>("bb_prompt");
menuAC->Insert(std::move(menuACA));
menuB->Insert(std::move(menuBB));
menuB->Insert(std::move(menuBA));
menuA->Insert(std::move(menuAA));
menuA->Insert(std::move(menuAB));
menuA->Insert(std::move(menuAC));
rootMenu->Insert(std::move(menuA));
rootMenu->Insert(std::move(menuB));
Cli cli(std::move(rootMenu));
// global exit action
cli.ExitAction(
[](auto &out) { out << "Goodbye and thanks for all the fish.\n"; });
CliFileSession input(cli);
input.Start();
return 0;
}
I'm not sure why, unfortunately I don't have much time to study the problem. Hope this can help.
Thanks for you work,
Luca
Hi,
I'm having some trouble with the example in README. This compiles correctly but gives a segfault when executed.
A way of making it work is the following:
I'm not sure why, unfortunately I don't have much time to study the problem. Hope this can help.
Thanks for you work,
Luca