feat: handle missing cfg, git correctly

This commit is contained in:
Jozef Steinhübl 2024-07-22 14:58:51 +02:00
parent 7a34db763c
commit 68fb86bfb4
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F
3 changed files with 14 additions and 0 deletions

View file

@ -6,6 +6,11 @@
void 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;
}
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);

View file

@ -16,6 +16,12 @@ void cli_command_init(int argc, char **argv) {
return;
}
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;
}
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) == NULL) {
printf("Failed to get current working directory.\n");

View file

@ -10,6 +10,9 @@ struct gimi_config *config_read() {
char errbuf[200];
file_ptr = fopen(".gimi/config.toml", "r");
if (!file_ptr) {
return NULL;
}
toml_table_t *toml_cfg = toml_parse_file(file_ptr, errbuf, sizeof(errbuf));
fclose(file_ptr);