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

Commit

Permalink
add packages function
Browse files Browse the repository at this point in the history
  • Loading branch information
Daishan Peng committed Aug 2, 2018
1 parent 8563489 commit 998f6ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Conf struct {
Package string `yaml:"package,omitempty"`
Imports []Import `yaml:"import,omitempty"`
Excludes []string `yaml:"exclude,omitempty"`
Packages []string `yaml:"packages,omitempty"`
ImportMap map[string]Import `yaml:"-"`
confFile string `yaml:"-"`
yamlType bool `yaml:"-"`
Expand All @@ -25,7 +26,7 @@ type Import struct {
Version string `yaml:"version,omitempty"`
Repo string `yaml:"repo,omitempty"`
Update bool `yaml:"-"`
Options `yaml:"-"`
Options `yaml:",inline"`
}

type Options struct {
Expand Down Expand Up @@ -79,6 +80,11 @@ func Parse(path string) (*Conf, error) {
continue
}

if strings.HasPrefix(fields[0], "package=") {
trashConf.Packages = append(trashConf.Packages, strings.TrimPrefix(fields[0], "package="))
continue
}

// Otherwise it's an import pattern
packageImport := Import{}
packageImport.Package = fields[0] // at least 1 field at this point: trimmed the line and skipped empty
Expand Down
4 changes: 4 additions & 0 deletions trash.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,10 @@ func cleanup(update bool, dir, targetDir string, trashConf *conf.Conf) error {
if err := removeExcludes(trashConf.Excludes, targetDir); err != nil {
logrus.Errorf("Error removing excluded dirs: %v", err)
}
for _, im := range trashConf.Packages {
logrus.Infof("Must include package %s", im)
imports[im] = true
}
if err := removeUnusedImports(imports, targetDir, updatePackages); err != nil {
logrus.Errorf("Error removing unused dirs: %v", err)
}
Expand Down

0 comments on commit 998f6ef

Please sign in to comment.