* @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
| 1529 | * |
| 1530 | * @note If any of the parameters are invalid, the function logs an error and does not add the group. |
| 1531 | */ |
| 1532 | void 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"); |
nothing calls this directly
no outgoing calls
no test coverage detected