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

Function selectSkill

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

Source from the content-addressed store, hash-verified

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