# ccmd **Repository Path**: fishmwei/ccmd ## Basic Information - **Project Name**: ccmd - **Description**: 使用C语言编写的一个命令行框架 - **Primary Language**: C - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-06-04 - **Last Updated**: 2022-10-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ccmd #### 介绍 使用C语言编写的一个命令行框架 #### 软件架构 软件架构说明 #### 安装教程 ```shell cd /path/to/root/of/project mkdir build && cd build cmake .. make && make install ``` #### 使用说明 接口说明: ```c /** *@ Description: 设置ccmd的调试信息输出函数 *@ cb: [in] 调试信息输出函数 *@ return void */ void set_cmd_log_printer(cmd_log_printer cb); /** *@ Description: 解析命令行参数 *@ options: [in, out] 选项解析结果 *@ argc: [in] 选项个数 *@ argv: 选项数组 *@ return void */ int cmd_parse(void *results, const int argc, const char **argv); /** *@ Description: 增加一个选项配置,必须在调用cmd_parse之前注册才生效 *@ cfg: [in] 选项配置 *@ opt: [in] 选项关联的opt配置 *@ return 0:成功 非0:失败 */ int add_cmd_opt(cmd_opt_cfg *cfg, struct option *opt_cfg); /** *@ Description: 根据选项配置,显示帮助信息到stdout *@ return void */ void usage(void); ``` 示例参考 (example/example.c) ```c void main(const int argc, const char **argv) { //set_cmd_log_printer(cmd_log); opts_register(); struct result command_results={0}; int ret = cmd_parse((void *)&command_results, argc, argv); if (0 != ret) { return; } printf("get student info:\r\n"); printf(" name : %s\r\n", command_results.name); printf(" address: %s\r\n", command_results.address); printf(" age : %d\r\n", command_results.age); printf(" fresh : %s\r\n", command_results.fresh?"true":"false"); return; } ``` ```shell cd example mkdir build && cd build cmake .. make root@keep-VirtualBox:/media/sf_VM_SHARE/ccmd/example/build# ./ccmd_test --help Usage ./ccmd_test [options] ... Options: --help: prints this help --name: specify student name --address: specify student home address --age: specify student age --fresh: is fresh graduate root@keep-VirtualBox:/media/sf_VM_SHARE/ccmd/example/build# ./ccmd_test --name xiaoming --address Fuzhou,Fujian --age 18 --fresh get student info: name : xiaoming address: Fuzhou,Fujian age : 18 fresh : true ``` #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)