(opts *PreviewOptions, skills []discovery.Skill)
| 450 | } |
| 451 | |
| 452 | func 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. |
| 487 | type treeNode struct { |
no test coverage detected