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

Function Install

internal/skills/installer/installer.go:57–143  ·  view source on GitHub ↗

Install fetches and writes skills to the target directory.

(opts *Options)

Source from the content-addressed store, hash-verified

55
56// Install fetches and writes skills to the target directory.
57func Install(opts *Options) (*Result, error) {
58 targetDir := opts.Dir
59 if targetDir == "" {
60 if opts.AgentHost == nil {
61 return nil, fmt.Errorf("either Dir or AgentHost must be specified")
62 }
63 var err error
64 targetDir, err = opts.AgentHost.InstallDir(opts.Scope, opts.GitRoot, opts.HomeDir)
65 if err != nil {
66 return nil, err
67 }
68 }
69
70 if len(opts.Skills) == 1 {
71 skill := opts.Skills[0]
72 if opts.OnProgress != nil {
73 opts.OnProgress(0, 1)
74 defer opts.OnProgress(1, 1)
75 }
76 if err := installSkill(opts, skill, targetDir); err != nil {
77 return nil, fmt.Errorf("failed to install skill %q: %w", skill.InstallName(), err)
78 }
79 var warnings []string
80 if err := lockfile.RecordInstall(opts.Host, skill.InstallName(), opts.Owner, opts.Repo, skill.Path+"/SKILL.md", skill.TreeSHA, opts.PinnedRef); err != nil {
81 warnings = append(warnings, fmt.Sprintf("could not record install for %s: %v", skill.InstallName(), err))
82 }
83 return &Result{Installed: []string{skill.InstallName()}, Dir: targetDir, Warnings: warnings}, nil
84 }
85
86 total := len(opts.Skills)
87 if opts.OnProgress != nil {
88 opts.OnProgress(0, total)
89 }
90
91 type job struct {
92 idx int
93 skill discovery.Skill
94 }
95 jobs := make(chan job)
96
97 results := make([]skillResult, total)
98 var wg sync.WaitGroup
99 var done atomic.Int32
100
101 workers := min(maxConcurrency, total)
102 for range workers {
103 wg.Go(func() {
104 for j := range jobs {
105 err := installSkill(opts, j.skill, targetDir)
106 results[j.idx] = skillResult{name: j.skill.InstallName(), err: err}
107
108 if opts.OnProgress != nil {
109 opts.OnProgress(int(done.Add(1)), total)
110 }
111 }
112 })
113 }
114

Callers 4

updateSkillInPlaceFunction · 0.92
installRunFunction · 0.92
TestInstallFunction · 0.85

Calls 6

RecordInstallFunction · 0.92
installSkillFunction · 0.85
InstallDirMethod · 0.80
InstallNameMethod · 0.80
ErrorfMethod · 0.65
AddMethod · 0.65

Tested by 2

TestInstallFunction · 0.68