selectItems filters discovered items based on user intent: - skillName given → find that specific item - --all flag → return everything - single item → return it directly - interactive TTY → run multi-select picker - non-interactive → list what was found and error
(items []discoveredItem, skillName string, all bool, kind entities.Kind, source string, stdin io.Reader)
| 1780 | // - interactive TTY → run multi-select picker |
| 1781 | // - non-interactive → list what was found and error |
| 1782 | func selectItems(items []discoveredItem, skillName string, all bool, kind entities.Kind, source string, stdin io.Reader) ([]discoveredItem, error) { |
| 1783 | if skillName != "" { |
| 1784 | for _, item := range items { |
| 1785 | if item.name == skillName { |
| 1786 | return []discoveredItem{item}, nil |
| 1787 | } |
| 1788 | } |
| 1789 | return nil, fmt.Errorf("%s %q not found in %s", kind, skillName, source) |
| 1790 | } |
| 1791 | |
| 1792 | if all || len(items) == 1 { |
| 1793 | return items, nil |
| 1794 | } |
| 1795 | |
| 1796 | // Interactive: run multi-select picker. |
| 1797 | if isInteractive(stdin) { |
| 1798 | return interactiveSelectItems(items, kind, source) |
| 1799 | } |
| 1800 | |
| 1801 | // Non-interactive: list and ask user to specify. |
| 1802 | fmt.Fprintf(os.Stderr, "Found %d %s(s) in %s:\n\n", len(items), kind, source) |
| 1803 | for _, item := range items { |
| 1804 | desc := extractFrontmatterDescription(item.content) |
| 1805 | if desc != "" { |
| 1806 | if len(desc) > 80 { |
| 1807 | desc = desc[:77] + "..." |
| 1808 | } |
| 1809 | fmt.Fprintf(os.Stderr, " %-35s %s\n", item.name, desc) |
| 1810 | } else { |
| 1811 | fmt.Fprintf(os.Stderr, " %s\n", item.name) |
| 1812 | } |
| 1813 | } |
| 1814 | fmt.Fprintf(os.Stderr, "\nSpecify a name to install one, or use --all to install all:\n") |
| 1815 | fmt.Fprintf(os.Stderr, " cam %s install <source> <name> --from-local --app <agent>\n", kind) |
| 1816 | fmt.Fprintf(os.Stderr, " cam %s install <source> --from-local --all --app <agent>\n", kind) |
| 1817 | return nil, fmt.Errorf("specify a %s name or use --all", kind) |
| 1818 | } |
| 1819 | |
| 1820 | // interactiveSelectItems runs a bubbletea multi-select picker. |
| 1821 | func interactiveSelectItems(items []discoveredItem, kind entities.Kind, source string) ([]discoveredItem, error) { |
no test coverage detected