Renaming overrides to mirrors
diff --git a/action/ensure.go b/action/ensure.go
index a2254a6..2933c1c 100644
--- a/action/ensure.go
+++ b/action/ensure.go
@@ -9,8 +9,8 @@
"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"
)
@@ -57,9 +57,9 @@
}
}
- 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
diff --git a/action/mirrors.go b/action/mirrors.go
new file mode 100644
index 0000000..edb3bed
--- /dev/null
+++ b/action/mirrors.go
@@ -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
+}
diff --git a/action/overrides.go b/action/overrides.go
deleted file mode 100644
index de87f61..0000000
--- a/action/overrides.go
+++ /dev/null
@@ -1,146 +0,0 @@
-package action
-
-import (
- "os"
- "path/filepath"
-
- "github.com/Masterminds/glide/msg"
- "github.com/Masterminds/glide/overrides"
- gpath "github.com/Masterminds/glide/path"
-)
-
-// OverridesList displays a list of currently setup overrides.
-func OverridesList() error {
- home := gpath.Home()
-
- op := filepath.Join(home, "overrides.yaml")
-
- if _, err := os.Stat(op); os.IsNotExist(err) {
- msg.Info("No overrides exist. No overrides.yaml file not found")
- return nil
- }
-
- ov, err := overrides.ReadOverridesFile(op)
- if err != nil {
- msg.Die("Unable to read overrides.yaml file: %s", err)
- }
-
- if len(ov.Repos) == 0 {
- msg.Info("No overrides found")
- return nil
- }
-
- msg.Info("Overrides...")
- 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
-}
-
-// OverridesSet sets an override to use
-func OverridesSet(o, r, v string) error {
- if o == "" || r == "" {
- msg.Err("Both the original and overriding values are required")
- return nil
- }
-
- home := gpath.Home()
-
- op := filepath.Join(home, "overrides.yaml")
-
- var ov *overrides.Overrides
- if _, err := os.Stat(op); os.IsNotExist(err) {
- msg.Info("No overrides.yaml file exists. Creating new one")
- ov = &overrides.Overrides{
- Repos: make(overrides.OverrideRepos, 0),
- }
- } else {
- ov, err = overrides.ReadOverridesFile(op)
- if err != nil {
- msg.Die("Error reading existing overrides.yaml file: %s", err)
- }
- }
-
- found := false
- for i, re := range ov.Repos {
- if re.Original == o {
- found = true
- msg.Info("%s found in overrides. Replacing with new settings", o)
- ov.Repos[i].Repo = r
- ov.Repos[i].Vcs = v
- }
- }
-
- if !found {
- nr := &overrides.OverrideRepo{
- 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 overrides.yaml file: %s", err)
- } else {
- msg.Info("overrides.yaml written with changes")
- }
-
- return nil
-}
-
-// OverridesRemove removes an override setting
-func OverridesRemove(k string) error {
- if k == "" {
- msg.Err("The override to remove is required")
- return nil
- }
-
- home := gpath.Home()
-
- op := filepath.Join(home, "overrides.yaml")
-
- if _, err := os.Stat(op); os.IsNotExist(err) {
- msg.Err("overrides.yaml file not found")
- return nil
- }
-
- ov, err := overrides.ReadOverridesFile(op)
- if err != nil {
- msg.Die("Unable to read overrides.yaml file: %s", err)
- }
-
- var nre overrides.OverrideRepos
- 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 overrides", k)
- } else {
- msg.Info("%s was removed from overrides", k)
- ov.Repos = nre
-
- err = ov.WriteFile(op)
- if err != nil {
- msg.Err("Error writing overrides.yaml file: %s", err)
- } else {
- msg.Info("overrides.yaml written with changes")
- }
- }
-
- return nil
-}
diff --git a/cfg/config.go b/cfg/config.go
index 49b3c65..ae01039 100644
--- a/cfg/config.go
+++ b/cfg/config.go
@@ -8,7 +8,7 @@
"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"
@@ -461,7 +461,7 @@
}
// 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
@@ -471,7 +471,7 @@
r = "https://" + d.Name
}
- f, nr, _ := overrides.Get(r)
+ f, nr, _ := mirrors.Get(r)
if f {
return nr
}
@@ -489,7 +489,7 @@
r = "https://" + d.Name
}
- f, _, nv := overrides.Get(r)
+ f, _, nv := mirrors.Get(r)
if f {
return nv
}
diff --git a/glide.go b/glide.go
index 2609a24..ce39ede 100644
--- a/glide.go
+++ b/glide.go
@@ -761,62 +761,62 @@
},
},
{
- Name: "override",
- Usage: "Manage overrides",
- Description: `Overrides provide the ability to replace a repo location with
- another location. This is useful when you want to have a cache for your
- continious integration (CI) system or if you want to work on a dependency
- in a local location, such as the GOPATH.
+ Name: "mirror",
+ Usage: "Manage mirrors",
+ Description: `Mirrors provide the ability to replace a repo location with
+ another location that's a mirror of the original. This is useful when you want
+ to have a cache for your continious integration (CI) system or if you want to
+ work on a dependency in a local location.
- The overrides are stored in an overrides.yaml file in your GLIDE_HOME.
+ The mirrors are stored in an mirrors.yaml file in your GLIDE_HOME.
- The three commands to manager overrides are 'list', 'set', and 'remove'.
+ The three commands to manager mirrors are 'list', 'set', and 'remove'.
Use 'set' in the form:
- glide override set [original] [replacement]
+ glide mirror set [original] [replacement]
or
- glide override set [original] [replacement] --vcs [type]
+ glide mirror set [original] [replacement] --vcs [type]
for example,
- glide override set https://github.com/example/foo https://git.example.com/example/foo.git
+ glide mirror set https://github.com/example/foo https://git.example.com/example/foo.git
- glide override set https://github.com/example/foo file:///path/to/local/repo --vcs git
+ glide mirror set https://github.com/example/foo file:///path/to/local/repo --vcs git
Use 'remove' in the form:
- glide override remove [original]
+ glide mirror remove [original]
for example,
- glide override remove https://github.com/example/foo`,
+ glide mirror remove https://github.com/example/foo`,
Subcommands: []cli.Command{
{
Name: "list",
- Usage: "List the current overrides",
+ Usage: "List the current mirrors",
Action: func(c *cli.Context) error {
- return action.OverridesList()
+ return action.MirrorsList()
},
},
{
Name: "set",
- Usage: "Set an override. This overwrites an existing entry if one exists",
+ Usage: "Set a mirror. This overwrites an existing entry if one exists",
Description: `Use 'set' in the form:
- glide override set [original] [replacement]
+ glide mirror set [original] [replacement]
or
- glide override set [original] [replacement] --vcs [type]
+ glide mirror set [original] [replacement] --vcs [type]
for example,
- glide override set https://github.com/example/foo https://git.example.com/example/foo.git
+ glide mirror set https://github.com/example/foo https://git.example.com/example/foo.git
- glide override set https://github.com/example/foo file:///path/to/local/repo --vcs git`,
+ glide mirror set https://github.com/example/foo file:///path/to/local/repo --vcs git`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "vcs",
@@ -824,22 +824,22 @@
},
},
Action: func(c *cli.Context) error {
- return action.OverridesSet(c.Args().Get(0), c.Args().Get(1), c.String("vcs"))
+ return action.MirrorsSet(c.Args().Get(0), c.Args().Get(1), c.String("vcs"))
},
},
{
Name: "remove",
ShortName: "rm",
- Usage: "Remove an override",
+ Usage: "Remove an mirror",
Description: `Use 'remove' in the form:
- glide override remove [original]
+ glide mirror remove [original]
for example,
- glide override remove https://github.com/example/foo`,
+ glide mirror remove https://github.com/example/foo`,
Action: func(c *cli.Context) error {
- return action.OverridesRemove(c.Args().Get(0))
+ return action.MirrorsRemove(c.Args().Get(0))
},
},
},
diff --git a/mirrors/cfg.go b/mirrors/cfg.go
new file mode 100644
index 0000000..f749c9d
--- /dev/null
+++ b/mirrors/cfg.go
@@ -0,0 +1,98 @@
+package mirrors
+
+import (
+ "io/ioutil"
+ "sort"
+ "strings"
+
+ "gopkg.in/yaml.v2"
+)
+
+// Mirrors contains global mirrors to local configuration
+type Mirrors struct {
+
+ // Repos contains repo mirror configuration
+ Repos MirrorRepos `yaml:"repos"`
+}
+
+// Marshal converts a Mirror instance to YAML
+func (ov *Mirrors) Marshal() ([]byte, error) {
+ yml, err := yaml.Marshal(&ov)
+ if err != nil {
+ return []byte{}, err
+ }
+ return yml, nil
+}
+
+// WriteFile writes an mirrors.yaml file
+//
+// This is a convenience function that marshals the YAML and then writes it to
+// the given file. If the file exists, it will be clobbered.
+func (ov *Mirrors) WriteFile(opath string) error {
+ o, err := ov.Marshal()
+ if err != nil {
+ return err
+ }
+ return ioutil.WriteFile(opath, o, 0666)
+}
+
+// ReadMirrorsFile loads the contents of an mirrors.yaml file.
+func ReadMirrorsFile(opath string) (*Mirrors, error) {
+ yml, err := ioutil.ReadFile(opath)
+ if err != nil {
+ return nil, err
+ }
+ ov, err := FromYaml(yml)
+ if err != nil {
+ return nil, err
+ }
+ return ov, nil
+}
+
+// FromYaml returns an instance of Mirrors from YAML
+func FromYaml(yml []byte) (*Mirrors, error) {
+ ov := &Mirrors{}
+ err := yaml.Unmarshal([]byte(yml), &ov)
+ return ov, err
+}
+
+// MarshalYAML is a hook for gopkg.in/yaml.v2.
+// It sorts mirror repos lexicographically for reproducibility.
+func (ov *Mirrors) MarshalYAML() (interface{}, error) {
+
+ sort.Sort(ov.Repos)
+
+ return ov, nil
+}
+
+// MirrorRepos is a slice of Mirror pointers
+type MirrorRepos []*MirrorRepo
+
+// Len returns the length of the MirrorRepos. This is needed for sorting with
+// the sort package.
+func (o MirrorRepos) Len() int {
+ return len(o)
+}
+
+// Less is needed for the sort interface. It compares two MirrorRepos based on
+// their original value.
+func (o MirrorRepos) Less(i, j int) bool {
+
+ // Names are normalized to lowercase because case affects sorting order. For
+ // example, Masterminds comes before kylelemons. Making them lowercase
+ // causes kylelemons to come first which is what is expected.
+ return strings.ToLower(o[i].Original) < strings.ToLower(o[j].Original)
+}
+
+// Swap is needed for the sort interface. It swaps the position of two
+// MirrorRepos.
+func (o MirrorRepos) Swap(i, j int) {
+ o[i], o[j] = o[j], o[i]
+}
+
+// MirrorRepo represents a single repo mirror
+type MirrorRepo struct {
+ Original string `yaml:"original"`
+ Repo string `yaml:"repo"`
+ Vcs string `yaml:"vcs,omitempty"`
+}
diff --git a/mirrors/mirrors.go b/mirrors/mirrors.go
new file mode 100644
index 0000000..e762a05
--- /dev/null
+++ b/mirrors/mirrors.go
@@ -0,0 +1,66 @@
+// Package mirrors handles managing mirrors in the running application
+package mirrors
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "github.com/Masterminds/glide/msg"
+ gpath "github.com/Masterminds/glide/path"
+)
+
+var mirrors map[string]*mirror
+
+func init() {
+ mirrors = make(map[string]*mirror)
+}
+
+type mirror struct {
+ Repo, Vcs string
+}
+
+// Get retrieves informtion about an mirror. It returns.
+// - bool if found
+// - new repo location
+// - vcs type
+func Get(k string) (bool, string, string) {
+ o, f := mirrors[k]
+ if !f {
+ return false, "", ""
+ }
+
+ return true, o.Repo, o.Vcs
+}
+
+// Load pulls the mirrors into memory
+func Load() error {
+ home := gpath.Home()
+
+ op := filepath.Join(home, "mirrors.yaml")
+
+ var ov *Mirrors
+ if _, err := os.Stat(op); os.IsNotExist(err) {
+ msg.Debug("No mirrors.yaml file exists")
+ ov = &Mirrors{
+ Repos: make(MirrorRepos, 0),
+ }
+ } else {
+ ov, err = ReadMirrorsFile(op)
+ if err != nil {
+ return fmt.Errorf("Error reading existing mirrors.yaml file: %s", err)
+ }
+ }
+
+ msg.Info("Loading mirrors from mirrors.yaml file")
+ for _, o := range ov.Repos {
+ msg.Debug("Found mirror: %s to %s (%s)", o.Original, o.Repo, o.Vcs)
+ no := &mirror{
+ Repo: o.Repo,
+ Vcs: o.Vcs,
+ }
+ mirrors[o.Original] = no
+ }
+
+ return nil
+}
diff --git a/overrides/overrides_test.go b/mirrors/mirrors_test.go
similarity index 73%
rename from overrides/overrides_test.go
rename to mirrors/mirrors_test.go
index dddc500..bb01bb2 100644
--- a/overrides/overrides_test.go
+++ b/mirrors/mirrors_test.go
@@ -1,4 +1,4 @@
-package overrides
+package mirrors
import "testing"
@@ -19,18 +19,18 @@
vcs: git
`
-func TestSortOverrides(t *testing.T) {
+func TestSortMirrors(t *testing.T) {
ov, err := FromYaml([]byte(oyml))
if err != nil {
- t.Error("Unable to read overrides yaml")
+ t.Error("Unable to read mirrors yaml")
}
out, err := ov.Marshal()
if err != nil {
- t.Error("Unable to marshal overrides yaml")
+ t.Error("Unable to marshal mirrors yaml")
}
if string(out) != ooutyml {
- t.Error("Output overrides sorting failed")
+ t.Error("Output mirrors sorting failed")
}
}
diff --git a/overrides/cfg.go b/overrides/cfg.go
deleted file mode 100644
index d79284e..0000000
--- a/overrides/cfg.go
+++ /dev/null
@@ -1,98 +0,0 @@
-package overrides
-
-import (
- "io/ioutil"
- "sort"
- "strings"
-
- "gopkg.in/yaml.v2"
-)
-
-// Overrides contains global overrides to local configuration
-type Overrides struct {
-
- // Repos contains repo override configuration
- Repos OverrideRepos `yaml:"repos"`
-}
-
-// Marshal converts an Overrides instance to YAML
-func (ov *Overrides) Marshal() ([]byte, error) {
- yml, err := yaml.Marshal(&ov)
- if err != nil {
- return []byte{}, err
- }
- return yml, nil
-}
-
-// WriteFile writes an overrides.yaml file
-//
-// This is a convenience function that marshals the YAML and then writes it to
-// the given file. If the file exists, it will be clobbered.
-func (ov *Overrides) WriteFile(opath string) error {
- o, err := ov.Marshal()
- if err != nil {
- return err
- }
- return ioutil.WriteFile(opath, o, 0666)
-}
-
-// ReadOverridesFile loads the contents of an overrides.yaml file.
-func ReadOverridesFile(opath string) (*Overrides, error) {
- yml, err := ioutil.ReadFile(opath)
- if err != nil {
- return nil, err
- }
- ov, err := FromYaml(yml)
- if err != nil {
- return nil, err
- }
- return ov, nil
-}
-
-// FromYaml returns an instance of Overrides from YAML
-func FromYaml(yml []byte) (*Overrides, error) {
- ov := &Overrides{}
- err := yaml.Unmarshal([]byte(yml), &ov)
- return ov, err
-}
-
-// MarshalYAML is a hook for gopkg.in/yaml.v2.
-// It sorts override repos lexicographically for reproducibility.
-func (ov *Overrides) MarshalYAML() (interface{}, error) {
-
- sort.Sort(ov.Repos)
-
- return ov, nil
-}
-
-// OverrideRepos is a slice of Override pointers
-type OverrideRepos []*OverrideRepo
-
-// Len returns the length of the OverrideRepos. This is needed for sorting with
-// the sort package.
-func (o OverrideRepos) Len() int {
- return len(o)
-}
-
-// Less is needed for the sort interface. It compares two OverrideRepos based on
-// their original value.
-func (o OverrideRepos) Less(i, j int) bool {
-
- // Names are normalized to lowercase because case affects sorting order. For
- // example, Masterminds comes before kylelemons. Making them lowercase
- // causes kylelemons to come first which is what is expected.
- return strings.ToLower(o[i].Original) < strings.ToLower(o[j].Original)
-}
-
-// Swap is needed for the sort interface. It swaps the position of two
-// OverrideRepos.
-func (o OverrideRepos) Swap(i, j int) {
- o[i], o[j] = o[j], o[i]
-}
-
-// OverrideRepo represents a single repo override
-type OverrideRepo struct {
- Original string `yaml:"original"`
- Repo string `yaml:"repo"`
- Vcs string `yaml:"vcs,omitempty"`
-}
diff --git a/overrides/overrides.go b/overrides/overrides.go
deleted file mode 100644
index 8299ede..0000000
--- a/overrides/overrides.go
+++ /dev/null
@@ -1,66 +0,0 @@
-// Package overrides handles managing overrides in the running application
-package overrides
-
-import (
- "fmt"
- "os"
- "path/filepath"
-
- "github.com/Masterminds/glide/msg"
- gpath "github.com/Masterminds/glide/path"
-)
-
-var overrides map[string]*override
-
-func init() {
- overrides = make(map[string]*override)
-}
-
-type override struct {
- Repo, Vcs string
-}
-
-// Get retrieves informtion about an override. It returns.
-// - bool if found
-// - new repo location
-// - vcs type
-func Get(k string) (bool, string, string) {
- o, f := overrides[k]
- if !f {
- return false, "", ""
- }
-
- return true, o.Repo, o.Vcs
-}
-
-// Load pulls the overrides into memory
-func Load() error {
- home := gpath.Home()
-
- op := filepath.Join(home, "overrides.yaml")
-
- var ov *Overrides
- if _, err := os.Stat(op); os.IsNotExist(err) {
- msg.Debug("No overrides.yaml file exists")
- ov = &Overrides{
- Repos: make(OverrideRepos, 0),
- }
- } else {
- ov, err = ReadOverridesFile(op)
- if err != nil {
- return fmt.Errorf("Error reading existing overrides.yaml file: %s", err)
- }
- }
-
- msg.Info("Loading overrides from overrides.yaml file")
- for _, o := range ov.Repos {
- msg.Debug("Found override: %s to %s (%s)", o.Original, o.Repo, o.Vcs)
- no := &override{
- Repo: o.Repo,
- Vcs: o.Vcs,
- }
- overrides[o.Original] = no
- }
-
- return nil
-}