interactiveUninstall lists installed items and lets the user pick which to remove.
(kind entities.Kind, apps []string, out io.Writer)
| 2209 | |
| 2210 | // interactiveUninstall lists installed items and lets the user pick which to remove. |
| 2211 | func interactiveUninstall(kind entities.Kind, apps []string, out io.Writer) error { |
| 2212 | for _, app := range apps { |
| 2213 | appPaths := entities.AppPathsFor(kind) |
| 2214 | dest, ok := appPaths[app] |
| 2215 | if !ok { |
| 2216 | continue |
| 2217 | } |
| 2218 | resolved := expandPath(dest) |
| 2219 | |
| 2220 | if kind == entities.KindPrompt || kind == entities.KindInstruction { |
| 2221 | fmt.Fprintf(out, " %s — prompt uninstall not supported interactively\n", app) |
| 2222 | continue |
| 2223 | } |
| 2224 | |
| 2225 | entries, err := os.ReadDir(resolved) |
| 2226 | if err != nil { |
| 2227 | continue |
| 2228 | } |
| 2229 | var items []multiSelectItem |
| 2230 | for _, e := range entries { |
| 2231 | if !e.IsDir() { |
| 2232 | continue |
| 2233 | } |
| 2234 | items = append(items, multiSelectItem{label: e.Name()}) |
| 2235 | } |
| 2236 | if len(items) == 0 { |
| 2237 | fmt.Fprintf(out, "No %ss installed in %s\n", kind, app) |
| 2238 | continue |
| 2239 | } |
| 2240 | |
| 2241 | title := fmt.Sprintf("Select %s(s) to uninstall from %s:", kind, app) |
| 2242 | selected, err := runMultiSelect(title, items) |
| 2243 | if err != nil { |
| 2244 | return err |
| 2245 | } |
| 2246 | for _, name := range selected { |
| 2247 | uninstallOneFromApp(kind, app, name, out) |
| 2248 | } |
| 2249 | } |
| 2250 | return nil |
| 2251 | } |
| 2252 | |
| 2253 | func readStdinIfPiped(in io.Reader) (string, error) { |
| 2254 | if file, ok := in.(*os.File); ok { |
no test coverage detected