forked from kardianos/govendor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkg.go
50 lines (44 loc) · 1.01 KB
/
pkg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package pkgspec defines a schema that contains the path, origin, version
// and other properties.
package pkgspec
import "bytes"
type Pkg struct {
Path string
FilePath string
Origin string
IncludeTree bool
MatchTree bool
HasVersion bool
HasOrigin bool
Version string
Uncommitted bool
}
func (pkg *Pkg) String() string {
buf := &bytes.Buffer{}
buf.WriteString(pkg.Path)
if pkg.IncludeTree {
buf.WriteString(TreeIncludeSuffix)
} else if pkg.MatchTree {
buf.WriteString(TreeMatchSuffix)
}
if len(pkg.Origin) > 0 {
buf.WriteString(originMatch)
buf.WriteString(pkg.Origin)
}
if pkg.HasVersion {
buf.WriteString(versionMatch)
if len(pkg.Version) > 0 {
buf.WriteString(pkg.Version)
}
}
return buf.String()
}
func (pkg *Pkg) PathOrigin() string {
if len(pkg.Origin) > 0 {
return pkg.Origin
}
return pkg.Path
}