Skip to content

Commit

Permalink
Added -mute option on make-help command line to skip targets without …
Browse files Browse the repository at this point in the history
…comment
  • Loading branch information
c4s4 committed Feb 3, 2021
1 parent f9c485a commit 6f3e949
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

include ~/.make/Golang.mk

go-build: build
go-binaries: binaries
test: go-test # Run unit tests
release: go-release # Perform release
release: go-release # Perform release (you must pass VERSION=X.Y.Z on command line)

go-build: clean # Build binary
build: clean # Build binary for current platform
$(title)
@mkdir -p $(BUILD_DIR)
@go build -ldflags "-X main.Version=$(VERSION) -s -f" -o $(BUILD_DIR)/ ./...
Expand All @@ -14,7 +16,7 @@ go-build: clean # Build binary
mv $$file make-$$file; \
done

go-binaries: clean # Build binaries
binaries: clean # Build binaries for all platforms
$(title)
@mkdir -p $(BUILD_DIR)/bin
@gox -ldflags "-X main.Version=$(VERSION) -s -f" -osarch '$(GOOSARCH)' -output=$(BUILD_DIR)/bin/make-{{.Dir}}-{{.OS}}-{{.Arch}} ./...
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ help: # Print help on Makefile
@make-help
```

To get help on targets in root makefile only (without parsing included ones), you can pass `-root` option on command line.
To get help on targets in root makefile only (without parsing included ones), you can pass `-root` option on command line. To skip help on targets without comment, you can pass `-mute` on command line.

## make-desc

Expand Down
24 changes: 15 additions & 9 deletions help/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,26 @@ const (
Print makefile help:
-help To print this help
-version To print version
-root To parse root makefile only`
-root To parse root makefile only
-mute Don't print targets without comment`
)

// ParseCommandLine parses command line and returns:
// - help: a boolean that tells if we print help
// - version: a boolean that tells if we print version
// - root: a boolean that tells if we parse recursively
func ParseCommandLine() (*bool, *bool, *bool) {
// - mute: a boolean that tells not to print targets without comment
func ParseCommandLine() (bool, bool, bool, bool) {
help := flag.Bool("help", false, "Print help")
version := flag.Bool("version", false, "Print version")
root := flag.Bool("root", false, "Parse root makefile only")
mute := flag.Bool("mute", false, "Don't print targets without comment")
flag.Parse()
return help, version, root
return *help, *version, *root, *mute
}

// HelpLineFormatter formats help lines to print
func HelpLineFormatter(help []maketools.HelpLine) string {
func HelpLineFormatter(help []maketools.HelpLine, mute bool) string {
indent := 0
for _, helpLine := range help {
if indent < len(helpLine.Name) {
Expand All @@ -43,6 +46,9 @@ func HelpLineFormatter(help []maketools.HelpLine) string {
}
var lines []string
for _, helpLine := range help {
if helpLine.Description == "" && mute {
continue
}
spaces := indent - len(helpLine.Name)
line := "\033[93m" + helpLine.Name + "\033[0m" + strings.Repeat(" ", spaces)
if helpLine.Description != "" {
Expand All @@ -65,12 +71,12 @@ func Error(err error) {
}

func main() {
help, version, root := ParseCommandLine()
if *help {
help, version, root, mute := ParseCommandLine()
if help {
fmt.Println(Help)
os.Exit(0)
}
if *version {
if version {
fmt.Println(Version)
os.Exit(0)
}
Expand All @@ -79,9 +85,9 @@ func main() {
println("No makefile found")
os.Exit(1)
}
helpLines, err := maketools.ParseMakefile(maketools.ReadFile(filename), !*root)
helpLines, err := maketools.ParseMakefile(maketools.ReadFile(filename), !root)
if err != nil {
Error(err)
}
fmt.Println(HelpLineFormatter(helpLines))
fmt.Println(HelpLineFormatter(helpLines, mute))
}

0 comments on commit 6f3e949

Please sign in to comment.