From 54c058db12daa01340cc06f2f3997024a98a96d1 Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Thu, 17 Jun 2021 21:29:48 -0700 Subject: Accept yaml and yml file extensions --- composer.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'composer.c') diff --git a/composer.c b/composer.c index fd67641..6bee94b 100644 --- a/composer.c +++ b/composer.c @@ -6,15 +6,23 @@ #define COMMAND "docker-compose" int main(int argc, char** argv) { - // TODO: Support docker-compose.yaml too - if (access("docker-compose.yaml", R_OK) < 0) { - fprintf(stderr, "No 'docker-compose.yaml' file found\n"); + // find the base file, with a preference for .yaml if both exist + char* base_file = NULL; + if (access("docker-compose.yml", R_OK) >= 0) { + base_file = "docker-compose.yml"; + } + else if (access("docker-compose.yaml", R_OK) >= 0) { + base_file = "docker-compose.yaml"; + } + else { + fprintf(stderr, "No 'docker-compose.yaml' or 'docker-compose.yml' file found, exiting\n"); exit(1); } // Get all files matching the given pattern in the current directory glob_t glob_buf; glob("docker-compose.*.yaml", 0, NULL, &glob_buf); + glob("docker-compose.*.yml", GLOB_APPEND, NULL, &glob_buf); // Create the char* args array for all the arguments we'll be passing in char* args[argc+2+(2*glob_buf.gl_pathc)]; @@ -22,7 +30,7 @@ int main(int argc, char** argv) { // Set the base command and file args[0] = COMMAND; args[1] = "-f"; - args[2] = "docker-compose.yaml"; + args[2] = base_file; // For each path found by glob, append -f [PATH] to args for(size_t i = 0; i < glob_buf.gl_pathc; i++) { @@ -43,4 +51,4 @@ int main(int argc, char** argv) { if (result < 0) { perror(COMMAND); } -} \ No newline at end of file +} -- cgit v1.2.3