aboutsummaryrefslogtreecommitdiff
path: root/src/Cli/Cli.c
diff options
context:
space:
mode:
authorfrosty <frostinator33@airmail.cc>2026-10-03 13:30:21 -0400
committerfrosty <frostinator33@airmail.cc>2026-10-03 13:30:21 -0400
commit65500761a632d22057d3b3e709b91dde168e125b (patch)
tree0ff30abf8de4120e5ed8db296688e0d85b65736b /src/Cli/Cli.c
parentcb716af752fb0b46aa8f78d3cbd5189a09642f39 (diff)
feat: add --exclude/--include
Diffstat (limited to 'src/Cli/Cli.c')
-rw-r--r--src/Cli/Cli.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Cli/Cli.c b/src/Cli/Cli.c
index 3648493..c7569da 100644
--- a/src/Cli/Cli.c
+++ b/src/Cli/Cli.c
@@ -16,6 +16,8 @@ void cli_print_usage(const char *program_name) {
" -d, --directory DIRECTORY Process a directory recursively\n"
" -o, --output OUTPUT Set the output path\n"
" -f, --overwrite Overwrite an existing output directory\n"
+ " --include PATTERN Keep entries matching PATTERN\n"
+ " --exclude PATTERN Drop entries matching PATTERN\n"
" -l, --log-level LEVEL error, warning, info, debug, or silent\n"
" -v, --version Show the program version\n"
" -h, --help Show this help\n",
@@ -28,12 +30,29 @@ static const char *strip_optional_equals(const char *value) {
return value != NULL && value[0] == '=' ? value + 1 : value;
}
+static CliParseResult append_pattern(CliOptions *options, PatternKind kind,
+ const char *value, const char *name) {
+ const char *pattern = strip_optional_equals(value);
+
+ if (pattern_list_append(&options->patterns, kind, pattern) != 0) {
+ logger_error("invalid %s pattern '%s'", name, pattern);
+ return CLI_PARSE_ERROR;
+ }
+ return CLI_PARSE_OK;
+}
+
+void cli_free_options(CliOptions *options) {
+ pattern_list_clear(&options->patterns);
+}
+
CliParseResult cli_parse(int argc, char **argv, CliOptions *options) {
static const struct option long_options[] = {
{"directory", required_argument, NULL, 'd'},
{"output", required_argument, NULL, 'o'},
{"overwrite", no_argument, NULL, 'f'},
{"force", no_argument, NULL, 'f'},
+ {"include", required_argument, NULL, 1},
+ {"exclude", required_argument, NULL, 2},
{"log-level", required_argument, NULL, 'l'},
{"version", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
@@ -46,6 +65,9 @@ CliParseResult cli_parse(int argc, char **argv, CliOptions *options) {
options->output_path = NULL;
options->overwrite_output = 0;
options->log_level = LOG_LEVEL_INFO;
+ options->patterns.items = NULL;
+ options->patterns.length = 0;
+ options->patterns.capacity = 0;
while ((option = getopt_long(argc, argv, "d:o:fl:vh", long_options, NULL)) !=
-1) {
@@ -59,6 +81,18 @@ CliParseResult cli_parse(int argc, char **argv, CliOptions *options) {
case 'f':
options->overwrite_output = 1;
break;
+ case 1:
+ if (append_pattern(options, PATTERN_INCLUDE, optarg, "include") !=
+ CLI_PARSE_OK) {
+ return CLI_PARSE_ERROR;
+ }
+ break;
+ case 2:
+ if (append_pattern(options, PATTERN_EXCLUDE, optarg, "exclude") !=
+ CLI_PARSE_OK) {
+ return CLI_PARSE_ERROR;
+ }
+ break;
case 'l':
if (logger_parse_level(optarg, &options->log_level) != 0) {
logger_error("unknown log level '%s'", optarg);