2019-09-24 20:32:35 +03:00
|
|
|
package runtime
|
|
|
|
|
2019-09-24 21:00:11 +03:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2019-09-24 20:32:35 +03:00
|
|
|
type CreateOption func(o *CreateOptions)
|
|
|
|
|
|
|
|
type CreateOptions struct {
|
|
|
|
// command to execute including args
|
|
|
|
Command []string
|
|
|
|
// Environment to configure
|
|
|
|
Env []string
|
2019-09-24 21:00:11 +03:00
|
|
|
// Log output
|
|
|
|
Output io.Writer
|
2019-09-24 20:32:35 +03:00
|
|
|
}
|
|
|
|
|
2019-09-24 21:00:11 +03:00
|
|
|
// WithCommand specifies the command to execute
|
2019-09-24 20:32:35 +03:00
|
|
|
func WithCommand(c string, args ...string) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
// set command
|
|
|
|
o.Command = []string{c}
|
|
|
|
// set args
|
|
|
|
o.Command = append(o.Command, args...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 21:00:11 +03:00
|
|
|
// WithEnv sets the created service env
|
2019-09-24 20:32:35 +03:00
|
|
|
func WithEnv(env []string) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Env = env
|
|
|
|
}
|
|
|
|
}
|
2019-09-24 21:00:11 +03:00
|
|
|
|
|
|
|
// WithOutput sets the arg output
|
|
|
|
func WithOutput(out io.Writer) CreateOption {
|
|
|
|
return func(o *CreateOptions) {
|
|
|
|
o.Output = out
|
|
|
|
}
|
|
|
|
}
|