diff --git a/Makefile b/Makefile index 4852b4d..8b09725 100644 --- a/Makefile +++ b/Makefile @@ -54,13 +54,43 @@ release: @goreleaser release --skip-publish --rm-dist .PHONY: help -## Display this help screen - requires gawk -help: - @gawk 'match($$0, /^## (.*)/, a) \ - { getline x; x = gensub(/(.+:) .+/, "\\1", "g", x) ; \ - printf "\033[36m%-30s\033[0m %s\n", x, a[1]; }' $(MAKEFILE_LIST) | sort .PHONY: build ## Builds binary from source build: CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags "$(LD_FLAGS)" -o dist/dirstalk cmd/dirstalk/main.go + +.PHONY: build +HELP_WIDTH=" " +## Display makefile help +help: + @printf "Usage\n"; + @awk '{ \ + if ($$0 ~ /^.PHONY: [a-zA-Z\-\_0-9]+$$/) { \ + helpCommand = substr($$0, index($$0, ":") + 2); \ + if (helpMessage) { \ + printf " \033[32m%-20s\033[0m %s\n", \ + helpCommand, helpMessage; \ + helpMessage = ""; \ + } \ + } else if ($$0 ~ /^[a-zA-Z\-\_0-9.]+:/) { \ + helpCommand = substr($$0, 0, index($$0, ":")); \ + if (helpMessage) { \ + printf " \033[32m%-20s\033[0m %s\n", \ + helpCommand, helpMessage; \ + helpMessage = ""; \ + } \ + } else if ($$0 ~ /^##/) { \ + if (helpMessage) { \ + helpMessage = helpMessage"\n"${HELP_WIDTH}substr($$0, 3); \ + } else { \ + helpMessage = substr($$0, 3); \ + } \ + } else { \ + if (helpMessage) { \ + print "\n"${HELP_WIDTH}helpMessage"\n" \ + } \ + helpMessage = ""; \ + } \ + }' \ +$(MAKEFILE_LIST) diff --git a/README.md b/README.md index 5908390..eb1cc68 100644 --- a/README.md +++ b/README.md @@ -102,11 +102,10 @@ make build # to build an executable for your h [dep](https://github.com/golang/dep) is the tool of choice for dependency management. -If you have [gawk](https://www.gnu.org/software/gawk/) available in your PATH you can also just launch ```bash make help ``` -to obtain a description of every command available in the Makefile. +will print a description of every command available in the Makefile. Wanna add a functionality? fix a bug? fork and create a PR.