From 0916aeb150381cb6cde9fc03a3ece0dca9848d5e Mon Sep 17 00:00:00 2001 From: Anna Antonenko Date: Tue, 24 Dec 2024 14:19:55 +0400 Subject: [PATCH] pvs and unit tests fixups --- applications/services/cli/cli.c | 29 +++++++++------------- applications/services/cli/cli.h | 40 ------------------------------- applications/services/cli/cli_i.h | 12 +++++++++- 3 files changed, 22 insertions(+), 59 deletions(-) diff --git a/applications/services/cli/cli.c b/applications/services/cli/cli.c index fdbf631a820..a344eb2ea9f 100644 --- a/applications/services/cli/cli.c +++ b/applications/services/cli/cli.c @@ -22,31 +22,24 @@ void cli_add_command( CliCommandFlag flags, CliExecuteCallback callback, void* context) { - // missing checks performed by cli_add_command_ex + furi_check(cli); + furi_check(name); + furi_check(callback); - CliCommand cmd = { + FuriString* name_str; + name_str = furi_string_alloc_set(name); + // command cannot contain spaces + furi_check(furi_string_search_char(name_str, ' ') == FURI_STRING_FAILURE); + + CliCommand command = { .name = name, .context = context, .execute_callback = callback, - .complete_callback = NULL, .flags = flags, }; - cli_add_command_ex(cli, &cmd); -} - -void cli_add_command_ex(Cli* cli, CliCommand* command) { - furi_check(cli); - furi_check(command); - furi_check(command->name); - furi_check(command->execute_callback); - - FuriString* name_str; - name_str = furi_string_alloc_set(command->name); - // command cannot contain spaces - furi_check(furi_string_search_char(name_str, ' ') == FURI_STRING_FAILURE); furi_check(furi_mutex_acquire(cli->mutex, FuriWaitForever) == FuriStatusOk); - CliCommandTree_set_at(cli->commands, name_str, *command); + CliCommandTree_set_at(cli->commands, name_str, command); furi_check(furi_mutex_release(cli->mutex) == FuriStatusOk); furi_string_free(name_str); @@ -75,7 +68,7 @@ bool cli_get_command(Cli* cli, FuriString* command, CliCommand* result) { furi_check(furi_mutex_acquire(cli->mutex, FuriWaitForever) == FuriStatusOk); CliCommand* data = CliCommandTree_get(cli->commands, command); if(data) *result = *data; - + furi_check(furi_mutex_release(cli->mutex) == FuriStatusOk); return !!data; diff --git a/applications/services/cli/cli.h b/applications/services/cli/cli.h index 56490fada60..166194181f5 100644 --- a/applications/services/cli/cli.h +++ b/applications/services/cli/cli.h @@ -60,46 +60,6 @@ void cli_add_command( CliExecuteCallback callback, void* context); -ARRAY_DEF(CommandCompletions, FuriString*, FURI_STRING_OPLIST); // -V524 -#define M_OPL_CommandCompletions_t() ARRAY_OPLIST(CommandCompletions) - -/** - * @brief Command autocomplete callback. - * - * This callback will be called from the shell thread. - * - * @param [in] partial_args Input after the name of the command up to the point - * where TAB was pressed. - * @param [out] full_args An initialized empty array that you fill up with - * suggestions for the entire `args`. - */ -typedef void (*CliCompleteCallback)( - PipeSide* pipe, - FuriString* partial_args, - CommandCompletions_t full_args, - void* context); - -/** - * @brief Extended command descriptor for `cli_add_command_ex` - */ -typedef struct { - const char* name; //