From e7fb31ad45aafe6733523da75a71131305a27ad9 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Tue, 7 Nov 2023 09:48:13 -0500 Subject: [PATCH] internal/cmd/deadcode: rename -format to -f (following go list) Change-Id: Ie87af973b853584082c298c339e995a8030f2d9b Reviewed-on: https://go-review.googlesource.com/c/tools/+/540475 Reviewed-by: Robert Findley LUCI-TryBot-Result: Go LUCI --- internal/cmd/deadcode/deadcode.go | 10 +++++----- internal/cmd/deadcode/doc.go | 8 ++++---- internal/cmd/deadcode/testdata/lineflag.txtar | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/cmd/deadcode/deadcode.go b/internal/cmd/deadcode/deadcode.go index 890fcc14f19..58b42c25180 100644 --- a/internal/cmd/deadcode/deadcode.go +++ b/internal/cmd/deadcode/deadcode.go @@ -43,7 +43,7 @@ var ( filterFlag = flag.String("filter", "", "report only packages matching this regular expression (default: module of first package)") generatedFlag = flag.Bool("generated", false, "include dead functions in generated Go files") whyLiveFlag = flag.String("whylive", "", "show a path from main to the named function") - formatFlag = flag.String("format", "", "format output records using template") + formatFlag = flag.String("f", "", "format output records using template") jsonFlag = flag.Bool("json", false, "output JSON records") cpuProfile = flag.String("cpuprofile", "", "write CPU profile to this file") memProfile = flag.String("memprofile", "", "write memory profile to this file") @@ -101,10 +101,10 @@ func main() { // Reject bad output options early. if *formatFlag != "" { if *jsonFlag { - log.Fatalf("you cannot specify both -format=template and -json") + log.Fatalf("you cannot specify both -f=template and -json") } if _, err := template.New("deadcode").Parse(*formatFlag); err != nil { - log.Fatalf("invalid -format: %v", err) + log.Fatalf("invalid -f: %v", err) } } @@ -232,7 +232,7 @@ func main() { } // Build a list of jsonEdge records - // to print as -json or -format=template. + // to print as -json or -f=template. var edges []any for _, edge := range path { edges = append(edges, jsonEdge{ @@ -357,7 +357,7 @@ func printObjects(format string, objects []any) { return } - // -format=template. Parse can't fail: we checked it earlier. + // -f=template. Parse can't fail: we checked it earlier. tmpl := template.Must(template.New("deadcode").Parse(format)) for _, object := range objects { var buf bytes.Buffer diff --git a/internal/cmd/deadcode/doc.go b/internal/cmd/deadcode/doc.go index 3c0e7119200..8d28eb31288 100644 --- a/internal/cmd/deadcode/doc.go +++ b/internal/cmd/deadcode/doc.go @@ -64,15 +64,15 @@ With no flags, the command prints dead functions grouped by package. With the -json flag, the command prints an array of Package objects, as defined by the JSON schema (see below). -With the -format=template flag, the command executes the specified template +With the -f=template flag, the command executes the specified template on each Package record. So, this template produces a result similar to the default format: - -format='{{println .Path}}{{range .Funcs}}{{printf "\t%s\n" .RelName}}{{end}}{{println}}' + -f='{{println .Path}}{{range .Funcs}}{{printf "\t%s\n" .RelName}}{{end}}{{println}}' And this template shows only the list of source positions of dead functions: - -format='{{range .Funcs}}{{println .Posn}}{{end}}' + -f='{{range .Funcs}}{{println .Posn}}{{end}}' # Why is a function not dead? @@ -87,7 +87,7 @@ preferred over those from tests. Paths from main functions are preferred over paths from init functions. The result is a list of Edge objects (see JSON schema below). -Again, the -json and -format=template flags may be used to control +Again, the -json and -f=template flags may be used to control the formatting of the list of Edge objects. The default format shows, for each edge in the path, whether the call is static or dynamic, and its source line number. For example: diff --git a/internal/cmd/deadcode/testdata/lineflag.txtar b/internal/cmd/deadcode/testdata/lineflag.txtar index e629e0573b1..51940ad3274 100644 --- a/internal/cmd/deadcode/testdata/lineflag.txtar +++ b/internal/cmd/deadcode/testdata/lineflag.txtar @@ -1,6 +1,6 @@ # Test of line-oriented output. - deadcode "-format={{range .Funcs}}{{println .Name}}{{end}}" -filter= example.com + deadcode "-f={{range .Funcs}}{{println .Name}}{{end}}" -filter= example.com want "(example.com.T).Goodbye" !want "(example.com.T).Hello"