aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2021-04-26 11:42:33 -0400
committerGalen Guyer <galen@galenguyer.com>2021-04-26 11:42:33 -0400
commit9d6f205073020bd716000d4857a3053e5b9b173f (patch)
tree86a161349972c6438a3e16c137860f5cd4910aa7
parent6703990fd9e0647814b67d4ee851ba203e03c84c (diff)
Add comments to composer source
-rw-r--r--composer.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/composer.c b/composer.c
index ee79b3d..fd67641 100644
--- a/composer.c
+++ b/composer.c
@@ -12,22 +12,33 @@ int main(int argc, char** argv) {
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);
+ // Create the char* args array for all the arguments we'll be passing in
char* args[argc+2+(2*glob_buf.gl_pathc)];
+
+ // Set the base command and file
args[0] = COMMAND;
args[1] = "-f";
args[2] = "docker-compose.yaml";
+
+ // For each path found by glob, append -f [PATH] to args
for(size_t i = 0; i < glob_buf.gl_pathc; i++) {
args[(2*i)+3] = "-f";
args[(2*i)+4] = glob_buf.gl_pathv[i];
}
+
+ // Append all command line arguments passed into composer
for (int i = 1; i < argc; i++) {
args[2+(2*glob_buf.gl_pathc)+i] = argv[i];
}
+
+ // Set the final arg to NULL as expected by execvp
args[argc+2+(2*glob_buf.gl_pathc)] = NULL;
+ // Run the command and print an error if it fails
int result = execvp(COMMAND, args);
if (result < 0) {
perror(COMMAND);