MCPcopy Create free account
hub / github.com/cli/cli / updateRun

Function updateRun

pkg/cmd/skills/update/update.go:153–457  ·  view source on GitHub ↗
(opts *UpdateOptions)

Source from the content-addressed store, hash-verified

151}
152
153func updateRun(opts *UpdateOptions) error {
154 cs := opts.IO.ColorScheme()
155 canPrompt := opts.IO.CanPrompt()
156
157 httpClient, err := opts.HttpClient()
158 if err != nil {
159 return err
160 }
161 apiClient := api.NewClientFromHTTP(httpClient)
162
163 gitRoot := installer.ResolveGitRoot(opts.GitClient)
164 homeDir := installer.ResolveHomeDir()
165
166 // Scan for installed skills
167 var installed []installedSkill
168 if opts.Dir != "" {
169 skills, scanErr := scanInstalledSkills(opts.Dir, nil, "")
170 if scanErr != nil {
171 return fmt.Errorf("could not scan directory: %w", scanErr)
172 }
173 installed = skills
174 } else {
175 installed = scanAllAgents(gitRoot, homeDir)
176 }
177
178 if len(installed) == 0 {
179 fmt.Fprintf(opts.IO.ErrOut, "No installed skills found.\n")
180 return nil
181 }
182
183 // Filter to requested skills if specified
184 if len(opts.Skills) > 0 {
185 requested := make(map[string]bool, len(opts.Skills))
186 for _, name := range opts.Skills {
187 requested[name] = true
188 }
189 var filtered []installedSkill
190 for _, s := range installed {
191 if requested[s.name] {
192 filtered = append(filtered, s)
193 }
194 }
195 if len(filtered) == 0 {
196 return fmt.Errorf("none of the specified skills are installed")
197 }
198 installed = filtered
199 }
200
201 // Skip skills with invalid metadata rather than aborting the entire
202 // update run. One corrupt skill should not prevent updating others.
203 {
204 var valid []installedSkill
205 for _, s := range installed {
206 if s.metadataErr != nil {
207 fmt.Fprintf(opts.IO.ErrOut, "%s Skipping %s: invalid repository metadata: %s\n", cs.WarningIcon(), s.name, s.metadataErr)
208 continue
209 }
210 valid = append(valid, s)

Callers 2

NewCmdUpdateFunction · 0.85
TestUpdateRunFunction · 0.85

Calls 15

NewClientFromHTTPFunction · 0.92
ResolveGitRootFunction · 0.92
ResolveHomeDirFunction · 0.92
FetchRepositoryFunction · 0.92
ResolveRefFunction · 0.92
DiscoverSkillsFunction · 0.92
ShortSHAFunction · 0.92
ShortRefFunction · 0.92
scanAllAgentsFunction · 0.85
promptForSkillOriginFunction · 0.85
updateSkillInPlaceFunction · 0.85
ColorSchemeMethod · 0.80

Tested by 1

TestUpdateRunFunction · 0.68