aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
+}