on main help sign in
refactor(shell): some small code adjustments
b9e41f8Andrey Nering
internal/shell/shell.go+4−5
@@ -100,7 +100,7 @@ func (s *Shell) Exec(ctx context.Context, command string) (string, string, error
100 s.mu.Lock()
100 s.mu.Lock()
101 defer s.mu.Unlock()
101 defer s.mu.Unlock()
102
102
103− return s.execPOSIX(ctx, command)
103+ return s.exec(ctx, command)
104}
104}
105
105
106// GetWorkingDir returns the current working directory
106// GetWorkingDir returns the current working directory
@@ -228,8 +228,8 @@ func (s *Shell) blockHandler() func(next interp.ExecHandlerFunc) interp.ExecHand
228 }
228 }
229}
229}
230
230
231−// execPOSIX executes commands using POSIX shell emulation (cross-platform)
231+// exec executes commands using a cross-platform shell interpreter.
232−func (s *Shell) execPOSIX(ctx context.Context, command string) (string, string, error) {
232+func (s *Shell) exec(ctx context.Context, command string) (string, string, error) {
233 line, err := syntax.NewParser().Parse(strings.NewReader(command), "")
233 line, err := syntax.NewParser().Parse(strings.NewReader(command), "")
234 if err != nil {
234 if err != nil {
235 return "", "", fmt.Errorf("could not parse command: %w", err)
235 return "", "", fmt.Errorf("could not parse command: %w", err)
@@ -249,11 +249,10 @@ func (s *Shell) execPOSIX(ctx context.Context, command string) (string, string,
249
249
250 err = runner.Run(ctx, line)
250 err = runner.Run(ctx, line)
251 s.cwd = runner.Dir
251 s.cwd = runner.Dir
252− s.env = []string{}
253 for name, vr := range runner.Vars {
252 for name, vr := range runner.Vars {
254 s.env = append(s.env, fmt.Sprintf("%s=%s", name, vr.Str))
253 s.env = append(s.env, fmt.Sprintf("%s=%s", name, vr.Str))
255 }
254 }
256− s.logger.InfoPersist("POSIX command finished", "command", command, "err", err)
255+ s.logger.InfoPersist("command finished", "command", command, "err", err)
257 return stdout.String(), stderr.String(), err
256 return stdout.String(), stderr.String(), err
258}
257}
259
258