Skip to content

Commit

Permalink
feat(golang-rewrite): improve output of 'asdf list all' command when …
Browse files Browse the repository at this point in the history
…plugin not found
  • Loading branch information
Stratus3D committed Dec 14, 2024
1 parent ef7b708 commit eb78a38
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ func currentCommand(logger *log.Logger, tool string) error {

// show single tool
plugin := plugins.New(conf, tool)

err = plugin.Exists()
_, ok := err.(plugins.PluginMissing)
pluginExists := !ok
Expand Down Expand Up @@ -1079,11 +1078,16 @@ func listAllCommand(logger *log.Logger, conf config.Config, toolName, filter str
return nil
}

plugin := plugins.New(conf, toolName)
plugin, err := loadPlugin(logger, conf, toolName)
if err != nil {
os.Exit(1)
return err
}

var stdout strings.Builder
var stderr strings.Builder

err := plugin.RunCallback("list-all", []string{}, map[string]string{}, &stdout, &stderr)
err = plugin.RunCallback("list-all", []string{}, map[string]string{}, &stdout, &stderr)
if err != nil {
fmt.Printf("Plugin %s's list-all callback script failed with output:\n", plugin.Name)
// Print to stderr
Expand Down Expand Up @@ -1131,7 +1135,11 @@ func listLocalCommand(logger *log.Logger, conf config.Config, pluginName, filter
}

if pluginName != "" {
plugin := plugins.New(conf, pluginName)
plugin, err := loadPlugin(logger, conf, pluginName)
if err != nil {
os.Exit(1)
return err
}
versions, _ := installs.Installed(conf, plugin)

if filter != "" {
Expand Down Expand Up @@ -1372,6 +1380,17 @@ func whereCommand(logger *log.Logger, tool, versionStr string) error {
return nil
}

func loadPlugin(logger *log.Logger, conf config.Config, pluginName string) (plugins.Plugin, error) {
plugin := plugins.New(conf, pluginName)
err := plugin.Exists()
if err != nil {
logger.Printf("No such plugin: %s", pluginName)
return plugin, err
}

return plugin, err
}

func reshimToolVersion(conf config.Config, tool, versionStr string, out io.Writer, errOut io.Writer) error {
version := toolversions.Parse(versionStr)
return shims.GenerateForVersion(conf, plugins.New(conf, tool), version, out, errOut)
Expand Down

0 comments on commit eb78a38

Please sign in to comment.