clang-tags
C/C++ source code indexing tool based on libclang
|
Base class for command parsers. More...
#include <request.hxx>
Public Member Functions | |
CommandParser (std::string name, std::string description="") | |
Constructor. | |
void | parse (std::istream &cin, std::ostream &cout, bool echo=false) |
Parse an input stream and handle key arguments. | |
void | parseJson (const Json::Value &request, std::ostream &cout) |
Parse an input stream and handle key arguments. |
Protected Member Functions | |
const std::string & | name () |
Get the command name. | |
void | setDescription (std::string description) |
Set the command description. | |
virtual void | defaults () |
Set default values for keys. | |
virtual void | run (std::ostream &cout)=0 |
Run the command. | |
CommandParser & | add (KeyParserBase *key) |
Add a key parser to the list of parameters. |
Protected Attributes | |
std::string | prompt_ |
Prompt used for interactive plain-text requests. |
Friends | |
class | Parser |
Base class for command parsers.
Parses the keys associated to a command, and run it.
Custom commands should be implemented through user-defined functors deriving from CommandParser.
|
inline |
Constructor.
name | Command name |
description | Command description |
|
inlineprotected |
Add a key parser to the list of parameters.
key | key parser |
|
inlineprotectedvirtual |
Set default values for keys.
This method should be specialized to specify default key values.
Reimplemented in CompleteCommand, GrepCommand, FindCommand, IndexCommand, UpdateCommand, Repeat, and CompilationDatabaseCommand.
|
inlineprotected |
Get the command name.
|
inline |
Parse an input stream and handle key arguments.
Parse all key arguments provided to the command, and handle them. Also run the command and output results to the provided stream. This method is used for plain-text requests.
cin | input stream, where the request will be read |
cout | output stream |
|
inline |
Parse an input stream and handle key arguments.
Parse all key arguments provided to the command, and handle them. Also run the command and output results to the provided stream. This method is used for JSON-formatted requests.
request | JSON request |
cout | output stream |
|
protectedpure virtual |
Run the command.
This typically is a user-defined function. It should use key values and write results on the provided output stream.
cout | output stream for results |
Implemented in ExitCommand, CompleteCommand, GrepCommand, FindCommand, IndexCommand, UpdateCommand, Repeat, and CompilationDatabaseCommand.
|
inlineprotected |
Set the command description.
This description will be used for help messages.
description | command description |