@@ -22,15 +22,10 @@ type Command struct {
2222 Params []string
2323 Env []string
2424 WorkDir string
25- StdoutFunc ReaderFunc
26- SterrFunc ReaderFunc
25+ stdoutFunc ReaderFunc
26+ stderrFunc ReaderFunc
2727}
2828
29- func NewPanicOption () Option {
30- return Option {
31- PanicOnError : true ,
32- }
33- }
3429func NewAllowedCodesOption (codes ... int ) Option {
3530 return Option {
3631 AllowedCodes : codes ,
@@ -49,50 +44,50 @@ func NewCommand(command string, params ...string) *Command {
4944 return cmd
5045}
5146
52- func (C * Command ) AddParam (param string ) * Command {
53- C .Params = append (C .Params , param )
54- return C
47+ func (c * Command ) AddParam (param string ) * Command {
48+ c .Params = append (c .Params , param )
49+ return c
5550}
5651
57- func (C * Command ) SetWorkDir (workDir string ) * Command {
58- C .WorkDir = workDir
59- return C
52+ func (c * Command ) SetWorkDir (workDir string ) * Command {
53+ c .WorkDir = workDir
54+ return c
6055}
61- func (C * Command ) SetEnv (env []string ) * Command {
62- C .Env = env
63- return C
56+ func (c * Command ) SetEnv (env []string ) * Command {
57+ c .Env = env
58+ return c
6459}
6560
66- func (C * Command ) AddEnv (env string ) * Command {
67- C .Env = append (C .Env , env )
68- return C
61+ func (c * Command ) AddEnv (env string ) * Command {
62+ c .Env = append (c .Env , env )
63+ return c
6964}
7065
71- func (C * Command ) SetStdoutFunc (StdoutFunc ReaderFunc ) * Command {
72- C . StdoutFunc = StdoutFunc
73- return C
66+ func (c * Command ) SetStdoutFunc (StdoutFunc ReaderFunc ) * Command {
67+ c . stdoutFunc = StdoutFunc
68+ return c
7469}
7570
76- func (C * Command ) SetStderrFunc (StderrtFunc ReaderFunc ) * Command {
77- C . SterrFunc = StderrtFunc
78- return C
71+ func (c * Command ) SetStderrFunc (StderrtFunc ReaderFunc ) * Command {
72+ c . stderrFunc = StderrtFunc
73+ return c
7974}
80- func (C * Command ) Run (opt ... Option ) (exitCode int , err error ) {
81- return C .RunWithContext (context .Background (), opt ... )
75+ func (c * Command ) Run (opt ... Option ) (exitCode int , err error ) {
76+ return c .RunWithContext (context .Background (), opt ... )
8277}
8378
84- func (C * Command ) RunWithContext (ctx context.Context , opt ... Option ) (exitCode int , err error ) {
79+ func (c * Command ) RunWithContext (ctx context.Context , opt ... Option ) (exitCode int , err error ) {
8580 wg := & sync.WaitGroup {}
8681 defer wg .Wait ()
8782 var cmd * exec.Cmd
8883 if runtime .GOOS == "windows" {
89- cmd = exec .CommandContext (ctx , C .Command , C .Params ... )
84+ cmd = exec .CommandContext (ctx , c .Command , c .Params ... )
9085 } else {
91- fullCommand := append ([]string {C .Command }, C .Params ... )
86+ fullCommand := append ([]string {c .Command }, c .Params ... )
9287 cmd = exec .CommandContext (ctx , "nice" , append ([]string {"-20" }, fullCommand ... )... )
9388 }
94- cmd .Env = C .Env
95- cmd .Dir = C .WorkDir
89+ cmd .Env = c .Env
90+ cmd .Dir = c .WorkDir
9691 stdout , err := cmd .StdoutPipe ()
9792 if err != nil {
9893 return
@@ -106,8 +101,8 @@ func (C *Command) RunWithContext(ctx context.Context, opt ...Option) (exitCode i
106101 }
107102
108103 wg .Add (2 )
109- go C .readerStreamProcessor (ctx , wg , stdout , C . StdoutFunc )
110- go C .readerStreamProcessor (ctx , wg , stderr , C . SterrFunc )
104+ go c .readerStreamProcessor (ctx , wg , stdout , c . stdoutFunc )
105+ go c .readerStreamProcessor (ctx , wg , stderr , c . stderrFunc )
111106
112107 err = cmd .Wait ()
113108 if err != nil {
@@ -147,7 +142,7 @@ func allowedCodes(opts []Option, exitCode int) bool {
147142 return exitCode == 0
148143}
149144
150- func (C * Command ) readerStreamProcessor (ctx context.Context , wg * sync.WaitGroup , reader io.ReadCloser , callbackFunc ReaderFunc ) {
145+ func (c * Command ) readerStreamProcessor (ctx context.Context , wg * sync.WaitGroup , reader io.ReadCloser , callbackFunc ReaderFunc ) {
151146 defer wg .Done ()
152147 buffer := make ([]byte , 4096 )
153148loop:
@@ -172,8 +167,8 @@ loop:
172167 }
173168}
174169
175- func (C * Command ) GetFullCommand () string {
176- return fmt .Sprintf ("%s %s" , C .Command , strings .Join (C .Params , " " ))
170+ func (c * Command ) GetFullCommand () string {
171+ return fmt .Sprintf ("%s %s" , c .Command , strings .Join (c .Params , " " ))
177172}
178173
179174func GetWD () string {
@@ -205,7 +200,7 @@ func StringToSlice(command string) (output []string) {
205200 } else if c == '\'' {
206201 cutQuote = ! cutQuote
207202 }
208- inLineWord = inLineWord + string (c )
203+ inLineWord += string (c )
209204 }
210205 output = append (output , inLineWord )
211206 return output
0 commit comments