Skip to content

Commit

Permalink
internal/cmd/deadcode: rename -format to -f
Browse files Browse the repository at this point in the history
(following go list)

Change-Id: Ie87af973b853584082c298c339e995a8030f2d9b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/540475
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
adonovan committed Nov 7, 2023
1 parent c538b4e commit e7fb31a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions internal/cmd/deadcode/deadcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
filterFlag = flag.String("filter", "<module>", "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")
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/deadcode/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/deadcode/testdata/lineflag.txtar
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit e7fb31a

Please sign in to comment.