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

View File

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

View File

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