Skip to content
This repository was archived by the owner on Mar 25, 2024. It is now read-only.

Commit 998f6ef

Browse files
author
Daishan Peng
committed
add packages function
1 parent 8563489 commit 998f6ef

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

conf/conf.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Conf struct {
1515
Package string `yaml:"package,omitempty"`
1616
Imports []Import `yaml:"import,omitempty"`
1717
Excludes []string `yaml:"exclude,omitempty"`
18+
Packages []string `yaml:"packages,omitempty"`
1819
ImportMap map[string]Import `yaml:"-"`
1920
confFile string `yaml:"-"`
2021
yamlType bool `yaml:"-"`
@@ -25,7 +26,7 @@ type Import struct {
2526
Version string `yaml:"version,omitempty"`
2627
Repo string `yaml:"repo,omitempty"`
2728
Update bool `yaml:"-"`
28-
Options `yaml:"-"`
29+
Options `yaml:",inline"`
2930
}
3031

3132
type Options struct {
@@ -79,6 +80,11 @@ func Parse(path string) (*Conf, error) {
7980
continue
8081
}
8182

83+
if strings.HasPrefix(fields[0], "package=") {
84+
trashConf.Packages = append(trashConf.Packages, strings.TrimPrefix(fields[0], "package="))
85+
continue
86+
}
87+
8288
// Otherwise it's an import pattern
8389
packageImport := Import{}
8490
packageImport.Package = fields[0] // at least 1 field at this point: trimmed the line and skipped empty

trash.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,10 @@ func cleanup(update bool, dir, targetDir string, trashConf *conf.Conf) error {
983983
if err := removeExcludes(trashConf.Excludes, targetDir); err != nil {
984984
logrus.Errorf("Error removing excluded dirs: %v", err)
985985
}
986+
for _, im := range trashConf.Packages {
987+
logrus.Infof("Must include package %s", im)
988+
imports[im] = true
989+
}
986990
if err := removeUnusedImports(imports, targetDir, updatePackages); err != nil {
987991
logrus.Errorf("Error removing unused dirs: %v", err)
988992
}

0 commit comments

Comments
 (0)