mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
examples: extract argument conversion helper
This commit is contained in:
@@ -181,3 +181,17 @@ int match_arg_separator(struct args_info *args)
|
||||
args->pos++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void strarray_from_args(git_strarray *array, struct args_info *args)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
array->count = args->argc - args->pos;
|
||||
array->strings = calloc(array->count, sizeof(char *));
|
||||
assert(array->strings != NULL);
|
||||
|
||||
for (i = 0; args->pos < args->argc; ++args->pos) {
|
||||
array->strings[i++] = args->argv[args->pos];
|
||||
}
|
||||
args->pos = args->argc;
|
||||
}
|
||||
|
||||
@@ -82,4 +82,9 @@ extern int match_bool_arg(int *out, struct args_info *args, const char *opt);
|
||||
*/
|
||||
extern int match_arg_separator(struct args_info *args);
|
||||
|
||||
/**
|
||||
* Consume all remaining arguments in a git_strarray
|
||||
*/
|
||||
extern void strarray_from_args(git_strarray *array, struct args_info *args);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user