pkger/paths/path.go

40 lines
616 B
Go
Raw Normal View History

2019-08-01 19:03:12 +03:00
package paths
import (
2019-08-02 00:35:42 +03:00
"encoding/json"
2019-08-01 19:03:12 +03:00
"fmt"
2019-08-02 00:35:42 +03:00
"os"
2019-08-01 19:03:12 +03:00
)
type Path struct {
Pkg string `json:"pkg"`
Name string `json:"name"`
}
func (p Path) String() string {
2019-08-02 00:35:42 +03:00
if p.Name == "" {
p.Name = "/"
2019-08-01 19:03:12 +03:00
}
2019-08-02 00:35:42 +03:00
return fmt.Sprintf("%s:%s", p.Pkg, p.Name)
2019-08-01 19:03:12 +03:00
}
2019-08-02 00:35:42 +03:00
func (p Path) Format(st fmt.State, verb rune) {
switch verb {
case 'v':
if st.Flag('+') {
b, err := json.MarshalIndent(p, "", " ")
if err != nil {
fmt.Fprint(os.Stderr, err)
return
}
fmt.Fprint(st, string(b))
return
2019-08-01 19:03:12 +03:00
}
2019-08-02 00:35:42 +03:00
fmt.Fprint(st, p.String())
case 'q':
fmt.Fprintf(st, "%q", p.String())
default:
fmt.Fprint(st, p.String())
2019-08-01 19:03:12 +03:00
}
}