MCPcopy
hub / github.com/cli/cli / selectSkill

Function selectSkill

pkg/cmd/skills/preview/preview.go:452–484  ·  view source on GitHub ↗
(opts *PreviewOptions, skills []discovery.Skill)

Source from the content-addressed store, hash-verified

450}
451
452func selectSkill(opts *PreviewOptions, skills []discovery.Skill) (discovery.Skill, error) {
453 if opts.SkillName != "" {
454 for _, s := range skills {
455 if s.DisplayName() == opts.SkillName || s.Name == opts.SkillName {
456 return s, nil
457 }
458 }
459 // Fall back to InstallName so that namespaced identifiers produced
460 // by the post-install hint (e.g. "namespace/skill") are accepted.
461 for _, s := range skills {
462 if s.InstallName() == opts.SkillName {
463 return s, nil
464 }
465 }
466 return discovery.Skill{}, fmt.Errorf("skill %q not found in %s", opts.SkillName, ghrepo.FullName(opts.repo))
467 }
468
469 if !opts.IO.CanPrompt() {
470 return discovery.Skill{}, fmt.Errorf("must specify a skill name when not running interactively")
471 }
472
473 choices := make([]string, len(skills))
474 for i, s := range skills {
475 choices[i] = s.DisplayName()
476 }
477
478 idx, err := opts.Prompter.Select("Select a skill to preview:", "", choices)
479 if err != nil {
480 return discovery.Skill{}, err
481 }
482
483 return skills[idx], nil
484}
485
486// treeNode represents a file or directory in the tree for rendering.
487type treeNode struct {

Callers 1

previewRunFunction · 0.85

Calls 6

FullNameFunction · 0.92
InstallNameMethod · 0.80
CanPromptMethod · 0.80
DisplayNameMethod · 0.65
ErrorfMethod · 0.65
SelectMethod · 0.65

Tested by

no test coverage detected