MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / cli_register_command_alias

Function cli_register_command_alias

cli/cli.c:1531–1558  ·  view source on GitHub ↗

* @brief Registers an alias for an existing command in the CLI parser. * * This function allows you to define an alternative name (alias) for an existing * command in the CLI parser. The alias will behave exactly like the original command. * * @param parser A pointer to the `CliParser` instance. Must not be NULL. * @param commandName The name of the existing command to alias. Must not be NUL

Source from the content-addressed store, hash-verified

1529 *
1530 * @note If any of the parameters are invalid, the function logs an error and does not add the group.
1531 */
1532void cli_add_option_group(CliParser *parser, const char *groupName, const CliOption *options, size_t numOptions) {
1533 if (parser == NULL || groupName == NULL || options == NULL || numOptions == 0) {
1534 snprintf(cli_last_error.message, sizeof(cli_last_error.message), "Invalid arguments provided.\n");
1535 cli_last_error.code = CLI_ERROR_INVALID_ARGUMENT;
1536
1537 CLI_LOG("[cli_add_option_group] %s", cli_last_error.message);
1538 return;
1539 }
1540
1541 // Track the group itself so cli_remove_option_group can find it later.
1542 CliOptionGroup *newGroups = (CliOptionGroup*)realloc(parser->optionGroups, sizeof(CliOptionGroup) * (parser->numOptionGroups + 1));
1543 if (!newGroups) {
1544 snprintf(cli_last_error.message, sizeof(cli_last_error.message),"Memory allocation failed in cli_add_option_group.\n");
1545 cli_last_error.code = CLI_ERROR_ALLOCATION_FAILED;
1546
1547 CLI_LOG("[cli_add_option_group] %s", cli_last_error.message);
1548 return;
1549 }
1550 parser->optionGroups = newGroups;
1551
1552 CliOptionGroup g;
1553 g.groupName = string_strdup(groupName);
1554 g.numOptions = numOptions;
1555 g.options = (CliOption*)malloc(sizeof(CliOption) * numOptions);
1556 g.registered = (unsigned char*)calloc(numOptions, 1);
1557 if (!g.groupName || !g.options || !g.registered) {
1558 free((void*)g.groupName);
1559 free(g.options);
1560 free(g.registered);
1561 snprintf(cli_last_error.message, sizeof(cli_last_error.message),"Memory allocation failed in cli_add_option_group.\n");

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected