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

Commit 4070c2b

Browse files
Merge pull request #87 from StrongMonkey/master
add ability to remove vendor when running trash -k
2 parents 1ffd3be + 2c286aa commit 4070c2b

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

conf/conf.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ type Import struct {
2929
Options `yaml:",inline"`
3030
}
3131

32+
type Imports []Import
33+
34+
func (i Imports) Len() int {
35+
return len(i)
36+
}
37+
38+
func (i Imports) Less(k, j int) bool {
39+
return strings.Compare(i[k].Package, i[j].Package) <= 0
40+
}
41+
42+
func (i Imports) Swap(k, j int) {
43+
tmp := i[j]
44+
i[j] = i[k]
45+
i[k] = tmp
46+
return
47+
}
48+
3249
type Options struct {
3350
Transitive bool `yaml:"transitive,omitempty"`
3451
Staging bool `yaml:"staging,omitempty"`

trash.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os/exec"
1313
"path"
1414
"path/filepath"
15+
"sort"
1516
"strings"
1617

1718
"github.com/Sirupsen/logrus"
@@ -73,6 +74,10 @@ func main() {
7374
Hidden: true,
7475
EnvVar: "GOPATH",
7576
},
77+
cli.BoolFlag{
78+
Name: "include-vendor",
79+
Usage: "whether to include vendor when running trash -k",
80+
},
7681
}
7782
app.Action = runWrapper
7883

@@ -101,6 +106,7 @@ func run(c *cli.Context) error {
101106
insecure := c.Bool("insecure")
102107
trashDir := c.String("cache")
103108
gopath = c.String("gopath")
109+
includeVendor := c.Bool("include-vendor")
104110

105111
update := false
106112
updateVendor := c.StringSlice("update")
@@ -218,6 +224,24 @@ func run(c *cli.Context) error {
218224
}
219225

220226
if keep {
227+
if !includeVendor {
228+
wd, err := os.Getwd()
229+
if err != nil {
230+
return err
231+
}
232+
root := filepath.Join(wd, "vendor")
233+
return filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
234+
if err != nil {
235+
return filepath.SkipDir
236+
}
237+
if info.IsDir() && info.Name() == "vendor" && path != root {
238+
logrus.Infof("Removing %s", path)
239+
os.RemoveAll(path)
240+
return filepath.SkipDir
241+
}
242+
return nil
243+
})
244+
}
221245
return nil
222246
}
223247
return cleanup(update, dir, targetDir, trashConf)
@@ -1010,6 +1034,7 @@ func cleanup(update bool, dir, targetDir string, trashConf *conf.Conf) error {
10101034
writeConf.Imports = append(writeConf.Imports, i)
10111035
}
10121036
}
1037+
sort.Sort(conf.Imports(writeConf.Imports))
10131038
data, err := yaml.Marshal(writeConf)
10141039
if err != nil {
10151040
return err

trash.lock

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package: github.com/rancher/trash
2+
import:
3+
- package: github.com/Masterminds/glide
4+
version: fb6c62596ce1b29128f1ef7e329c367a648ee9b1
5+
repo: https://github.com/StrongMonkey/glide.git
6+
- package: github.com/Masterminds/vcs
7+
version: v1.12.0
8+
- package: github.com/Sirupsen/logrus
9+
version: v0.10.0
10+
- package: github.com/cloudfoundry-incubator/candiedyaml
11+
version: 99c3df8
12+
- package: github.com/davecgh/go-spew
13+
version: 5215b55
14+
- package: github.com/mitchellh/go-homedir
15+
version: b8bc1bf767474819792c23f32d8286a45736f1c6
16+
- package: github.com/pmezard/go-difflib
17+
version: 792786c
18+
- package: github.com/stretchr/testify
19+
version: v1.1.3
20+
- package: github.com/urfave/cli
21+
version: v1.18.0
22+
- package: golang.org/x/sys
23+
version: a408501
24+
- package: gopkg.in/yaml.v2
25+
version: eb3733d160e74a9c7e442f435eb3bea458e1d19f

0 commit comments

Comments
 (0)