Files
args.h/test/main.cpp
2025-10-20 13:24:18 +02:00

52 lines
1.7 KiB
C++

#define ARGS_IMPLEMENTATION
#include "../args.h"
#include <stdio.h>
void args_add_bool(args_t *args, const char *name, const char *alt_name, const char *help) {
args_desc_t desc = {name, alt_name};
desc.help = help;
desc.store_value = "1";
desc.default_value = "0";
args_add(args, desc);
}
void args_add_nargs(args_t *args, const char *name, const char *alt_name, const char *nargs, const char *help) {
args_desc_t desc = {name, alt_name};
desc.nargs = nargs;
desc.help = help;
args_add(args, desc);
}
int main(int argc, char **argv) {
args_t args = {
.program = argv[0],
.description = (char *)"this program does very cool things on many files and outputs it somewhere",
.epilogue = (char *)"it also shows cool epilogue text in it's help",
};
args_add_nargs(&args, "filenames", NULL, "+", "list of filenames to process");
args_add_nargs(&args, "--output", "-o", "?", "path to the folder where output will be gathered");
args_add_bool(&args, "--force", "-f", "force the processing");
args_add_bool(&args, "--recursive", "-r", "apply recursively to files in current directory");
args_add_bool(&args, "--help", "-h", "show this help window");
args_parse(&args, argc, argv);
const char **filenames = args_get(&args, "filenames");
const char **output = args_get(&args, "--output");
int force = atoi(args_get(&args, "-f")[0]);
int recursive = atoi(args_get(&args, "--recursive")[0]);
int help = atoi(args_get(&args, "--help")[0]);
for (int i = 0; filenames[i]; i += 1) {
//
}
if (help) {
args_print_help(&args);
return 0;
}
// ..
(void)filenames; (void)output; (void)force; (void)recursive;
args_free(&args);
}