diff --git a/internal/cmd/beta/session_cmd.go b/internal/cmd/beta/session_cmd.go index 6d35e323..b92287b5 100644 --- a/internal/cmd/beta/session_cmd.go +++ b/internal/cmd/beta/session_cmd.go @@ -1,7 +1,6 @@ package beta import ( - "bytes" "os" "os/exec" "strconv" @@ -31,7 +30,7 @@ All exported variables during the session will be available to the subsequent co ) error { defer logger.Sync() - envCollector, err := command.NewEnvCollectorFactory().UseFifo(false).Build() + envCollector, err := command.NewEnvCollectorFactory().Build() if err != nil { return errors.WithStack(err) } @@ -116,16 +115,7 @@ func sessionSetupCmd() *cobra.Command { debug, ) - buf := bytes.NewBufferString("#!/bin/sh\n") - if debug { - _, _ = buf.WriteString("set -euxo pipefail\n") - } - _ = envSetter.SetOnShell(buf) - if debug { - _, _ = buf.WriteString("set +euxo pipefail\n") - } - - _, err := cmd.OutOrStdout().Write(buf.Bytes()) + err := envSetter.SetOnShell(cmd.OutOrStdout()) return errors.WithStack(err) }, ) diff --git a/internal/command/command_inline_shell.go b/internal/command/command_inline_shell.go index bbef39e9..6da15b79 100644 --- a/internal/command/command_inline_shell.go +++ b/internal/command/command_inline_shell.go @@ -14,7 +14,7 @@ type inlineShellCommand struct { internalCommand debug bool - envCollector EnvCollector + envCollector envCollector logger *zap.Logger session *Session } diff --git a/internal/command/command_terminal.go b/internal/command/command_terminal.go index ca5c0864..bddb8963 100644 --- a/internal/command/command_terminal.go +++ b/internal/command/command_terminal.go @@ -17,7 +17,7 @@ var introMsg = []byte( type terminalCommand struct { internalCommand - envCollector EnvCollector + envCollector envCollector logger *zap.Logger session *Session stdinWriter io.Writer diff --git a/internal/command/env_collector.go b/internal/command/env_collector.go index 2a092b3c..733ae7ea 100644 --- a/internal/command/env_collector.go +++ b/internal/command/env_collector.go @@ -41,9 +41,7 @@ func SetEnvDumpCommand(cmd string) { envCollectorEnableEncryption = false } -type EnvCollector interface { - EnvSetter - +type envCollector interface { // Diff compares the environment variables before and after the command execution. // It returns the list of env that were changed and deleted. Diff() (changed []string, deleted []string, _ error) @@ -51,9 +49,7 @@ type EnvCollector interface { // ExtraEnv provides a list of extra environment variables that should be set // before the command execution. ExtraEnv() []string -} -type EnvSetter interface { // SetOnShell writes additional commands to the shell session // in order to collect the environment variables after // the command execution. diff --git a/internal/command/env_collector_factory.go b/internal/command/env_collector_factory.go index b7b7b4b7..7a910060 100644 --- a/internal/command/env_collector_factory.go +++ b/internal/command/env_collector_factory.go @@ -29,7 +29,7 @@ func (f *EnvCollectorFactory) UseFifo(value bool) *EnvCollectorFactory { return f } -func (f *EnvCollectorFactory) Build() (EnvCollector, error) { +func (f *EnvCollectorFactory) Build() (envCollector, error) { scanner := scanEnv var ( diff --git a/internal/command/env_collector_fifo_unix.go b/internal/command/env_collector_fifo_unix.go index 99076e3c..cb112e02 100644 --- a/internal/command/env_collector_fifo_unix.go +++ b/internal/command/env_collector_fifo_unix.go @@ -28,7 +28,7 @@ type envCollectorFifo struct { temp *tempDirectory } -var _ EnvCollector = (*envCollectorFifo)(nil) +var _ envCollector = (*envCollectorFifo)(nil) func newEnvCollectorFifo( scanner envScanner, diff --git a/internal/command/env_collector_file.go b/internal/command/env_collector_file.go index 2d110b87..a0124869 100644 --- a/internal/command/env_collector_file.go +++ b/internal/command/env_collector_file.go @@ -12,7 +12,7 @@ type envCollectorFile struct { temp *tempDirectory } -var _ EnvCollector = (*envCollectorFile)(nil) +var _ envCollector = (*envCollectorFile)(nil) func newEnvCollectorFile( scanner envScanner, diff --git a/internal/command/factory.go b/internal/command/factory.go index 3752b7e6..672d4b8e 100644 --- a/internal/command/factory.go +++ b/internal/command/factory.go @@ -259,7 +259,7 @@ func (f *commandFactory) buildVirtual(base *base, opts CommandOptions) *virtualC // TODO(adamb): env collector (fifo) might need a context which will unblock it when the command finishes. // Otherwise, it won't know when to finish waiting for the output from env producer. -func (f *commandFactory) getEnvCollector() (EnvCollector, error) { +func (f *commandFactory) getEnvCollector() (envCollector, error) { if f.docker != nil { return nil, nil }