cmd: add remote arg

issue #2
This commit is contained in:
tylen 2024-09-26 19:21:17 +00:00 committed by Vasily Davydov
parent 384b5ceb3d
commit 5172da33ac
3 changed files with 9 additions and 2 deletions

View File

@ -11,16 +11,19 @@ static struct ArgList* supported_args;
static const char* PREDEFINED_ARG_NAMES [] = {
"--project",
"--remote",
"--help"
};
static const char* PREDEFINED_ARG_DESC [] = {
"Path to the project to be used for looking up TODO's",
"Remote to follow in project's git configuration",
"Show this message"
};
static const char* PREDEFINED_ARG_VALUES [] = {
NULL,
"origin",
NULL
};
@ -99,6 +102,7 @@ void init_cmd(void) {
switch (i)
{
case ARG_PROJECT:
case ARG_REMOTE:
case ARG_HELP:
append_arg(supported_args, renderArgById(i));
break;
@ -193,8 +197,10 @@ struct ArgList* parse_args(const int argc, char* argv[]) {
{
case ARG_HELP:
usage();
exit(1);
break;
case ARG_PROJECT:
case ARG_REMOTE:
int next_iterator = (i + 1 < argc) ? i + 1 : i;
if (!validate_arg_param(argv[next_iterator])) {
LOG_ERROR("Argument '%s' requires a value.", PREDEFINED_ARG_NAMES[current_arg]);

View File

@ -10,6 +10,7 @@
typedef enum {
ARG_PROJECT,
ARG_REMOTE,
ARG_HELP,
ARG_COUNT
} ArgNameId;

View File

@ -21,8 +21,8 @@ Buffer* buffer_create(size_t capacity) {
void buffer_append(Buffer* buffer, const char* str) {
LOG_DEBUG("Entering function %s", __func__);
size_t len = strlen(str);
if (buffer->size + len >= buffer->capacity) {
buffer->capacity = buffer->size + len;
while (buffer->size + len >= buffer->capacity) {
buffer->capacity *= 2;
buffer->data = (char*)cdo_realloc(buffer->data, buffer->capacity);
}
strcpy(buffer->data + buffer->size, str);