1
0
mirror of https://github.com/golang/go synced 2024-11-18 09:04:49 -07:00

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>
This commit is contained in:
Ian Cottrell 2019-05-02 13:04:19 -04:00
parent 2346320968
commit 83df196e57

View File

@ -7,6 +7,7 @@ package span
import (
"encoding/json"
"fmt"
"path"
)
// Span represents a source code range in standardized form.
@ -167,7 +168,9 @@ func (s Span) Format(f fmt.State, c rune) {
// 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
}