@@ -27,22 +27,25 @@ var (
27
27
errInvalidOverride = errors .New ("\" override\" must be a TOML array of tables" )
28
28
errInvalidRequired = errors .New ("\" required\" must be a TOML list of strings" )
29
29
errInvalidIgnored = errors .New ("\" ignored\" must be a TOML list of strings" )
30
+ errInvalidPrune = errors .New ("\" prune\" must be a TOML table of boolean values" )
30
31
errInvalidProjectRoot = errors .New ("ProjectRoot name validation failed" )
31
32
)
32
33
33
34
// Manifest holds manifest file data and implements gps.RootManifest.
34
35
type Manifest struct {
35
- Constraints gps.ProjectConstraints
36
- Ovr gps.ProjectConstraints
37
- Ignored []string
38
- Required []string
36
+ Constraints gps.ProjectConstraints
37
+ Ovr gps.ProjectConstraints
38
+ Ignored []string
39
+ Required []string
40
+ PruneOptions gps.PruneOptions
39
41
}
40
42
41
43
type rawManifest struct {
42
- Constraints []rawProject `toml:"constraint,omitempty"`
43
- Overrides []rawProject `toml:"override,omitempty"`
44
- Ignored []string `toml:"ignored,omitempty"`
45
- Required []string `toml:"required,omitempty"`
44
+ Constraints []rawProject `toml:"constraint,omitempty"`
45
+ Overrides []rawProject `toml:"override,omitempty"`
46
+ Ignored []string `toml:"ignored,omitempty"`
47
+ Required []string `toml:"required,omitempty"`
48
+ PruneOptions rawPruneOptions `toml:"prune,omitempty"`
46
49
}
47
50
48
51
type rawProject struct {
@@ -53,11 +56,18 @@ type rawProject struct {
53
56
Source string `toml:"source,omitempty"`
54
57
}
55
58
59
+ type rawPruneOptions struct {
60
+ UnusedPackages bool `toml:"unused-packages,omitempty"`
61
+ NonGoFiles bool `toml:"non-go,omitempty"`
62
+ GoTests bool `toml:"go-tests,omitempty"`
63
+ }
64
+
56
65
// NewManifest instantites a new manifest.
57
66
func NewManifest () * Manifest {
58
67
return & Manifest {
59
- Constraints : make (gps.ProjectConstraints ),
60
- Ovr : make (gps.ProjectConstraints ),
68
+ Constraints : make (gps.ProjectConstraints ),
69
+ Ovr : make (gps.ProjectConstraints ),
70
+ PruneOptions : gps .PruneNestedVendorDirs ,
61
71
}
62
72
}
63
73
@@ -150,6 +160,22 @@ func validateManifest(s string) ([]error, error) {
150
160
return warns , errInvalidRequired
151
161
}
152
162
}
163
+ case "prune" :
164
+ // Check if prune is of Map type
165
+ if reflect .TypeOf (val ).Kind () != reflect .Map {
166
+ warns = append (warns , errors .New ("prune should be a TOML table" ))
167
+ }
168
+ for key , value := range val .(map [string ]interface {}) {
169
+ switch key {
170
+ case "non-go" , "go-tests" , "unused-packages" :
171
+ if _ , ok := value .(bool ); ! ok {
172
+ warns = append (warns , errors .Errorf ("unexpected type for prune.%s: %T" , key , value ))
173
+ return warns , errInvalidPrune
174
+ }
175
+ default :
176
+ warns = append (warns , errors .Errorf ("unknown field: prune.%s" , key ))
177
+ }
178
+ }
153
179
default :
154
180
warns = append (warns , fmt .Errorf ("unknown field in manifest: %v" , prop ))
155
181
}
@@ -253,6 +279,16 @@ func fromRawManifest(raw rawManifest) (*Manifest, error) {
253
279
m .Ovr [name ] = prj
254
280
}
255
281
282
+ if raw .PruneOptions .UnusedPackages {
283
+ m .PruneOptions |= gps .PruneUnusedPackages
284
+ }
285
+ if raw .PruneOptions .GoTests {
286
+ m .PruneOptions |= gps .PruneGoTestFiles
287
+ }
288
+ if raw .PruneOptions .NonGoFiles {
289
+ m .PruneOptions |= gps .PruneNonGoFiles
290
+ }
291
+
256
292
return m , nil
257
293
}
258
294
0 commit comments