CLI: A boost command line interpreter based on boost Program Option

Hi all, I wrote a little command line interpreter based on the program option library by Vladimir Prus. You can find it here: http://minilien.com/?bNPy1ECuWv. It's not a big thing but can help sometime. You also have the subversion repository there: http://code.google.com/p/clipo/ Let me know what you think. JD

on Thu Aug 02 2007, JD <jean.daniel.michaud-AT-gmail.com> wrote:
Hi all,
I wrote a little command line interpreter based on the program option library by Vladimir Prus. You can find it here: http://minilien.com/?bNPy1ECuWv.
It's not a big thing but can help sometime. You also have the subversion repository there: http://code.google.com/p/clipo/
Let me know what you think.
Hi JD, I don't think you can expect anyone here to crawl through your source code or open a zip file without first having some idea what your code does. I suggest posting some examples, right in your email message, and making the docs available online. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com

David Abrahams wrote:
on Thu Aug 02 2007, JD <jean.daniel.michaud-AT-gmail.com> wrote:
Hi all,
I wrote a little command line interpreter based on the program option library by Vladimir Prus. You can find it here: http://minilien.com/?bNPy1ECuWv.
It's not a big thing but can help sometime. You also have the subversion repository there: http://code.google.com/p/clipo/
Let me know what you think.
Hi JD,
I don't think you can expect anyone here to crawl through your source code or open a zip file without first having some idea what your code does. I suggest posting some examples, right in your email message, and making the docs available online.
But they are... Just click on the link above and you have an example :) And if load a web page is really too much, here is what you will find: Example: ///// namespace po = boost::program_options; void handler(const std::vector<std::string> ¶meters) { for (std::vector<std::string>::const_iterator it = parameters.begin(); it != parameters.end(); ++it) std::cout << *it << std::endl; } void exit_(unsigned int code = 0) { exit(code); } int main(int argc, char **argv) { boost::cli::commands_description desc; desc.add_options() ("handler", po::value< std::vector<std::string>
()->notifier(&handler)->multitoken()) ("exit", po::value< unsigned int >()->notifier(&exit_)) ;
boost::cli::command_line_interpreter cli(desc, ">"); cli.interpret(std::cin); } ////// Output:
handler error: required parameter is missing in 'handler' handler 1 2 3 1 2 3 toto error: unknown option toto exit 0 Press any key to continue . . .
JD

Hi, I am looking for a similar functionality and would like to ask your opinion, what would it require to make cli usable across a network? For example I would want to embed it and control an existing application using a telnet like service. Regards, Ariel Kalingking

Ariel Kalingking wrote:
Hi,
I am looking for a similar functionality and would like to ask your opinion, what would it require to make cli usable across a network? For example I would want to embed it and control an existing application using a telnet like service.
Well I guess for that you would need much more than a CLI. But you can use it in conjunction with some RPC implementation like xml-rpc (http://xmlrpcpp.sourceforge.net/), and bind the cli commands to an XmlRpcClient that would call remote procedure on XmlRpcServer. Something like that: // Code on client side: #define PORT 16000 void sendFile(std::vector<std::string> &args) { XmlRpcClient c(argv[0], PORT); XmlRpcValue server_args, result; server_args.setSize(args.size() - 1); for (int i = 1; i < args.size(); ++i) server_args[i] = args[i]; if (c.execute("send_file", server_args, result)) std::cout << "\nMethods:\n " << result << "\n\n"; else std::cout << "Error calling 'listMethods'\n\n"; } int main(int argc, char **argv) { boost::cli::commands_description desc; desc.add_options() ("sendFile", po::value< std::vector<std::string>
()->notifier(&sendFile), "SendFile <server_ip_address> <file1> ... <filen>") ;
boost::cli::command_line_interpreter cli(desc, ">"); cli.interpret(std::cin); } //Code on server side: // No arguments, result is "Hello". class SendFile : public XmlRpcServerMethod { public: SendFile(XmlRpcServer* s) : XmlRpcServerMethod("send_file", s) {} void execute(XmlRpcValue& params, XmlRpcValue& result) { std::cout << "send_file called on server" << std::endl; // Sends the files in params here! } }; int main(int argc, char **argv) { XmlRpcServer s; s.bindAndListen(PORT); SendFile sf_command(&s); s.work(-1.0); return 0; } Don't forget to use the last version of the cli on http://code.google.com/p/clipo/ ! :) JD
participants (3)
-
Ariel Kalingking
-
David Abrahams
-
JD