github.com/sandwich-go/boost@v1.3.29/xproc/gen_processoptions_optiongen.go (about) 1 // Code generated by optiongen. DO NOT EDIT. 2 // optiongen: github.com/timestee/optiongen 3 4 package xproc 5 6 import ( 7 "io" 8 "os" 9 ) 10 11 // ProcessOptions should use NewProcessOptions to initialize it 12 type ProcessOptions struct { 13 Args []string 14 Stdin io.Reader 15 Stdout io.Writer 16 Stderr io.Writer 17 WorkingDir string 18 Env []string 19 } 20 21 // NewProcessOptions new ProcessOptions 22 func NewProcessOptions(opts ...ProcessOption) *ProcessOptions { 23 cc := newDefaultProcessOptions() 24 for _, opt := range opts { 25 opt(cc) 26 } 27 if watchDogProcessOptions != nil { 28 watchDogProcessOptions(cc) 29 } 30 return cc 31 } 32 33 // ApplyOption apply multiple new option 34 func (cc *ProcessOptions) ApplyOption(opts ...ProcessOption) { 35 for _, opt := range opts { 36 opt(cc) 37 } 38 } 39 40 // ProcessOption option func 41 type ProcessOption func(cc *ProcessOptions) 42 43 // WithArgs option func for filed Args 44 func WithArgs(v ...string) ProcessOption { 45 return func(cc *ProcessOptions) { 46 cc.Args = v 47 } 48 } 49 50 // WithStdin option func for filed Stdin 51 func WithStdin(v io.Reader) ProcessOption { 52 return func(cc *ProcessOptions) { 53 cc.Stdin = v 54 } 55 } 56 57 // WithStdout option func for filed Stdout 58 func WithStdout(v io.Writer) ProcessOption { 59 return func(cc *ProcessOptions) { 60 cc.Stdout = v 61 } 62 } 63 64 // WithStderr option func for filed Stderr 65 func WithStderr(v io.Writer) ProcessOption { 66 return func(cc *ProcessOptions) { 67 cc.Stderr = v 68 } 69 } 70 71 // WithWorkingDir option func for filed WorkingDir 72 func WithWorkingDir(v string) ProcessOption { 73 return func(cc *ProcessOptions) { 74 cc.WorkingDir = v 75 } 76 } 77 78 // WithEnv option func for filed Env 79 func WithEnv(v ...string) ProcessOption { 80 return func(cc *ProcessOptions) { 81 cc.Env = v 82 } 83 } 84 85 // InstallProcessOptionsWatchDog the installed func will called when NewProcessOptions called 86 func InstallProcessOptionsWatchDog(dog func(cc *ProcessOptions)) { watchDogProcessOptions = dog } 87 88 // watchDogProcessOptions global watch dog 89 var watchDogProcessOptions func(cc *ProcessOptions) 90 91 // newDefaultProcessOptions new default ProcessOptions 92 func newDefaultProcessOptions() *ProcessOptions { 93 cc := &ProcessOptions{} 94 95 for _, opt := range [...]ProcessOption{ 96 WithArgs(make([]string, 0)...), 97 WithStdin(os.Stdin), 98 WithStdout(os.Stdout), 99 WithStderr(os.Stderr), 100 WithWorkingDir(""), 101 WithEnv(make([]string, 0)...), 102 } { 103 opt(cc) 104 } 105 106 return cc 107 } 108 109 // all getter func 110 func (cc *ProcessOptions) GetArgs() []string { return cc.Args } 111 func (cc *ProcessOptions) GetStdin() io.Reader { return cc.Stdin } 112 func (cc *ProcessOptions) GetStdout() io.Writer { return cc.Stdout } 113 func (cc *ProcessOptions) GetStderr() io.Writer { return cc.Stderr } 114 func (cc *ProcessOptions) GetWorkingDir() string { return cc.WorkingDir } 115 func (cc *ProcessOptions) GetEnv() []string { return cc.Env } 116 117 // ProcessOptionsVisitor visitor interface for ProcessOptions 118 type ProcessOptionsVisitor interface { 119 GetArgs() []string 120 GetStdin() io.Reader 121 GetStdout() io.Writer 122 GetStderr() io.Writer 123 GetWorkingDir() string 124 GetEnv() []string 125 } 126 127 // ProcessOptionsInterface visitor + ApplyOption interface for ProcessOptions 128 type ProcessOptionsInterface interface { 129 ProcessOptionsVisitor 130 ApplyOption(...ProcessOption) 131 }