2023-11-22 21:39:27 +00:00
|
|
|
#include <stdio.h>
|
2023-11-22 20:43:34 +00:00
|
|
|
#include <stdlib.h>
|
2023-11-23 15:07:22 +00:00
|
|
|
#include <unistd.h>
|
2023-11-22 20:43:34 +00:00
|
|
|
|
2023-11-22 21:39:27 +00:00
|
|
|
#include "config.h"
|
2023-11-22 20:43:34 +00:00
|
|
|
#include "dyn_array.h"
|
|
|
|
|
2023-11-23 11:10:04 +00:00
|
|
|
const char *ENV_SPEC_ROOT_DIR = "SPEC_ROOT_DIR";
|
|
|
|
|
2023-11-22 18:15:12 +00:00
|
|
|
int main(int argc, char **argv) {
|
2023-11-22 20:43:34 +00:00
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr, "Usage: gen-flake <spec>\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2023-11-23 15:07:22 +00:00
|
|
|
const char *cwd = getcwd(0, 0);
|
2023-11-23 11:10:04 +00:00
|
|
|
const char *root_dir = getenv(ENV_SPEC_ROOT_DIR);
|
2023-11-23 15:07:22 +00:00
|
|
|
const char *target = argv[1];
|
2023-11-23 11:10:04 +00:00
|
|
|
|
2023-11-23 14:40:17 +00:00
|
|
|
struct Config *config = 0;
|
2023-11-23 15:07:22 +00:00
|
|
|
switch (config_load(cwd, root_dir, target, &config)) {
|
|
|
|
case CE_ENV_CWD_INVALID:
|
|
|
|
fprintf(stderr, "Could not retrieve the $CWD value.");
|
2023-11-22 21:39:27 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2023-11-23 15:07:22 +00:00
|
|
|
case CE_ENV_SPEC_ROOT_DIR_INVALID:
|
|
|
|
fprintf(stderr, "Must specify $SPEC_ROOT_DIR environment variable.");
|
2023-11-22 21:39:27 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2023-11-23 15:07:22 +00:00
|
|
|
case CE_TARGET_INVALID:
|
2023-11-22 21:55:55 +00:00
|
|
|
fprintf(stderr, "Target spec `%s` is invalid.", argv[1]);
|
2023-11-22 21:39:27 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2023-11-22 18:15:12 +00:00
|
|
|
|
2023-11-23 14:40:17 +00:00
|
|
|
config_free(config);
|
2023-11-23 15:07:22 +00:00
|
|
|
free((void *)cwd);
|
2023-11-22 21:39:27 +00:00
|
|
|
return EXIT_SUCCESS;
|
2023-11-22 18:15:12 +00:00
|
|
|
}
|