Skip to content

Commit

Permalink
Renaming overrides to mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfarina committed Aug 16, 2016
1 parent 9f8eca0 commit 71b7469
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 276 deletions.
6 changes: 3 additions & 3 deletions action/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"strings"

"github.com/Masterminds/glide/cfg"
"github.com/Masterminds/glide/mirrors"
"github.com/Masterminds/glide/msg"
"github.com/Masterminds/glide/overrides"
gpath "github.com/Masterminds/glide/path"
"github.com/Masterminds/glide/util"
)
Expand Down Expand Up @@ -57,9 +57,9 @@ func EnsureConfig() *cfg.Config {
}
}

err = overrides.Load()
err = mirrors.Load()
if err != nil {
msg.Err("Unable to load overrides: %s", err)
msg.Err("Unable to load mirrors: %s", err)
}

return conf
Expand Down
146 changes: 146 additions & 0 deletions action/mirrors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package action

import (
"os"
"path/filepath"

"github.com/Masterminds/glide/mirrors"
"github.com/Masterminds/glide/msg"
gpath "github.com/Masterminds/glide/path"
)

// MirrorsList displays a list of currently setup mirrors.
func MirrorsList() error {
home := gpath.Home()

op := filepath.Join(home, "mirrors.yaml")

if _, err := os.Stat(op); os.IsNotExist(err) {
msg.Info("No mirrors exist. No mirrors.yaml file not found")
return nil
}

ov, err := mirrors.ReadMirrorsFile(op)
if err != nil {
msg.Die("Unable to read mirrors.yaml file: %s", err)
}

if len(ov.Repos) == 0 {
msg.Info("No mirrors found")
return nil
}

msg.Info("Mirrors...")
for _, r := range ov.Repos {
if r.Vcs == "" {
msg.Info("--> %s replaced by %s", r.Original, r.Repo)
} else {
msg.Info("--> %s replaced by %s (%s)", r.Original, r.Repo, r.Vcs)
}
}

return nil
}

// MirrorsSet sets a mirror to use
func MirrorsSet(o, r, v string) error {
if o == "" || r == "" {
msg.Err("Both the original and mirror values are required")
return nil
}

home := gpath.Home()

op := filepath.Join(home, "mirrors.yaml")

var ov *mirrors.Mirrors
if _, err := os.Stat(op); os.IsNotExist(err) {
msg.Info("No mirrors.yaml file exists. Creating new one")
ov = &mirrors.Mirrors{
Repos: make(mirrors.MirrorRepos, 0),
}
} else {
ov, err = mirrors.ReadMirrorsFile(op)
if err != nil {
msg.Die("Error reading existing mirrors.yaml file: %s", err)
}
}

found := false
for i, re := range ov.Repos {
if re.Original == o {
found = true
msg.Info("%s found in mirrors. Replacing with new settings", o)
ov.Repos[i].Repo = r
ov.Repos[i].Vcs = v
}
}

if !found {
nr := &mirrors.MirrorRepo{
Original: o,
Repo: r,
Vcs: v,
}
ov.Repos = append(ov.Repos, nr)
}

msg.Info("%s being set to %s", o, r)

err := ov.WriteFile(op)
if err != nil {
msg.Err("Error writing mirrors.yaml file: %s", err)
} else {
msg.Info("mirrors.yaml written with changes")
}

return nil
}

// MirrorsRemove removes a mirrors setting
func MirrorsRemove(k string) error {
if k == "" {
msg.Err("The mirror to remove is required")
return nil
}

home := gpath.Home()

op := filepath.Join(home, "mirrors.yaml")

if _, err := os.Stat(op); os.IsNotExist(err) {
msg.Err("mirrors.yaml file not found")
return nil
}

ov, err := mirrors.ReadMirrorsFile(op)
if err != nil {
msg.Die("Unable to read mirrors.yaml file: %s", err)
}

var nre mirrors.MirrorRepos
var found bool
for _, re := range ov.Repos {
if re.Original != k {
nre = append(nre, re)
} else {
found = true
}
}

if !found {
msg.Warn("%s was not found in mirrors", k)
} else {
msg.Info("%s was removed from mirrors", k)
ov.Repos = nre

err = ov.WriteFile(op)
if err != nil {
msg.Err("Error writing mirrors.yaml file: %s", err)
} else {
msg.Info("mirrors.yaml written with changes")
}
}

return nil
}
146 changes: 0 additions & 146 deletions action/overrides.go

This file was deleted.

8 changes: 4 additions & 4 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"sort"
"strings"

"github.com/Masterminds/glide/overrides"
"github.com/Masterminds/glide/mirrors"
"github.com/Masterminds/glide/util"
"github.com/Masterminds/vcs"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -461,7 +461,7 @@ func (d *Dependency) MarshalYAML() (interface{}, error) {
}

// Remote returns the remote location to fetch source from. This location is
// the central place where overrides happen from.
// the central place where mirrors can alter the location.
func (d *Dependency) Remote() string {
var r string

Expand All @@ -471,7 +471,7 @@ func (d *Dependency) Remote() string {
r = "https://" + d.Name
}

f, nr, _ := overrides.Get(r)
f, nr, _ := mirrors.Get(r)
if f {
return nr
}
Expand All @@ -489,7 +489,7 @@ func (d *Dependency) Vcs() string {
r = "https://" + d.Name
}

f, _, nv := overrides.Get(r)
f, _, nv := mirrors.Get(r)
if f {
return nv
}
Expand Down
Loading

0 comments on commit 71b7469

Please sign in to comment.