diff --git a/src/cli/cli.c b/src/cli/cli.c index 305c6d5..eddee24 100644 --- a/src/cli/cli.c +++ b/src/cli/cli.c @@ -19,11 +19,11 @@ int cli_handle(int argc, char **argv) { char *sub_command = argv[0]; if (strcmp(sub_command, "init") == 0) { - cli_command_init(argc, argv); + return cli_command_init(argc, argv); } if (strcmp(sub_command, "config") == 0) { - cli_command_config(argc, argv); + return cli_command_config(argc, argv); } return 0; diff --git a/src/cli/command/config.c b/src/cli/command/config.c index cb9263a..bd6ff9e 100644 --- a/src/cli/command/config.c +++ b/src/cli/command/config.c @@ -4,17 +4,19 @@ #define INIT_CONFIG "[providers]\n" -void cli_command_config(int argc, char **argv) { +int cli_command_config(int argc, char **argv) { struct gimi_config *cfg = config_read(); if (!cfg) { printf("Missing gimi config. Initialize it using gimi init command."); - return; + return 1; } for (int i = 0; i < cfg->providers_size; i++) { struct gimi_config_provider *provider = cfg->providers[i]; - printf("ssh: %s | primary: %d\n", provider->ssh, provider->primary); + printf("name: %s | ssh: %s | primary: %d\n", provider->name, provider->ssh, + provider->primary); } config_free(cfg); + return 0; } diff --git a/src/cli/command/config.h b/src/cli/command/config.h index b855828..4d19c8e 100644 --- a/src/cli/command/config.h +++ b/src/cli/command/config.h @@ -1 +1 @@ -void cli_command_config(int argc, char **argv); +int cli_command_config(int argc, char **argv); diff --git a/src/cli/command/init.c b/src/cli/command/init.c index e3f96ca..c80f11a 100644 --- a/src/cli/command/init.c +++ b/src/cli/command/init.c @@ -8,24 +8,26 @@ #define INIT_CONFIG "[providers]\n" -void cli_command_init(int argc, char **argv) { +int cli_command_init(int argc, char **argv) { errno = 0; int ret = mkdir(".gimi", S_IRWXU); if (ret == -1 && errno != EEXIST) { printf("Failed to initialize gimi.\n"); - return; + return 1; } struct stat stats; if (stat(".git", &stats) != 0 || !S_ISDIR(stats.st_mode)) { printf("Missing .git directory. Use git init to initialize git.\n"); - return; + return 1; } char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd)) == NULL) { printf("Failed to get current working directory.\n"); + return 1; } + printf("Initialized gimi in %s/.gimi\n", cwd); FILE *file_ptr; @@ -33,4 +35,6 @@ void cli_command_init(int argc, char **argv) { fprintf(file_ptr, INIT_CONFIG); fclose(file_ptr); + + return 0; } diff --git a/src/cli/command/init.h b/src/cli/command/init.h index 24d1da9..2be267b 100644 --- a/src/cli/command/init.h +++ b/src/cli/command/init.h @@ -1 +1 @@ -void cli_command_init(int argc, char **argv); +int cli_command_init(int argc, char **argv);