From 65500761a632d22057d3b3e709b91dde168e125b Mon Sep 17 00:00:00 2001 From: frosty Date: Sat, 3 Oct 2026 13:30:21 -0400 Subject: feat: add --exclude/--include --- src/Cli/Cli.c | 34 ++++++++++++++++++++++++++++++++++ src/Cli/Cli.h | 3 +++ 2 files changed, 37 insertions(+) (limited to 'src/Cli') 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); diff --git a/src/Cli/Cli.h b/src/Cli/Cli.h index 9695fd4..e574c88 100644 --- a/src/Cli/Cli.h +++ b/src/Cli/Cli.h @@ -2,6 +2,7 @@ #define YAPSSG_CLI_H #include "Logger/Logger.h" +#include "Pattern/Pattern.h" typedef enum { INPUT_TYPE_NONE, @@ -22,9 +23,11 @@ typedef struct { const char *output_path; int overwrite_output; LogLevel log_level; + PatternList patterns; } CliOptions; CliParseResult cli_parse(int argc, char **argv, CliOptions *options); +void cli_free_options(CliOptions *options); void cli_print_usage(const char *program_name); #endif -- cgit v1.3