1
0
mirror of https://github.com/NevermindZZT/letter-shell.git synced 2025-01-21 10:02:54 +08:00

84 lines
2.3 KiB
C
Raw Normal View History

2020-10-18 16:00:55 +08:00
/**
* @file shell_cmd_group.h
* @author Letter(nevermindzzt@gmail.com)
* @brief shell command group support
* @version 0.1
* @date 2020-10-18
*
* @copyright (c) 2020 Letter
*
*/
#include "shell.h"
/**
* @brief shell
*/
#define SHELL_CMD_GROUP_FUNC_NAME(_group) agency##_group
/**
* @brief shell命令组函数定义
*
* @param _group
*/
#define SHELL_CMD_GROUP_FUNC(_group) \
void SHELL_CMD_GROUP_FUNC_NAME(_group)(int p1, int p2) \
2021-11-04 10:01:48 +08:00
{ shellCmdGroupRun(_group, p1, (char **)p2); }
2020-10-18 16:00:55 +08:00
/**
* @brief shell
*
* @param _attr
* @param _name
* @param _group
* @param _desc
*/
#define SHELL_EXPORT_CMD_GROUP(_attr, _name, _group, _desc) \
SHELL_CMD_GROUP_FUNC(_group) \
SHELL_EXPORT_CMD(_attr, _name, SHELL_CMD_GROUP_FUNC_NAME(_group), _desc)
/**
* @brief shell item定义
*
* @param _type (SHELL_TYPE_CMD_MAIN or SHELL_TYPE_CMD_FUNC)
* @param _func
* @param _desc
2024-06-13 22:40:10 +08:00
* @param ...
2020-10-18 16:00:55 +08:00
*/
2024-06-13 22:40:10 +08:00
#define SHELL_CMD_GROUP_ITEM(_type, _name, _func, _desc, ...) \
2020-10-18 16:00:55 +08:00
{ \
.attr.value = SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(_type), \
2020-10-18 16:00:55 +08:00
.data.cmd.name = #_name, \
.data.cmd.function = (int (*)())_func, \
2024-06-13 22:40:10 +08:00
.data.cmd.desc = #_desc, \
##__VA_ARGS__ \
2020-10-18 16:00:55 +08:00
}
2024-06-13 22:40:10 +08:00
#if SHELL_USING_FUNC_SIGNATURE == 1
/**
* @brief shell item定义
*
* @param _type (SHELL_TYPE_CMD_MAIN or SHELL_TYPE_CMD_FUNC)
* @param _func
* @param _desc
* @param _sign
*/
#define SHELL_CMD_GROUP_ITEM_SIGN(_type, _name, _func, _desc, _sign) \
{ \
.attr.value = SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(_type)|SHELL_CMD_DISABLE_RETURN, \
.data.cmd.name = #_name, \
.data.cmd.function = (int (*)())_func, \
.data.cmd.desc = #_desc, \
.data.cmd.signature = #_sign, \
}
#endif
2020-10-18 16:00:55 +08:00
/**
* @brief shell
*
* @note
*/
#define SHELL_CMD_GROUP_END() {.data.cmd.name = NULL}
2020-10-18 16:00:55 +08:00
2021-11-04 10:01:48 +08:00
int shellCmdGroupRun(ShellCommand *group, int argc, char *argv[]);