I want to do this:
ENV=development cat dbconfig.json | jq '.database.$ENV'
where config looks like:
{
"database": {
"development": {
"name": "example",
"user": "user",
"password": "asdfasdf"
}
}
}
I want to specify the ENV
in the command and use it to fetch the key "development"
from the json.
In a makefile specifically, I would like to do:
# ensure env is set
ifeq ($(ENV),)
$(error ENV is not set)
endif
CONFIG := $(shell cat config.json)
DATABASE_NAME = $(shell echo CONFIG | jq 'database.$(ENV).name')
migrate:
@migrate -source backend/migrations -database postgres://localhost:5432/$(DATABASE_NAME) up
.PHONY: migrate
I am new to jq, and somewhat to makefiles, how could this be accomplished?