A C++ framework for writing line-oriented command interpreters in the style of a Unix shell.
The cli library parses each line the user types: commands, arguments,
variable assignments, redirections (<, >, >>), pipes (|) and background
execution (&). It then calls the functions the program has registered for
each command.
- A C++ compiler with C++11 support
- CMake 2.6 or later
- Boost 1.44 or later
- Doxygen (optional, only to build the documentation)
cd build
cmake ..
makeThe demo program is built as build/bin/simpleshell and the static library as
build/lib/libcli.a.
To generate the API documentation, run make doc (requires Doxygen).
src/main.cpp is a complete example. The essentials are:
#include <cli/shell.hpp>
bool onCommand(const std::string& command, cli::ShellArguments const& arguments)
{
// Run the command...
return false; // returning true ends the interpreter
}
int main()
{
cli::ShellInterpreter interpreter;
interpreter.promptText("$ ");
interpreter.onRunCommand(&onCommand);
interpreter.loop();
return 0;
}include/cli/— public library headerssrc/cli/— library implementationsrc/main.cpp— demo programdoc/— Doxygen configuration
Copyright 2010-2016 Jesús Torres jmtorres@ull.es
Licensed under the Apache License 2.0.