From 08793aa1435ac3b1a5bb425d1bd4660253aea6b5 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 16 Jan 2024 11:20:50 +1100 Subject: [PATCH] Make ... optional in .args (#1086) --- test/tool/args/args_test.c | 14 +++++++++----- tool/args/args.c | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/test/tool/args/args_test.c b/test/tool/args/args_test.c index 9d46a624d..4ddcd3088 100644 --- a/test/tool/args/args_test.c +++ b/test/tool/args/args_test.c @@ -64,20 +64,24 @@ world\r\n\ EXPECT_EQ(NULL, __argv[5]); } -TEST(LoadZipArgs, testDefaultArgs_hasCliArgs_doesNothing) { +TEST(LoadZipArgs, testDefaultArgs_hasCliArgs_impliedMergeThem) { int argc = 2; char *args[] = {"prog", "yo", 0}; char **argv = &args[0]; EXPECT_EQ(0, LoadZipArgsImpl(&argc, &argv, strdup("\ -x\r\n\ -hello\r\n\ +hello o\r\n\ -y\r\n\ world\r\n\ "))); - ASSERT_EQ(2, argc); + ASSERT_EQ(6, argc); EXPECT_STREQ("prog", argv[0]); - EXPECT_STREQ("yo", argv[1]); - EXPECT_EQ(NULL, argv[2]); + EXPECT_STREQ("-x", argv[1]); + EXPECT_STREQ("hello o", argv[2]); + EXPECT_STREQ("-y", argv[3]); + EXPECT_STREQ("world", argv[4]); + EXPECT_STREQ("yo", argv[5]); + EXPECT_EQ(NULL, argv[6]); } TEST(LoadZipArgs, testDots_hasCliArgs_mergesThem) { diff --git a/tool/args/args.c b/tool/args/args.c index d99ed8c26..0d7a298de 100644 --- a/tool/args/args.c +++ b/tool/args/args.c @@ -91,6 +91,15 @@ int LoadZipArgsImpl(int *argc, char ***argv, char *data) { } start = 0; } + + if (!founddots) + { + founddots = true; + for (i = 1; i < *argc; ++i) { + AddZipArg(&n, &args, (*argv)[i]); + } + } + if (founddots || *argc <= 1) { if (!g_zipargs.initialized) { atexit(FreeZipArgs); @@ -118,8 +127,9 @@ int LoadZipArgsImpl(int *argc, char ***argv, char *data) { * * Your `.args` file should have one argument per line. * - * If the special argument `...` is *not* encountered, then the - * replacement will only happen if *no* CLI args are specified. + * If the special argument `...` is *not* encountered, then it would be assumed + * that the developer intent is for whatever CLI args were specified by the user + * to be appended to the end * * If the special argument `...` *is* encountered, then it'll be * replaced with whatever CLI args were specified by the user.