mirror of
https://github.com/xHyroM/gimi.git
synced 2024-11-10 02:38:06 +01:00
feat: handle missing cfg, git correctly
This commit is contained in:
parent
7a34db763c
commit
68fb86bfb4
3 changed files with 14 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue