Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build and run urfave-cli-genflags via its Makefile #1526

Merged
merged 3 commits into from Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli.go
Expand Up @@ -22,4 +22,4 @@
// }
package cli

//go:generate go run cmd/urfave-cli-genflags/main.go
//go:generate make -C cmd/urfave-cli-genflags run
7 changes: 7 additions & 0 deletions cmd/urfave-cli-genflags/Makefile
@@ -1,6 +1,9 @@
GOIMPORTS_BIN ?= $(shell which goimports || true)
GOTEST_FLAGS ?= -v --coverprofile main.coverprofile --covermode count --cover github.com/urfave/cli/v2/cmd/urfave-cli-genflags
GOBUILD_FLAGS ?= -x

export GOIMPORTS_BIN

.PHONY: all
all: test build smoke-test

Expand All @@ -19,3 +22,7 @@ smoke-test: build
.PHONY: show-cover
show-cover:
go tool cover -func main.coverprofile

.PHONY: run
run: build
./urfave-cli-genflags
17 changes: 15 additions & 2 deletions cmd/urfave-cli-genflags/main.go
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
_ "embed"
"fmt"
"log"
"os"
"os/exec"
Expand Down Expand Up @@ -37,6 +38,9 @@ var (
func sh(ctx context.Context, exe string, args ...string) (string, error) {
cmd := exec.CommandContext(ctx, exe, args...)
cmd.Stderr = os.Stderr

fmt.Fprintf(os.Stderr, "# ---> %s\n", cmd)

outBytes, err := cmd.Output()
return string(outBytes), err
}
Expand Down Expand Up @@ -89,10 +93,19 @@ func main() {
Aliases: []string{"N"},
Value: "cli.",
},
&cli.PathFlag{
Name: "goimports",
EnvVars: []string{"GOIMPORTS_BIN"},
Value: filepath.Join(top, ".local/bin/goimports"),
},
},
Action: runGenFlags,
}

if err := os.Chdir(top); err != nil {
log.Fatal(err)
}

if err := app.RunContext(ctx, os.Args); err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -163,11 +176,11 @@ func runGenFlags(cCtx *cli.Context) error {
return err
}

if _, err := sh(cCtx.Context, "goimports", "-w", cCtx.Path("generated-output")); err != nil {
if _, err := sh(cCtx.Context, cCtx.Path("goimports"), "-w", cCtx.Path("generated-output")); err != nil {
return err
}

if _, err := sh(cCtx.Context, "goimports", "-w", cCtx.Path("generated-test-output")); err != nil {
if _, err := sh(cCtx.Context, cCtx.Path("goimports"), "-w", cCtx.Path("generated-test-output")); err != nil {
return err
}

Expand Down