From 07dcfe9053d3dd49337fc3fdaa4a8c1fdb5c8908 Mon Sep 17 00:00:00 2001 From: Caio Fernando Date: Wed, 2 Oct 2024 16:21:19 -0300 Subject: [PATCH] improve makefile --- Makefile | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1eb88d1..c03211f 100644 --- a/Makefile +++ b/Makefile @@ -61,9 +61,41 @@ watch: fi migration-create: - goose create -dir="internal/database/migrations" $(name) sql + @echo "Creating migration..." + + @if command -v goose > /dev/null; then \ + goose create -dir="internal/database/migrations" $(name) sql; \ + else \ + read -p "Go's 'goose' is not installed on your machine. Do you want to install it? [Y/n] " choice; \ + if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \ + go install github.com/pressly/goose/v3/cmd/goose@latest; \ + if command asdf > /dev/null; then \ + asdf reshim golang; \ + fi; \ + goose create -dir="internal/database/migrations" $(name) sql; \ + else \ + echo "You chose not to install goose. Exiting..."; \ + exit 1; \ + fi; \ + fi; generate: - sqlc generate + @echo "Generating sqlc files..." + + @if command -v sqlc > /dev/null; then \ + sqlc generate; \ + else \ + read -p "Go's 'sqlc' is not installed on your machine. Do you want to install it? [Y/n] " choice; \ + if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \ + go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest; \ + if command asdf > /dev/null; then \ + asdf reshim golang; \ + fi; \ + sqlc generate; \ + else \ + echo "You chose not to install sqlc. Exiting..."; \ + exit 1; \ + fi; \ + fi; .PHONY: all build run test clean watch docker-run docker-down itest migration-create