Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 3690bd8

Browse files
committed
internal/gps: export PruneProject and fix minor nits
Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent 20907fd commit 3690bd8

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

internal/gps/prune.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package gps
66

77
import (
8-
"fmt"
98
"log"
109
"os"
1110
"path/filepath"
@@ -23,7 +22,8 @@ const (
2322
// PruneUnusedPackages indicates if unused Go packages should be pruned.
2423
PruneUnusedPackages
2524
// PruneNonGoFiles indicates if non-Go files should be pruned.
26-
// LICENSE & COPYING files are kept for convience.
25+
// Files matching licenseFilePrefixes and legalFileSubstrings are kept to attempt to
26+
// comply with legal requirements.
2727
PruneNonGoFiles
2828
// PruneGoTestFiles indicates if Go test files should be pruned.
2929
PruneGoTestFiles
@@ -61,7 +61,7 @@ func Prune(baseDir string, options PruneOptions, l Lock, logger *log.Logger) err
6161
// TODO(ibrasho) allow passing specific options per project
6262
for _, lp := range l.Projects() {
6363
projectDir := filepath.Join(baseDir, string(lp.Ident().ProjectRoot))
64-
err := pruneProject(projectDir, lp, options, logger)
64+
err := PruneProject(projectDir, lp, options, logger)
6565
if err != nil {
6666
return err
6767
}
@@ -70,9 +70,9 @@ func Prune(baseDir string, options PruneOptions, l Lock, logger *log.Logger) err
7070
return nil
7171
}
7272

73-
// pruneProject remove excess files according to the options passed, from
73+
// PruneProject remove excess files according to the options passed, from
7474
// the lp directory in baseDir.
75-
func pruneProject(baseDir string, lp LockedProject, options PruneOptions, logger *log.Logger) error {
75+
func PruneProject(baseDir string, lp LockedProject, options PruneOptions, logger *log.Logger) error {
7676
projectDir := filepath.Join(baseDir, string(lp.Ident().ProjectRoot))
7777

7878
if (options & PruneNestedVendorDirs) != 0 {
@@ -158,7 +158,6 @@ func calculateUnusedPackages(lp LockedProject, projectDir string) (map[string]st
158158
if err != nil {
159159
return errors.Wrap(err, "unexpected error while calculating unused packages")
160160
}
161-
fmt.Println(pkg)
162161

163162
if _, ok := imported[pkg]; !ok {
164163
unused[pkg] = struct{}{}
@@ -174,7 +173,6 @@ func calculateUnusedPackages(lp LockedProject, projectDir string) (map[string]st
174173
func collectUnusedPackagesFiles(projectDir string, unusedPackages map[string]struct{}) ([]string, error) {
175174
// TODO(ibrasho): is this useful?
176175
files := make([]string, 0, len(unusedPackages))
177-
fmt.Println(unusedPackages)
178176

179177
err := filepath.Walk(projectDir, func(path string, info os.FileInfo, err error) error {
180178
if err != nil {
@@ -256,9 +254,7 @@ func collectNonGoFiles(baseDir string, logger *log.Logger) ([]string, error) {
256254
}
257255

258256
// isPreservedFile checks if the file name idicates that the file should be
259-
// preserved.
260-
// isPreservedFile checks if the file name contains one of the prefixes in
261-
// licenseFilePrefixes or contains one of the legalFileSubstrings entries.
257+
// preserved based on licenseFilePrefixes or legalFileSubstrings.
262258
func isPreservedFile(name string) bool {
263259
name = strings.ToLower(name)
264260

@@ -279,7 +275,7 @@ func isPreservedFile(name string) bool {
279275

280276
// pruneGoTestFiles deletes all Go test files (*_test.go) within baseDir.
281277
func pruneGoTestFiles(baseDir string, logger *log.Logger) error {
282-
files, err := collectGoTestsFile(baseDir)
278+
files, err := collectGoTestFiles(baseDir)
283279
if err != nil {
284280
return errors.Wrap(err, "could not collect Go test files")
285281
}
@@ -291,9 +287,9 @@ func pruneGoTestFiles(baseDir string, logger *log.Logger) error {
291287
return nil
292288
}
293289

294-
// collectGoTestsFile returns a slice contains all Go test files (any files
290+
// collectGoTestFiles returns a slice contains all Go test files (any files
295291
// prefixed with _test.go) in baseDir.
296-
func collectGoTestsFile(baseDir string) ([]string, error) {
292+
func collectGoTestFiles(baseDir string) ([]string, error) {
297293
files := make([]string, 0)
298294

299295
err := filepath.Walk(baseDir, func(path string, info os.FileInfo, err error) error {

0 commit comments

Comments
 (0)