feat(console): add command user context support

Current implementation implicitly forces the developer to use global variables
to enter its context during the command invocation, this change enables each
module to register a context for command to find without the need to manage
global variables.

No API breakage.

Fields added:
   esp_console_cmd_t::func_w_context    - (*)(int argc, char **argv, void *context)

Functions added:
   esp_err_t esp_console_cmd_set_context(const char *cmd, void *context)

Usage:

   esp_console_cmd_register(&cmd));
   esp_console_cmd_set_context(cmd.command, (void *)"context"));

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
This commit is contained in:
Alon Bar-Lev
2023-10-20 20:48:52 +03:00
committed by Jakob Hasse
parent 142218c2eb
commit bccb2873bd
5 changed files with 196 additions and 6 deletions
+6 -1
View File
@@ -147,7 +147,12 @@ Linenoise 库不需要显式地初始化,但是在调用行编辑函数之前
- 命令名字(不含空格的字符串)
- 帮助文档,解释该命令的用途
- 可选的提示文本,列出命令的参数。如果应用程序使用 ``Argtable3`` 库来解析参数,则可以通过提供指向 argtable 参数定义结构体的指针来自动生成提示文本
- 命令处理函数
- 命令处理函数(无上下文),或
- 命令处理函数(有上下文)。如要使用此函数,则必须在调用其他命令 **之前** 调用 :cpp:func:`esp_console_cmd_set_context` 初始化上下文。
.. note::
使用接受上下文的命令处理函数或者不接受上下文的命令处理函数均可,但两者不能同时使用。如果使用接受上下文的命令处理程序函数,则必须调用 :cpp:func:`esp_console_cmd_set_context` 初始化上下文,否则该函数可能会访问未初始化的上下文。
命令注册模块还提供了其它函数: