bob.hpp
Loading...
Searching...
No Matches
bob::Cli Class Reference

A command line interface (CLI) that can be used to run commands and subcommands. More...

#include <bob.hpp>

Inheritance diagram for bob::Cli:
bob::CliCommand

Public Member Functions

 Cli (int argc, char *argv[])
 Create a new CLI interface.
 
 Cli (string title, int argc, char *argv[])
 Create a new CLI interface with a title.
 
int serve ()
 Run the CLI and handle the commands.
 
- Public Member Functions inherited from bob::CliCommand
 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.
 
CliFlagfind_short (char name)
 Finds a flag by its short name.
 
CliFlagfind_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.
 
CliCommandadd_command (CliCommand command)
 
CliCommandadd_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.
 
CliCommandadd_command (const string &name, string description)
 Adds a subcommand to this command. Returns a reference to the new command.
 
CliCommandadd_command (const string &name, CliCommandFunc func)
 
CliCommandadd_command (const string &name)
 Adds a subcommand without a description to this command. Returns a reference to the new command.
 
CliCommandadd_flag (const CliFlag &arg)
 Adds a flag argument to this command.
 
CliCommandadd_flag (char short_name, CliFlagType type, string description="")
 Adds a short flag argument to this command.
 
CliCommandadd_flag (const string &long_name, CliFlagType type, string description="")
 Adds a long flag argument to this command.
 
CliCommandadd_flag (char short_name, const string &long_name, CliFlagType type, string description="")
 Adds a short and long flag argument to this command.
 
CliCommandadd_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.
 

Additional Inherited Members

- Public Attributes inherited from bob::CliCommand
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< CliFlagflags
 The flags provided to this command.
 
vector< CliCommandcommands
 Subcommands of this command.
 

Detailed Description

A command line interface (CLI) that can be used to run commands and subcommands.

Examples
cli/bob.cpp.

The documentation for this class was generated from the following file: