aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2021-06-17 21:29:48 -0700
committerGalen Guyer <galen@galenguyer.com>2021-06-17 21:29:48 -0700
commit54c058db12daa01340cc06f2f3997024a98a96d1 (patch)
tree4b5149782397108d9b9cdec9da3df8e4e0822c9c
parente4c72a2f3b84d218b2666f0989cddb0fe21366ea (diff)
Accept yaml and yml file extensionsHEADmain
-rw-r--r--composer.c18
1 files changed, 13 insertions, 5 deletions
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
+}