mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-12-25 12:55:09 -07:00
f1e7c05ae3
* 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
30 lines
564 B
Go
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()
|
|
}
|