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

Commit 88b2cc6

Browse files
authored
Merge pull request #44 from imikushin/vendor-conf
Cleanup: rename trash.conf to vendor.conf in messages and readme
2 parents 6f78de3 + 5c0fedd commit 88b2cc6

File tree

5 files changed

+42
-41
lines changed

5 files changed

+42
-41
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Keeping the trash in your ./vendor dir to a minimum.
77
Make sure you're using go1.6 or later version.
88

99
0. Download and extract `trash` to your PATH
10-
1. Copy `trash.conf` file to your project and edit to your needs.
10+
1. Copy `vendor.conf` file to your project and edit to your needs.
1111
2. Run `trash`
1212

13-
`trash.conf` (in your project root dir) specifies the revisions (git tags or commits, or branches - if you're drunk) of the libraries to be fetched, checked out and copied to ./vendor dir. For example:
13+
`vendor.conf` (in your project root dir) specifies the revisions (git tags or commits, or branches - if you're drunk) of the libraries to be fetched, checked out and copied to ./vendor dir. For example:
1414
```
1515
github.com/rancher/trash
1616
@@ -46,7 +46,7 @@ I'd been slightly reluctant to the idea of writing it, but apparently the world
4646

4747
## Help
4848

49-
For the world's convenience, `trash` can detect glide.yaml (and glide.yml, as well as trash.yaml) and use that instead of trash.conf (and you can Force it to use any other file). Just in case, here's the program help:
49+
For the world's convenience, `trash` can detect glide.yaml (and glide.yml, as well as trash.yaml) and use that instead of vendor.conf (and you can Force it to use any other file). Just in case, here's the program help:
5050

5151
```
5252
$ trash -h
@@ -66,7 +66,7 @@ COMMANDS:
6666
help, h Shows a list of commands or help for one command
6767
6868
GLOBAL OPTIONS:
69-
--file value, -f value Vendored packages list (default: "trash.conf")
69+
--file value, -f value Vendored packages list (default: "vendor.conf")
7070
--directory value, -C value The directory in which to run, --file is relative to this (default: ".")
7171
--keep, -k Keep all downloaded vendor code (preserving .git dirs)
7272
--update, -u Update vendored packages, add missing ones

conf/conf.go

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import (
1111
yaml "github.com/cloudfoundry-incubator/candiedyaml"
1212
)
1313

14-
type Trash struct {
14+
type Conf struct {
1515
Package string `yaml:"package,omitempty"`
1616
Imports []Import `yaml:"import,omitempty"`
1717
importMap map[string]Import
18+
confFile string
1819
}
1920

2021
type Import struct {
@@ -23,20 +24,20 @@ type Import struct {
2324
Repo string `yaml:"repo,omitempty"`
2425
}
2526

26-
func Parse(path string) (*Trash, error) {
27+
func Parse(path string) (*Conf, error) {
2728
file, err := os.Open(path)
2829
if err != nil {
2930
return nil, err
3031
}
3132
defer file.Close()
3233

33-
trash := &Trash{}
34-
if err := yaml.NewDecoder(file).Decode(trash); err == nil {
35-
trash.Dedupe()
36-
return trash, nil
34+
trashConf := &Conf{confFile: path}
35+
if err := yaml.NewDecoder(file).Decode(trashConf); err == nil {
36+
trashConf.Dedupe()
37+
return trashConf, nil
3738
}
3839

39-
trash = &Trash{}
40+
trashConf = &Conf{confFile: path}
4041
_, err = file.Seek(0, 0)
4142
if err != nil {
4243
return nil, err
@@ -53,9 +54,9 @@ func Parse(path string) (*Trash, error) {
5354
}
5455
fields := strings.Fields(line)
5556

56-
if len(fields) == 1 && trash.Package == "" {
57-
trash.Package = fields[0] // use the first 1-field line as the root package
58-
logrus.Infof("Using '%s' as the project's root package (from trash.conf)", trash.Package)
57+
if len(fields) == 1 && trashConf.Package == "" {
58+
trashConf.Package = fields[0] // use the first 1-field line as the root package
59+
logrus.Infof("Using '%s' as the project's root package (from %s)", trashConf.Package, trashConf.confFile)
5960
continue
6061
}
6162

@@ -67,19 +68,19 @@ func Parse(path string) (*Trash, error) {
6768
if len(fields) > 1 {
6869
packageImport.Version = fields[1]
6970
}
70-
trash.Imports = append(trash.Imports, packageImport)
71+
trashConf.Imports = append(trashConf.Imports, packageImport)
7172
}
7273

73-
trash.Dedupe()
74-
return trash, nil
74+
trashConf.Dedupe()
75+
return trashConf, nil
7576
}
7677

7778
// Dedupe deletes duplicates and sorts the imports
78-
func (t *Trash) Dedupe() {
79+
func (t *Conf) Dedupe() {
7980
t.importMap = map[string]Import{}
8081
for _, i := range t.Imports {
8182
if _, ok := t.importMap[i.Package]; ok {
82-
logrus.Debugf("Package '%s' has duplicates (in trash.conf)", i.Package)
83+
logrus.Debugf("Package '%s' has duplicates (in %s)", i.Package, t.confFile)
8384
continue
8485
}
8586
t.importMap[i.Package] = i
@@ -96,12 +97,12 @@ func (t *Trash) Dedupe() {
9697
t.Imports = imports
9798
}
9899

99-
func (t *Trash) Get(pkg string) (Import, bool) {
100+
func (t *Conf) Get(pkg string) (Import, bool) {
100101
i, ok := t.importMap[pkg]
101102
return i, ok
102103
}
103104

104-
func (t *Trash) Dump(path string) error {
105+
func (t *Conf) Dump(path string) error {
105106
file, err := os.Create(path)
106107
defer file.Close()
107108
if err != nil {
@@ -111,8 +112,6 @@ func (t *Trash) Dump(path string) error {
111112
w := bufio.NewWriter(file)
112113
defer w.Flush()
113114

114-
fmt.Fprintln(w, "# trash.conf")
115-
fmt.Fprintln(w)
116115
fmt.Fprintln(w, "# package")
117116
fmt.Fprintln(w, t.Package)
118117
fmt.Fprintln(w)
@@ -124,3 +123,7 @@ func (t *Trash) Dump(path string) error {
124123

125124
return nil
126125
}
126+
127+
func (t *Conf) ConfFile() string {
128+
return t.confFile
129+
}

conf/conf_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestDuplicates(t *testing.T) {
3939
}
4040

4141
for i, d := range testData {
42-
trash := Trash{"", d.imports, nil}
42+
trash := Conf{"", d.imports, nil}
4343
trash.Dedupe()
4444

4545
if d.duplicates != len(d.imports)-len(trash.Imports) {

trash.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func run(c *cli.Context) error {
7474
}
7575

7676
dir := c.String("directory")
77-
trashFile := c.String("file")
77+
confFile := c.String("file")
7878
keep := c.Bool("keep")
7979
update := c.Bool("update")
8080
trashDir := c.String("cache")
@@ -94,30 +94,30 @@ func run(c *cli.Context) error {
9494
}
9595
logrus.Debugf("dir: '%s'", dir)
9696

97-
for _, trashFile = range []string{trashFile, "trash.conf", "vndr.cfg", "vendor.manifest", "trash.yml", "glide.yaml", "glide.yml", "trash.yaml"} {
98-
if _, err = os.Stat(trashFile); err == nil {
97+
for _, confFile = range []string{confFile, "trash.conf", "vndr.cfg", "vendor.manifest", "trash.yml", "glide.yaml", "glide.yml", "trash.yaml"} {
98+
if _, err = os.Stat(confFile); err == nil {
9999
break
100100
}
101101
}
102102
if err != nil {
103103
if os.IsNotExist(err) && update {
104-
trashFile = c.String("file")
105-
logrus.Warnf("Trash! '%s' not found, creating a new one!", trashFile)
106-
if _, err = os.Create(trashFile); err != nil {
104+
confFile = c.String("file")
105+
logrus.Warnf("Trash! '%s' not found, creating a new one!", confFile)
106+
if _, err = os.Create(confFile); err != nil {
107107
return err
108108
}
109109
} else {
110110
return err
111111
}
112112
}
113-
logrus.Infof("Trash! Reading file: '%s'", trashFile)
113+
logrus.Infof("Trash! Reading file: '%s'", confFile)
114114

115-
trashConf, err := conf.Parse(trashFile)
115+
trashConf, err := conf.Parse(confFile)
116116
if err != nil {
117117
return err
118118
}
119119
if update {
120-
return updateTrash(trashDir, dir, trashFile, trashConf)
120+
return updateTrash(trashDir, dir, confFile, trashConf)
121121
}
122122
if err := vendor(keep, trashDir, dir, trashConf); err != nil {
123123
return err
@@ -128,7 +128,7 @@ func run(c *cli.Context) error {
128128
return cleanup(dir, trashConf)
129129
}
130130

131-
func updateTrash(trashDir, dir, trashFile string, trashConf *conf.Trash) error {
131+
func updateTrash(trashDir, dir, trashFile string, trashConf *conf.Conf) error {
132132
// TODO collect imports, create `trashConf *conf.Trash`
133133
rootPackage := trashConf.Package
134134
if rootPackage == "" {
@@ -161,7 +161,7 @@ func updateTrash(trashDir, dir, trashFile string, trashConf *conf.Trash) error {
161161
imports = collectImports(rootPackage, libRoot)
162162
}
163163

164-
trashConf = &conf.Trash{Package: rootPackage}
164+
trashConf = &conf.Conf{Package: rootPackage}
165165
for pkg := range imports {
166166
if pkg == rootPackage || strings.HasPrefix(pkg, rootPackage+"/") {
167167
continue
@@ -213,7 +213,7 @@ func getLatestVersion(libRoot, pkg string) (string, error) {
213213
return s, nil
214214
}
215215

216-
func vendor(keep bool, trashDir, dir string, trashConf *conf.Trash) error {
216+
func vendor(keep bool, trashDir, dir string, trashConf *conf.Conf) error {
217217
logrus.WithFields(logrus.Fields{"keep": keep, "dir": dir, "trashConf": trashConf}).Debug("vendor")
218218
defer os.Chdir(dir)
219219

@@ -647,7 +647,7 @@ func removeEmptyDirs() error {
647647
}
648648

649649
func guessRootPackage(dir string) string {
650-
logrus.Warn("Trying to guess the root package using GOPATH. It's best to specify it in `trash.conf`")
650+
logrus.Warn("Trying to guess the root package using GOPATH. It's best to specify it in `vendor.conf`")
651651
logrus.Warnf("GOPATH is '%s'", gopath)
652652
if gopath == "" || strings.Contains(gopath, ":") {
653653
logrus.Fatalf("GOPATH not set or is not a single path. You need to specify the root package!")
@@ -663,7 +663,7 @@ func guessRootPackage(dir string) string {
663663
return dir[len(srcPath+"/"):]
664664
}
665665

666-
func cleanup(dir string, trashConf *conf.Trash) error {
666+
func cleanup(dir string, trashConf *conf.Conf) error {
667667
rootPackage := trashConf.Package
668668
if rootPackage == "" {
669669
rootPackage = guessRootPackage(dir)
@@ -683,7 +683,7 @@ func cleanup(dir string, trashConf *conf.Trash) error {
683683
for _, i := range trashConf.Imports {
684684
if _, err := os.Stat(dir + "/vendor/" + i.Package); err != nil {
685685
if os.IsNotExist(err) {
686-
logrus.Warnf("Package '%s' has been completely removed: it's probably useless (in trash.conf)", i.Package)
686+
logrus.Warnf("Package '%s' has been completely removed: it's probably useless (in %s)", i.Package, trashConf.ConfFile())
687687
} else {
688688
logrus.Errorf("os.Stat() failed for: %s", dir+"/vendor/"+i.Package)
689689
}

trash.conf renamed to vendor.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# trash.conf
2-
31
# package
42
github.com/rancher/trash
53

0 commit comments

Comments
 (0)