RTU_ALL_AI/docs/public/libcmd/API-libcmd.md

27 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# API-libcmd — 命令处理框架
> 命令注册/分发/补全,内置 linenoise 行编辑,供 libdatacenter 等模块调试使用。
## 接口
| 函数/宏 | 说明 |
|---------|------|
| `cmd_manager_add_command(name, func, desc, complete)` | 注册命令 |
| `cmd_manager_get_commands(out_count)` | 获取所有已注册命令列表 |
| `cmd_help(argc, argv)` | 打印帮助信息 |
| `cmd_find(name)` | 按名称查找命令 |
| `cmd_complete(buf, completions, ncomp)` | Tab 自动补全回调 |
| `cmd_sub_complete(buf, completions, ncomp, subs, sub_count)` | 子命令补全 |
| `linenoise(prompt)` | 行编辑+历史交互式输入 |
| `linenoiseFree(ptr)` | 释放 linenoise 返回的内存 |
| `linenoiseHistoryAdd(line)` | 添加历史记录 |
| `linenoiseHistoryFree()` | 释放历史 |
| `lineniseSetCompletionCallback(cb)` | 设置自动补全回调 |
| `CMD_REGISTER(name, func, desc)` | 注册命令宏(无补全) |
| `CMD_REGISTER_C(name, func, desc, complete)` | 注册命令宏(带补全) |
## 依赖
- `myBase.h`
- 无外部依赖linenoise 内置实现)