Make ... optional in .args (#1086)

This commit is contained in:
Brian 2024-01-16 11:20:50 +11:00 committed by GitHub
parent 6db1200a7e
commit 08793aa143
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View file

@ -64,20 +64,24 @@ world\r\n\
EXPECT_EQ(NULL, __argv[5]); EXPECT_EQ(NULL, __argv[5]);
} }
TEST(LoadZipArgs, testDefaultArgs_hasCliArgs_doesNothing) { TEST(LoadZipArgs, testDefaultArgs_hasCliArgs_impliedMergeThem) {
int argc = 2; int argc = 2;
char *args[] = {"prog", "yo", 0}; char *args[] = {"prog", "yo", 0};
char **argv = &args[0]; char **argv = &args[0];
EXPECT_EQ(0, LoadZipArgsImpl(&argc, &argv, strdup("\ EXPECT_EQ(0, LoadZipArgsImpl(&argc, &argv, strdup("\
-x\r\n\ -x\r\n\
hello\r\n\ hello o\r\n\
-y\r\n\ -y\r\n\
world\r\n\ world\r\n\
"))); ")));
ASSERT_EQ(2, argc); ASSERT_EQ(6, argc);
EXPECT_STREQ("prog", argv[0]); EXPECT_STREQ("prog", argv[0]);
EXPECT_STREQ("yo", argv[1]); EXPECT_STREQ("-x", argv[1]);
EXPECT_EQ(NULL, argv[2]); 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) { TEST(LoadZipArgs, testDots_hasCliArgs_mergesThem) {

View file

@ -91,6 +91,15 @@ int LoadZipArgsImpl(int *argc, char ***argv, char *data) {
} }
start = 0; start = 0;
} }
if (!founddots)
{
founddots = true;
for (i = 1; i < *argc; ++i) {
AddZipArg(&n, &args, (*argv)[i]);
}
}
if (founddots || *argc <= 1) { if (founddots || *argc <= 1) {
if (!g_zipargs.initialized) { if (!g_zipargs.initialized) {
atexit(FreeZipArgs); atexit(FreeZipArgs);
@ -118,8 +127,9 @@ int LoadZipArgsImpl(int *argc, char ***argv, char *data) {
* *
* Your `.args` file should have one argument per line. * Your `.args` file should have one argument per line.
* *
* If the special argument `...` is *not* encountered, then the * If the special argument `...` is *not* encountered, then it would be assumed
* replacement will only happen if *no* CLI args are specified. * 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 * If the special argument `...` *is* encountered, then it'll be
* replaced with whatever CLI args were specified by the user. * replaced with whatever CLI args were specified by the user.