mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-12-24 12:25:28 -07:00
65688915a5
* Create Plugin.Exists method * Create internal/versions package * Add missing asdfrc for internal/resolve package tests * Create versions.ParseString function * Create versions.InstallOneVersion function * Update hook package to allow hook output to be received * Write tests
38 lines
934 B
Go
38 lines
934 B
Go
// Package hook provides a simple interface for running hook commands that may
|
|
// be defined in the asdfrc file
|
|
package hook
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"asdf/config"
|
|
"asdf/execute"
|
|
)
|
|
|
|
// Run gets a hook command from config and runs it with the provided arguments.
|
|
// Output is sent to STDOUT and STDERR
|
|
func Run(conf config.Config, hookName string, arguments []string) error {
|
|
return RunWithOutput(conf, hookName, arguments, os.Stdout, os.Stderr)
|
|
}
|
|
|
|
// RunWithOutput gets a hook command from config and runs it with the provided
|
|
// arguments. Output is sent to the provided io.Writers.
|
|
func RunWithOutput(config config.Config, hookName string, arguments []string, stdOut io.Writer, stdErr io.Writer) error {
|
|
hookCmd, err := config.GetHook(hookName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if hookCmd == "" {
|
|
return nil
|
|
}
|
|
|
|
cmd := execute.NewExpression(hookCmd, arguments)
|
|
|
|
cmd.Stdout = stdOut
|
|
cmd.Stderr = stdErr
|
|
|
|
return cmd.Run()
|
|
}
|