![]() |
bob.hpp
|
Represents a CLI command. More...
#include <bob.hpp>
Public Member Functions | |
CliCommand (const string &name, CliCommandFunc func, const string &description="") | |
Create a CLI command with a command function to be executed when this command is invoked. | |
CliCommand (const string &name, const string &description="") | |
Create a CLI command which prints its subcommands and flags when invoked. | |
bool | is_menu () const |
Checks if this command is a menu command (has subcommands). | |
void | usage () const |
Prints the command's help message. | |
CliFlag * | find_short (char name) |
Finds a flag by its short name. | |
CliFlag * | find_long (string name) |
Finds a flag by its long name. | |
void | handle_help () |
Prints the help message if the --help flag is set. | |
int | run (int argc, string argv[]) |
Runs the command with the given arguments. | |
void | set_description (const string &desc) |
Set the description of the command. | |
void | set_default_command (CliCommandFunc f) |
Sets the function to be called this command is executed without a subcommand. | |
CliCommand & | add_command (CliCommand command) |
CliCommand & | add_command (const string &name, string description, CliCommandFunc func) |
Adds a subcommand with a command function to this command. Returns a reference to the new command. | |
CliCommand & | add_command (const string &name, string description) |
Adds a subcommand to this command. Returns a reference to the new command. | |
CliCommand & | add_command (const string &name, CliCommandFunc func) |
CliCommand & | add_command (const string &name) |
Adds a subcommand without a description to this command. Returns a reference to the new command. | |
CliCommand & | add_flag (const CliFlag &arg) |
Adds a flag argument to this command. | |
CliCommand & | add_flag (char short_name, CliFlagType type, string description="") |
Adds a short flag argument to this command. | |
CliCommand & | add_flag (const string &long_name, CliFlagType type, string description="") |
Adds a long flag argument to this command. | |
CliCommand & | add_flag (char short_name, const string &long_name, CliFlagType type, string description="") |
Adds a short and long flag argument to this command. | |
CliCommand & | add_flag (const string &long_name, char short_name, CliFlagType type, string description="") |
Adds a short and long flag argument to this command. | |
CliCommand | alias (const string &name, const string &description="") |
Creates a command which is an alias for this command. | |
Public Attributes | |
vector< string > | path |
Path to the command, e.g. {"./bob", "test", "run"}. | |
vector< string > | args |
Arguments that are not flags. | |
string | name |
The name of the command. | |
CliCommandFunc | func |
The function that will be called when this command is executed. | |
string | description |
Description of the command, e.g. "Run tests". | |
vector< CliFlag > | flags |
The flags provided to this command. | |
vector< CliCommand > | commands |
Subcommands of this command. | |
CliCommand & bob::CliCommand::add_command | ( | CliCommand | command | ) |
Adds a subcommand to this command. Returns a reference to the new command.
CliCommand & bob::CliCommand::add_command | ( | const string & | name, |
CliCommandFunc | func | ||
) |
Adds a subcommand with a command function and without a description to this command. Returns a reference to the new command.