Skip to content

Commit c9a09b9

Browse files
committed
examples: extract argument conversion helper
1 parent 204a464 commit c9a09b9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

examples/args.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,17 @@ int match_arg_separator(struct args_info *args)
181181
args->pos++;
182182
return 1;
183183
}
184+
185+
void strarray_from_args(git_strarray *array, struct args_info *args)
186+
{
187+
size_t i;
188+
189+
array->count = args->argc - args->pos;
190+
array->strings = calloc(array->count, sizeof(char *));
191+
assert(array->strings != NULL);
192+
193+
for (i = 0; args->pos < args->argc; ++args->pos) {
194+
array->strings[i++] = args->argv[args->pos];
195+
}
196+
args->pos = args->argc;
197+
}

examples/args.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,9 @@ extern int match_bool_arg(int *out, struct args_info *args, const char *opt);
8282
*/
8383
extern int match_arg_separator(struct args_info *args);
8484

85+
/**
86+
* Consume all remaining arguments in a git_strarray
87+
*/
88+
extern void strarray_from_args(git_strarray *array, struct args_info *args);
89+
8590
#endif

0 commit comments

Comments
 (0)