From 0d3e045b34f38d23e6160ce8aae363f358bd5cdc Mon Sep 17 00:00:00 2001 From: René Scharfe Date: Wed, 9 Jul 2025 11:45:14 +0200 Subject: parse-options: add precision handling for PARSE_OPT_CMDMODE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Build on 09705696f7 (parse-options: introduce precision handling for `OPTION_INTEGER`, 2025-04-17) to support value variables of different sizes for PARSE_OPT_CMDMODE options. Do that by requiring their "precision" to be set and casting their "value" pointer accordingly. Call the function that does the raw casting do_get_int_value() to reserve the name get_int_value() for a more friendly wrapper we're going to introduce in one of the next patches. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- t/helper/test-parse-options.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 't/helper/test-parse-options.c') diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c index f2663dd0c0..1e03ff88f6 100644 --- a/t/helper/test-parse-options.c +++ b/t/helper/test-parse-options.c @@ -148,9 +148,16 @@ int cmd__parse_options(int argc, const char **argv) OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23), OPT_CMDMODE(0, "mode1", &integer, "set integer to 1 (cmdmode option)", 1), OPT_CMDMODE(0, "mode2", &integer, "set integer to 2 (cmdmode option)", 2), - OPT_CALLBACK_F(0, "mode34", &integer, "(3|4)", - "set integer to 3 or 4 (cmdmode option)", - PARSE_OPT_CMDMODE, mode34_callback), + { + .type = OPTION_CALLBACK, + .long_name = "mode34", + .value = &integer, + .precision = sizeof(integer), + .argh = "(3|4)", + .help = "set integer to 3 or 4 (cmdmode option)", + .flags = PARSE_OPT_CMDMODE, + .callback = mode34_callback, + }, OPT_CALLBACK('L', "length", &integer, "str", "get length of ", length_callback), OPT_FILENAME('F', "file", &file, "set file to "), -- cgit v1.2.3