feat: v0.2.0

This commit is contained in:
2025-07-14 16:12:38 +08:00
commit 0e42917578
23 changed files with 2583 additions and 0 deletions

5
examples/CMakeLists.txt Normal file
View File

@@ -0,0 +1,5 @@
project(example)
add_executable(example simple.c)
target_link_libraries(example CArgParse)

41
examples/simple.c Normal file
View File

@@ -0,0 +1,41 @@
#include "ArgParse.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
ArgParse *Init() {
ArgParse *ap = argParseInit("简单的命令行工具示例");
// 添加第一个命令
Command *cmd = argParseAddCommand(
ap, "list", "列出文件列表", NULL, NULL, NULL, SINGLEVALUE);
// 添加第一个命令的参数
argParseAddArg(cmd,
"-a",
"--all",
"列出所有文件包括隐藏文件",
NULL,
NULL,
false,
NOVALUE);
return ap;
}
int main(int argc, char *argv[]) {
ArgParse *ap = Init();
argParseParse(ap, argc, argv);
char *dir = argParseGetCurCommandValue(ap);
if (dir != NULL) {
printf("列出目录: %s 的文件列表\n", dir);
}
if (argParseCheckCurArgTriggered(ap, "-a")) {
printf("触发了 -a 参数,列出所有文件\n");
}
argParseFree(ap);
return 0;
}