internal/span: add a filename only print for spans
This prints the base of the path rather than the whole path when printing a
span.
This is useful for places where you are printing for the user rather than for
machines.
The format is %f
Change-Id: I6d1a52e4583099ff298c1fb645272578a49472eb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/174942
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/span/span.go b/internal/span/span.go
index b5733252..7719257 100644
--- a/internal/span/span.go
+++ b/internal/span/span.go
@@ -7,6 +7,7 @@
import (
"encoding/json"
"fmt"
+ "path"
)
// Span represents a source code range in standardized form.
@@ -167,7 +168,9 @@
// we should always have a uri, simplify if it is file format
//TODO: make sure the end of the uri is unambiguous
uri := string(s.v.URI)
- if !fullForm {
+ if c == 'f' {
+ uri = path.Base(uri)
+ } else if !fullForm {
if filename, err := s.v.URI.Filename(); err == nil {
uri = filename
}