diff --git a/src/client/client_cli.c b/src/client/client_cli.c index 0de3a4f..8179c52 100644 --- a/src/client/client_cli.c +++ b/src/client/client_cli.c @@ -187,7 +187,8 @@ static const OptionEntry* find_table_option(const char* arg) { return NULL; } -static int apply_table_option(Config* config, const OptionEntry* entry, const char* value) { +static int apply_table_option(Config* config, const OptionEntry* entry, const char* option_name, + const char* value) { void* field = (char*)config + entry->offset; switch (entry->kind) { case OPT_FLAG: @@ -208,8 +209,8 @@ static int apply_table_option(Config* config, const OptionEntry* entry, const ch } case OPT_UNSUPPORTED: log_message(LOG_LEVEL_ERROR, - "%s requires --dirs, which is not implemented; refusing to ignore option", - entry->name); + "%s: directory-only transfer is not implemented; refusing to ignore option", + option_name); return -1; } return -1; @@ -221,14 +222,17 @@ int parse_args(Config* config, int argc, char* argv[], int* positional_args, for (int i = 1; i < argc; i++) { const OptionEntry* entry = find_table_option(argv[i]); if (entry) { + const char* option_name = argv[i]; + const char* value = NULL; if (entry->kind != OPT_FLAG) { - if (i + 1 >= argc) { + if (entry->kind != OPT_UNSUPPORTED && i + 1 >= argc) { log_message(LOG_LEVEL_ERROR, "missing argument for %s", entry->name); return -1; } - if (apply_table_option(config, entry, argv[++i]) != 0) - return -1; - } else if (apply_table_option(config, entry, NULL) != 0) { + if (entry->kind != OPT_UNSUPPORTED) + value = argv[++i]; + } + if (apply_table_option(config, entry, option_name, value) != 0) { return -1; } continue; diff --git a/tests/test_client_cli.c b/tests/test_client_cli.c index d998a3e..de1bc5a 100644 --- a/tests/test_client_cli.c +++ b/tests/test_client_cli.c @@ -1,8 +1,10 @@ #include "test_client_cli.h" #include "client_validation.h" #include "config.h" +#include "log.h" #include "test_utils.h" #include "utils.h" +#include #include #include #include @@ -260,7 +262,7 @@ static void test_parse_args_unknown_option() { config_delete(cfg); } -/* Directory aliases require the not-yet-implemented --dirs behavior. */ +/* Directory aliases must report the unsupported directory-only behavior clearly. */ static void test_parse_args_rejects_dirs_aliases() { static const char* const options[] = {"--dirs", "--old-dirs", "--old-d"}; @@ -269,8 +271,21 @@ static void test_parse_args_rejects_dirs_aliases() { char* argv[] = {"fastsync", (char*)options[i], "/src", "/dst"}; int positional_args[2]; int positional_count = 0; + FILE* log_file = tmpfile(); + char log_buffer[256] = {0}; + + EXPECT_NOT_NULL(log_file); + log_set_file(log_file); EXPECT_EQ_INT(parse_args(cfg, 4, argv, positional_args, &positional_count), -1); + fflush(log_file); + rewind(log_file); + EXPECT_TRUE(fread(log_buffer, 1, sizeof(log_buffer) - 1, log_file) > 0); + EXPECT_TRUE(strstr(log_buffer, options[i]) != NULL); + EXPECT_TRUE(strstr(log_buffer, "directory-only transfer is not implemented") != NULL); + EXPECT_TRUE(strstr(log_buffer, "requires --dirs") == NULL); + log_set_file(NULL); + fclose(log_file); config_delete(cfg); } }