feat: check if cfg exists

This commit is contained in:
Jozef Steinhübl 2024-07-23 18:07:58 +02:00
parent cdc87b444a
commit 45d13856ec
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F
5 changed files with 14 additions and 13 deletions

View file

@ -104,6 +104,8 @@ char *generate_sourcehut(struct gimi_config *cfg,
int generate(int argc, char **argv) {
struct gimi_config *cfg = config_read();
ASSERT_CONFIG_EXIST(cfg);
struct gimi_config_provider *provider;
if (argc == 2) {

View file

@ -6,11 +6,7 @@
int cli_command_config(int argc, char **argv) {
struct gimi_config *cfg = config_read();
if (!cfg) {
printf(
"error: missing gimi config, initialize it using gimi init command.");
return 1;
}
ASSERT_CONFIG_EXIST(cfg);
for (int i = 0; i < cfg->providers_size; i++) {
struct gimi_config_provider *provider = cfg->providers[i];

View file

@ -7,8 +7,7 @@
int providers() {
struct gimi_config *cfg = config_read();
if (!cfg)
return 1;
ASSERT_CONFIG_EXIST(cfg);
for (int i = 0; i < cfg->providers_size; i++) {
struct gimi_config_provider *provider = cfg->providers[i];
@ -27,8 +26,7 @@ int provider_info(int argc, char **argv) {
}
struct gimi_config *cfg = config_read();
if (!cfg)
return 1;
ASSERT_CONFIG_EXIST(cfg);
struct gimi_config_provider *provider = config_find_provider(cfg, argv[1]);
config_free(cfg);
@ -54,8 +52,7 @@ int provider_sync(int argc, char **argv) {
}
struct gimi_config *cfg = config_read();
if (!cfg)
return 1;
ASSERT_CONFIG_EXIST(cfg);
struct gimi_config_provider *provider = config_find_provider(cfg, argv[1]);
config_free(cfg);

View file

@ -55,8 +55,7 @@ int git_push(char *provider_name, char *branch_name, bool verbose) {
int cli_command_push(int argc, char **argv) {
struct gimi_config *cfg = config_read();
if (!cfg)
return 1;
ASSERT_CONFIG_EXIST(cfg);
bool verbose = argc == 2 && strcmp(argv[1], "--verbose") == 0;

View file

@ -1,5 +1,12 @@
#include <stdbool.h>
#define ASSERT_CONFIG_EXIST(cfg) \
if (!cfg) { \
printf( \
"error: missing gimi config, initialize it using gimi init command."); \
return 1; \
}
struct gimi_config_provider {
char *name;
char *ssh;