diff --git a/kcompose.sh b/kcompose.sh index 5e17853..df89fbc 100755 --- a/kcompose.sh +++ b/kcompose.sh @@ -15,13 +15,34 @@ # along with this program. If not, see . set -f # Disables Globbing -defaultConfigFile=$HOME/.kcompose/config +configPath=$HOME/.kcompose/ + +defaultConfigPath=${configPath}default/ +defaultConfigFile=${defaultConfigPath}config + +defaultCredentialsPath=${configPath}default/ +defaultCredentialsFile=${defaultCredentialsPath}credentials + +if [ ! -f ${configPath}context ]; then + touch ${configPath}context +fi + +source ${configPath}context +currentContext=${KCOMPOSE_CONTEXT:-"default"} + +if [ -z "$KCOMPOSE_CONFIG_FILE" ]; then + if [ ! -d "${configPath}${currentContext}" ]; then + echo -e "WARNING: Context ${currentContext} not found\n\n" + echo -e "Please, set a valid context using the command:" + echo -e "kcompose context set \n" + fi +fi # Config chain # Defaults broker="localhost:9092" -credentialsFile="" kafkaLocation="/usr/share/kcompose/kafka" +credentialsFile="" configFile=${KCOMPOSE_CONFIG_FILE:-$defaultConfigFile} # Config file @@ -88,6 +109,12 @@ ask() { eval "$result=\"$answer\"" } +saveContext() { + if [ -f ${configPath}context ]; then + echo "KCOMPOSE_CONTEXT=$1" > ${configPath}context + fi +} + saveConfigs() { mkdir -p $(dirname $configFile) cat >$configFile <