I am trying to create a nice and dynamic help, but I am struggling to interpret the variable name in the project’s .env file. I need these names to be interpreted by the .env. I will provide the closest result I was able to achieve, but I couldn’t make any further progress.
In the image above, I marked the text that needs to be interpreted by the .env
Here is the code:
SHELL := /bin/bash
include .env
ENV_FILE = .env
help: ## Show help.
@awk 'BEGIN {
FS = ":.*##";
printf "nUsage:n make 33[0;34m<target>33[0mnnTargets:n"
}
/^[a-zA-Z_/-$${}]+:.*?##/ {
targetName = $$1;
description = $$2;
if (match(targetName, "\$\{([^}]+)\}")) {
varEnvName = substr(targetName, RSTART+1, RLENGTH-2);
gsub("\$$\{[a-zA-Z_]+\}", varEnvName, targetName);
};
printf " 33[0;34m%-10s33[0m %sn", targetName, description
}' $(MAKEFILE_LIST)
call/${DOCKER_PHP_CONTAINER_NAME}/a: ## PHP // Help dynamic.
@echo "Dynamic target running for ${DOCKER_PHP_CONTAINER_NAME}"
call/${DOCKER_NGINX_CONTAINER_NAME}/a: ## NGINX // Help dynamic.
@echo "Dynamic target running for ${DOCKER_NGINX_CONTAINER_NAME}"
call/bpro_php/b: ## Help fixed.
@echo "Fixed target running..."
2
Answers
I made it :)
I'm not sure if it's a best solution, but it's work for me.