MCPcopy Create free account
hub / github.com/Masterminds/glide / MirrorsRemove

Function MirrorsRemove

action/mirrors.go:101–146  ·  view source on GitHub ↗

MirrorsRemove removes a mirrors setting

(k string)

Source from the content-addressed store, hash-verified

99
100// MirrorsRemove removes a mirrors setting
101func MirrorsRemove(k string) error {
102 if k == "" {
103 msg.Err("The mirror to remove is required")
104 return nil
105 }
106
107 home := gpath.Home()
108
109 op := filepath.Join(home, "mirrors.yaml")
110
111 if _, err := os.Stat(op); os.IsNotExist(err) {
112 msg.Err("mirrors.yaml file not found")
113 return nil
114 }
115
116 ov, err := mirrors.ReadMirrorsFile(op)
117 if err != nil {
118 msg.Die("Unable to read mirrors.yaml file: %s", err)
119 }
120
121 var nre mirrors.MirrorRepos
122 var found bool
123 for _, re := range ov.Repos {
124 if re.Original != k {
125 nre = append(nre, re)
126 } else {
127 found = true
128 }
129 }
130
131 if !found {
132 msg.Warn("%s was not found in mirrors", k)
133 } else {
134 msg.Info("%s was removed from mirrors", k)
135 ov.Repos = nre
136
137 err = ov.WriteFile(op)
138 if err != nil {
139 msg.Err("Error writing mirrors.yaml file: %s", err)
140 } else {
141 msg.Info("mirrors.yaml written with changes")
142 }
143 }
144
145 return nil
146}

Callers

nothing calls this directly

Calls 5

ErrMethod · 0.80
DieMethod · 0.80
WarnMethod · 0.80
InfoMethod · 0.80
WriteFileMethod · 0.45

Tested by

no test coverage detected