-
Hi, issue: question: Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi @vlsireddy , The Cli library is not for parsing application parameters, instead, it provides an interactive shell where you can enter commands in a positional way.
So, instead of:
you can have instead:
|
Beta Was this translation helpful? Give feedback.
-
Hi, understood both points. btw gr8 work. Thanks |
Beta Was this translation helpful? Give feedback.
-
After making an off-topic reply on #69, this seems to be a more appropriate place to make my suggestion. While CLI does not provide a way to parse and handle arguments, it is possible to have an arbitrary list of arguments as a list of string. There is two tweaks to do with regard to a normal use of argparse:
Fortunately, it is possible to work around those two issues relatively easily. An example of this manipulation, is this code: static void cmd_read_lib(std::ostream& out, const std::vector<std::string>& _args){
std::vector<std::string> extended_args = {"read"};
std::copy(std::begin(_args),std::end(_args),std::back_inserter(extended_args));
argparse::ArgumentParser args("Liberty reader","1.0.0",argparse::default_arguments::none);
// Note default_arguments::none
args.add_argument("path")
.help("Liberty file path");
args.add_argument("--threads","-j")
.help("Number of threads to use. 0 for maximum")
.scan<'i', int>()
.default_value(1);
args.add_argument("-h", "--help")
.action([=](const std::string& s) {
std::cout << args; // Still display the help, but doesn't quit the program.
})
.default_value(false)
.help("shows help message")
.implicit_value(true)
.nargs(0);
args.parse_args(extended_args);
if (args.get<bool>("help")) // Properly exit the function if help is requested.
return;
// Rest of the function
}
// ... In your menu building :
function<void(ostream&,const vector<string>&)> f_read = cmd_read_lib;
root->Insert("read",f_read,"Read the liberty file"); When using the help, the argument parser will complain that there is a missing positional argument, but this is a minor issue and doesn't cause actual issue. Hoping that it can help ! |
Beta Was this translation helpful? Give feedback.
Hi @vlsireddy ,
first of all, thank you for using cli library.
The
simplelocalsession
is an example of using aSimpleLocalSession
that does not provide autocompletion and other valuable features.Instead, you should use
CliLocalSession
(see the examplescomplete
orpluginmanager
).Cli library is not for parsing application parameters, instead, it provides an interactive shell where you can enter commands in a positional way.
Every command has this syntax:
So, instead of:
you can have instead: