asdf/hook/hook.go
Trevor Brown f1e7c05ae3 feat(golang-rewrite): create RunCallback method for Plugin struct
* Create `plugins.New` function, updating existing code to use it
* Add another test for `hook.Run` function
* Enable `plugin_add_command.bats` tests for Go implementation of asdf
* Add `RunCallback` method to `Plugin` struct
* Update `plugins.Add` function to run `post-plugin-add` plugin callback script
* Handle Bash expression and scripts properly in `execute` package so `$@` is always set
2024-12-18 10:21:41 -05:00

30 lines
564 B
Go

// Package hook provides a simple interface for running hook commands that may
// be defined in the asdfrc file
package hook
import (
"os"
"asdf/config"
"asdf/execute"
)
// Run gets a hook command from config and runs it with the provided arguments
func Run(config config.Config, hookName string, arguments []string) error {
hookCmd, err := config.GetHook(hookName)
if err != nil {
return err
}
if hookCmd == "" {
return nil
}
cmd := execute.NewExpression(hookCmd, arguments)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}