From 20d4685a1359458646714d64e6d7e4a1924ced48 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Fri, 6 Oct 2023 00:17:42 +0500 Subject: [PATCH] added support for podman and docker engines --- container-compose | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/container-compose b/container-compose index 1a0fa4c..1105b25 100755 --- a/container-compose +++ b/container-compose @@ -2,10 +2,21 @@ check_file() { local file="" + local engine="" local opt local OPTARG local OPTIND=1 + # Manually parse --engine= argument + for arg in "$@"; do + case $arg in + --engine=*) + engine="${arg#*=}" + shift # Remove --engine= from positional parameters + ;; + esac + done + # Check if -f flag is provided while getopts ":f:" opt; do case $opt in @@ -13,7 +24,7 @@ check_file() { file="$OPTARG" ;; \?) - echo "Usage: $0 [-f file]" + echo "Usage: $0 [-f file] [--engine=engine_name]" return 1 ;; :) @@ -23,6 +34,7 @@ check_file() { esac done + # Check if file is provided, if not look for default files if [ -z "$file" ]; then if [ -f "compose.yaml" ]; then @@ -48,7 +60,23 @@ check_file() { return 1 fi - # Output the file being used - echo "Using $file" + # Set engine based on file if engine is not set + if [ -z "$engine" ]; then + case $file in + docker-compose.yaml|docker-compose.yml) + engine="docker" + ;; + podman-compose.yaml|podman-compose.yml) + engine="podman" + ;; + *) + echo "Engine not set and cannot be determined from file name. Specify with --engine=engine_name" + return 1 + ;; + esac + fi + + # Output the file and engine being used + echo "Using $file with engine $engine" } check_file "$@"