mirror of
https://github.com/xHyroM/gimi.git
synced 2024-11-24 00:21:04 +01:00
feat: return proper codes
This commit is contained in:
parent
68fb86bfb4
commit
fac687bd68
5 changed files with 16 additions and 10 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
void cli_command_config(int argc, char **argv);
|
||||
int cli_command_config(int argc, char **argv);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
void cli_command_init(int argc, char **argv);
|
||||
int cli_command_init(int argc, char **argv);
|
||||
|
|
Loading…
Reference in a new issue