CLI

Method
Description
cli
Default constructor.
set_category
Sets the current category.
insert_command
Inserts a command.
insert_read_command
Inserts a read command.
insert_write_command
Inserts a write command.
run
Runs the shell.
template<class ...S>
class cli

CLI main class.

The stores of a CLI are passed as type arguments to cli. For example, if the CLI has stores for Graphs and Trees which are handled by classes graph and tree, respectively, the class instantiation is cli<graph, tree>.

Public Functions

cli(const std::string &prefix)

Default constructor.

Initializes the CLI with a prefix that is used as a command prefix in stand-alone application mode and as a module name when build as Python module.

The constructor will add the default commands to the CLI. If no store type is specified, then no store-related command will be added.

Parameters
  • prefix: Either command prefix or module name (depending on build mode)

void set_category(const std::string &_category)

Sets the current category.

This category will be used as category for all commands that are added afterwards, until this method is called again with a different argument.

The categories are used in the help command to organize the commands.

The macros :c:macro:ALICE_COMMAND and :c:macro:ALICE_ADD_COMMAND will automatically call this method.

Parameters
  • _category: Category name

void insert_command(const std::string &name, const std::shared_ptr<command> &cmd)

Inserts a command.

Inserts a command (as a shared pointer) to the CLI.

The macro :c:macro:ALICE_ADD_COMMAND will automatically call this method with a convention that a command with name <name> must be called <name>_command.

Parameters
  • name: Name of the command
  • cmd: Shared pointer to a command instance

template<typename Tag>
void insert_read_command(const std::string &name, const std::string &label)

Inserts a read command.

Inserts a read command for a given file tag. The name of the command can be arbitrary but the default convention is to prefix it with read_. The macro :c:macro:ALICE_ADD_FILE_TYPE together :c:macro:ALICE_READ_FILE will automatically add a read command called read_<tagname>.

Parameters
  • name: Name of the command
  • label: Label for the file type (used in help string)

template<typename Tag>
void insert_write_command(const std::string &name, const std::string &label)

Inserts a write command.

Inserts a writ command for a given file tag. The name of the command can be arbitrary but the default convention is to prefix it with write_. The macro :c:macro:ALICE_ADD_FILE_TYPE together :c:macro:ALICE_WRITE_FILE will automatically add a write command called write_<tagname>.

Parameters
  • name: Name of the command
  • label: Label for the file type (used in help string)

int run(int argc, char **argv)

Runs the shell.

This function is only used if the CLI is used in stand-alone mode, not when used as Python module. The values argc and argv can be taken from the main function. For some flags, such as -f and -c, the CLI will read commands from a file or the command line, respectively, and then stop (unless flag -i is set). Otherwise, the CLI will enter a loop that accepts commands as user inputer.

Parameters
  • argc: Number of arguments (incl. program name, like argc in main)
  • argv: Argument values (like argv in main)