Skip to content

Commit e7fb31a

Browse files
committed
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent c538b4e commit e7fb31a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

internal/cmd/deadcode/deadcode.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var (
4343
filterFlag = flag.String("filter", "<module>", "report only packages matching this regular expression (default: module of first package)")
4444
generatedFlag = flag.Bool("generated", false, "include dead functions in generated Go files")
4545
whyLiveFlag = flag.String("whylive", "", "show a path from main to the named function")
46-
formatFlag = flag.String("format", "", "format output records using template")
46+
formatFlag = flag.String("f", "", "format output records using template")
4747
jsonFlag = flag.Bool("json", false, "output JSON records")
4848
cpuProfile = flag.String("cpuprofile", "", "write CPU profile to this file")
4949
memProfile = flag.String("memprofile", "", "write memory profile to this file")
@@ -101,10 +101,10 @@ func main() {
101101
// Reject bad output options early.
102102
if *formatFlag != "" {
103103
if *jsonFlag {
104-
log.Fatalf("you cannot specify both -format=template and -json")
104+
log.Fatalf("you cannot specify both -f=template and -json")
105105
}
106106
if _, err := template.New("deadcode").Parse(*formatFlag); err != nil {
107-
log.Fatalf("invalid -format: %v", err)
107+
log.Fatalf("invalid -f: %v", err)
108108
}
109109
}
110110

@@ -232,7 +232,7 @@ func main() {
232232
}
233233

234234
// Build a list of jsonEdge records
235-
// to print as -json or -format=template.
235+
// to print as -json or -f=template.
236236
var edges []any
237237
for _, edge := range path {
238238
edges = append(edges, jsonEdge{
@@ -357,7 +357,7 @@ func printObjects(format string, objects []any) {
357357
return
358358
}
359359

360-
// -format=template. Parse can't fail: we checked it earlier.
360+
// -f=template. Parse can't fail: we checked it earlier.
361361
tmpl := template.Must(template.New("deadcode").Parse(format))
362362
for _, object := range objects {
363363
var buf bytes.Buffer

internal/cmd/deadcode/doc.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ With no flags, the command prints dead functions grouped by package.
6464
With the -json flag, the command prints an array of Package
6565
objects, as defined by the JSON schema (see below).
6666
67-
With the -format=template flag, the command executes the specified template
67+
With the -f=template flag, the command executes the specified template
6868
on each Package record. So, this template produces a result similar to the
6969
default format:
7070
71-
-format='{{println .Path}}{{range .Funcs}}{{printf "\t%s\n" .RelName}}{{end}}{{println}}'
71+
-f='{{println .Path}}{{range .Funcs}}{{printf "\t%s\n" .RelName}}{{end}}{{println}}'
7272
7373
And this template shows only the list of source positions of dead functions:
7474
75-
-format='{{range .Funcs}}{{println .Posn}}{{end}}'
75+
-f='{{range .Funcs}}{{println .Posn}}{{end}}'
7676
7777
# Why is a function not dead?
7878
@@ -87,7 +87,7 @@ preferred over those from tests. Paths from main functions are
8787
preferred over paths from init functions.
8888
8989
The result is a list of Edge objects (see JSON schema below).
90-
Again, the -json and -format=template flags may be used to control
90+
Again, the -json and -f=template flags may be used to control
9191
the formatting of the list of Edge objects.
9292
The default format shows, for each edge in the path, whether the call
9393
is static or dynamic, and its source line number. For example:

internal/cmd/deadcode/testdata/lineflag.txtar

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Test of line-oriented output.
22

3-
deadcode "-format={{range .Funcs}}{{println .Name}}{{end}}" -filter= example.com
3+
deadcode "-f={{range .Funcs}}{{println .Name}}{{end}}" -filter= example.com
44

55
want "(example.com.T).Goodbye"
66
!want "(example.com.T).Hello"

0 commit comments

Comments
 (0)