Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Apr 2, 2024
1 parent b795ce2 commit 33bcac2
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import (
// App info
const (
APP = "GoMakeGen"
VER = "2.3.1"
VER = "2.3.2"
DESC = "Utility for generating makefiles for Go applications"
)

Expand Down Expand Up @@ -84,6 +84,7 @@ type Makefile struct {
PkgBase string

MaxTargetNameSize int
MaxOptionNameSize int

HasTests bool
Benchmark bool
Expand Down Expand Up @@ -685,7 +686,7 @@ func (m *Makefile) getPhony() string {
phony := []string{"fmt", "vet"}

if len(m.Binaries) != 0 {
phony = append(phony, "all", "clean")
phony = append(phony, "all", "install", "uninstall", "clean")
}

if len(m.BaseImports) != 0 || m.ModUsed {
Expand All @@ -712,6 +713,10 @@ func (m *Makefile) getPhony() string {
phony = append(phony, "benchmark")
}

for _, target := range phony {
m.MaxTargetNameSize = mathutil.Max(m.MaxTargetNameSize, len(target))
}

if m.GlideUsed {
phony = append(phony, "glide-create", "glide-install", "glide-update")
}
Expand All @@ -726,10 +731,6 @@ func (m *Makefile) getPhony() string {

phony = append(phony, "help")

for _, target := range append(phony, m.Binaries...) {
m.MaxTargetNameSize = mathutil.Max(m.MaxTargetNameSize, len(target)+2)
}

return ".PHONY = " + strings.Join(phony, " ") + "\n"
}

Expand Down Expand Up @@ -926,6 +927,8 @@ func (m *Makefile) getTestTarget() string {
result += "\t" + testTarget + " " + targets + "\n"
result += "endif\n\n"

m.MaxOptionNameSize = mathutil.Max(m.MaxOptionNameSize, len("COVERAGE_FILE"))

return result
}

Expand Down Expand Up @@ -1085,21 +1088,24 @@ func (m *Makefile) getModTarget() string {
result += "mod-vendor:\n"
result += "\trm -rf vendor && go mod vendor $(VERBOSE_FLAG)\n\n"

m.MaxOptionNameSize = mathutil.Max(m.MaxOptionNameSize, len("MODULE_PATH"))

return result
}

// getHelpTarget generates target for "help" command
func (m *Makefile) getHelpTarget() string {
fmtSize := strconv.Itoa(m.MaxTargetNameSize)
targetNameSize := strconv.Itoa(m.MaxTargetNameSize)
optionNameSize := strconv.Itoa(m.MaxOptionNameSize)

result := "help: ## Show this info\n"
result += "\t@echo -e '\\n\\033[1mTargets:\\033[0m\\n'\n"
result += "\t@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \\\n"
result += "\t\t| awk 'BEGIN {FS = \":.*?## \"}; {printf \" \\033[33m%-" + fmtSize + "s\\033[0m %s\\n\", $$1, $$2}'\n"
result += "\t\t| awk 'BEGIN {FS = \":.*?## \"}; {printf \" \\033[33m%-" + targetNameSize + "s\\033[0m %s\\n\", $$1, $$2}'\n"
result += "\t@echo -e '\\n\\033[1mVariables:\\033[0m\\n'\n"
result += "\t@grep -E '^ifdef [A-Z_]+ .*?## .*$$' $(abspath $(lastword $(MAKEFILE_LIST))) \\\n"
result += "\t\t| sed 's/ifdef //' \\\n"
result += "\t\t| awk 'BEGIN {FS = \" .*?## \"}; {printf \" \\033[32m%-14s\\033[0m %s\\n\", $$1, $$2}'\n"
result += "\t\t| awk 'BEGIN {FS = \" .*?## \"}; {printf \" \\033[32m%-" + optionNameSize + "s\\033[0m %s\\n\", $$1, $$2}'\n"
result += "\t@echo -e ''\n"
result += "\t@echo -e '\\033[90mGenerated by GoMakeGen " + VER + "\\033[0m\\n'\n\n"

Expand Down

0 comments on commit 33bcac2

Please sign in to comment.