MCPcopy
hub / github.com/asdf-vm/asdf / listAllCommand

Function listAllCommand

internal/cli/cli.go:1222–1266  ·  view source on GitHub ↗
(logger *log.Logger, conf config.Config, toolName, filter string)

Source from the content-addressed store, hash-verified

1220}
1221
1222func listAllCommand(logger *log.Logger, conf config.Config, toolName, filter string) error {
1223 if toolName == "" {
1224 logger.Print("No plugin given")
1225 cli.OsExiter(1)
1226 return nil
1227 }
1228
1229 plugin, err := loadPlugin(logger, conf, toolName)
1230 if err != nil {
1231 cli.OsExiter(1)
1232 return err
1233 }
1234
1235 var stdout strings.Builder
1236 var stderr strings.Builder
1237
1238 err = plugin.RunCallback("list-all", []string{}, map[string]string{}, &stdout, &stderr)
1239 if err != nil {
1240 fmt.Printf("Plugin %s's list-all callback script failed with output:\n", plugin.Name)
1241 // Print to stderr
1242 os.Stderr.WriteString(stderr.String())
1243 os.Stderr.WriteString(stdout.String())
1244
1245 cli.OsExiter(1)
1246 return err
1247 }
1248
1249 versions := strings.Split(stdout.String(), " ")
1250
1251 if filter != "" {
1252 versions = filterByExactMatch(versions, filter)
1253 }
1254
1255 if len(versions) == 0 {
1256 logger.Printf("No compatible versions available (%s %s)", plugin.Name, filter)
1257 cli.OsExiter(1)
1258 return nil
1259 }
1260
1261 for _, version := range versions {
1262 fmt.Printf("%s\n", version)
1263 }
1264
1265 return nil
1266}
1267
1268func filterByExactMatch(allVersions []string, pattern string) (versions []string) {
1269 for _, version := range allVersions {

Callers 1

listCommandFunction · 0.85

Calls 3

loadPluginFunction · 0.85
RunCallbackMethod · 0.80
filterByExactMatchFunction · 0.70

Tested by

no test coverage detected