Blender V4.3
blender_cli_command.cc File Reference
#include <iostream>
#include "BLI_vector.hh"
#include "BKE_blender_cli_command.hh"
#include "MEM_guardedalloc.h"

Go to the source code of this file.

Functions

Public API
void BKE_blender_cli_command_register (std::unique_ptr< CommandHandler > cmd)
 
bool BKE_blender_cli_command_unregister (CommandHandler *cmd)
 
int BKE_blender_cli_command_exec (bContext *C, const char *id, const int argc, const char **argv)
 
void BKE_blender_cli_command_print_help ()
 
void BKE_blender_cli_command_free_all ()
 

Internal API

using CommandHandlerPtr = std::unique_ptr<CommandHandler>
 
blender::Vector< CommandHandlerPtrg_command_handlers
 
static CommandHandlerblender_cli_command_lookup (const std::string &id)
 
static int blender_cli_command_index (const CommandHandler *cmd)
 

Detailed Description

Generic CLI "--command" declarations.

Duplicate Commands

When two or more commands share the same identifier, a warning is printed and both are disabled.

This is done because command-line actions may be destructive so the down-side of running the wrong command could be severe. The reason this is not considered an error is we can't prevent it so easily, unlike operator ID's which may be longer, commands are typically short terms which wont necessarily include an add-ons identifier as a prefix for e.g. Further, an error would break loading add-ons who's primary is not necessarily to provide command-line access. An alternative solution could be to generate unique names (number them for example) but this isn't reliable as it would depend on it the order add-ons are loaded which isn't under user control.

Definition in file blender_cli_command.cc.

Typedef Documentation

◆ CommandHandlerPtr

using CommandHandlerPtr = std::unique_ptr<CommandHandler>

Definition at line 38 of file blender_cli_command.cc.

Function Documentation

◆ BKE_blender_cli_command_exec()

int BKE_blender_cli_command_exec ( struct bContext * C,
const char * id,
const int argc,
const char ** argv )

Run the command by id, passing in the argument list & context. The argument list must begin after the command identifier.

Definition at line 122 of file blender_cli_command.cc.

References blender_cli_command_lookup(), CommandHandler::exec(), and CommandHandler::is_duplicate.

Referenced by arg_handle_command_set().

◆ BKE_blender_cli_command_free_all()

void BKE_blender_cli_command_free_all ( )

Frees all commands (using their #CommandFreeFn call-backs).

Definition at line 176 of file blender_cli_command.cc.

References g_command_handlers.

Referenced by WM_exit_ex().

◆ BKE_blender_cli_command_print_help()

void BKE_blender_cli_command_print_help ( )

Print all known commands (used for passing --command help in the command-line).

Definition at line 138 of file blender_cli_command.cc.

References b, and g_command_handlers.

Referenced by arg_handle_command_set().

◆ BKE_blender_cli_command_register()

void BKE_blender_cli_command_register ( std::unique_ptr< CommandHandler > cmd)
Parameters
cmdThe memory for a command type (ownership is transferred).

Definition at line 74 of file blender_cli_command.cc.

References blender_cli_command_lookup(), and g_command_handlers.

Referenced by bpy_cli_command_register().

◆ BKE_blender_cli_command_unregister()

bool BKE_blender_cli_command_unregister ( CommandHandler * cmd)

Unregister a previously registered command.

Definition at line 87 of file blender_cli_command.cc.

References blender_cli_command_index(), g_command_handlers, CommandHandler::id, and CommandHandler::is_duplicate.

Referenced by bpy_cli_command_unregister().

◆ blender_cli_command_index()

static int blender_cli_command_index ( const CommandHandler * cmd)
static

Definition at line 56 of file blender_cli_command.cc.

References g_command_handlers.

Referenced by BKE_blender_cli_command_unregister().

◆ blender_cli_command_lookup()

static CommandHandler * blender_cli_command_lookup ( const std::string & id)
static

Variable Documentation

◆ g_command_handlers

blender::Vector<CommandHandlerPtr> g_command_handlers

All registered command handlers.

Note
the order doesn't matter as duplicates are detected and prevented from running.

Definition at line 44 of file blender_cli_command.cc.

Referenced by BKE_blender_cli_command_free_all(), BKE_blender_cli_command_print_help(), BKE_blender_cli_command_register(), BKE_blender_cli_command_unregister(), blender_cli_command_index(), and blender_cli_command_lookup().