Build and run urfave-cli-genflags
via its Makefile
so that `go.mod` files don't get all confused
This commit is contained in:
parent
f64acc4404
commit
11915a875d
2
cli.go
2
cli.go
@ -22,4 +22,4 @@
|
|||||||
// }
|
// }
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
//go:generate go run cmd/urfave-cli-genflags/main.go
|
//go:generate make -C cmd/urfave-cli-genflags run
|
||||||
|
@ -19,3 +19,7 @@ smoke-test: build
|
|||||||
.PHONY: show-cover
|
.PHONY: show-cover
|
||||||
show-cover:
|
show-cover:
|
||||||
go tool cover -func main.coverprofile
|
go tool cover -func main.coverprofile
|
||||||
|
|
||||||
|
.PHONY: run
|
||||||
|
run: build
|
||||||
|
./urfave-cli-genflags
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -37,6 +38,9 @@ var (
|
|||||||
func sh(ctx context.Context, exe string, args ...string) (string, error) {
|
func sh(ctx context.Context, exe string, args ...string) (string, error) {
|
||||||
cmd := exec.CommandContext(ctx, exe, args...)
|
cmd := exec.CommandContext(ctx, exe, args...)
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
fmt.Fprintf(os.Stderr, "# ---> %s\n", cmd)
|
||||||
|
|
||||||
outBytes, err := cmd.Output()
|
outBytes, err := cmd.Output()
|
||||||
return string(outBytes), err
|
return string(outBytes), err
|
||||||
}
|
}
|
||||||
@ -89,10 +93,18 @@ func main() {
|
|||||||
Aliases: []string{"N"},
|
Aliases: []string{"N"},
|
||||||
Value: "cli.",
|
Value: "cli.",
|
||||||
},
|
},
|
||||||
|
&cli.PathFlag{
|
||||||
|
Name: "goimports",
|
||||||
|
Value: filepath.Join(top, ".local/bin/goimports"),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: runGenFlags,
|
Action: runGenFlags,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := os.Chdir(top); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := app.RunContext(ctx, os.Args); err != nil {
|
if err := app.RunContext(ctx, os.Args); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -163,11 +175,11 @@ func runGenFlags(cCtx *cli.Context) error {
|
|||||||
return err
|
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
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user