From d4bfd83af68ed6964b82136899e0f413e9868a1f Mon Sep 17 00:00:00 2001 From: Adam Babik Date: Sun, 13 Oct 2024 14:54:14 +0200 Subject: [PATCH] F --- internal/cmd/beta/session_cmd.go | 14 ++------------ internal/command/command_inline_shell.go | 2 +- internal/command/command_terminal.go | 2 +- internal/command/env_collector.go | 6 +----- internal/command/env_collector_factory.go | 2 +- internal/command/env_collector_fifo_unix.go | 2 +- internal/command/env_collector_file.go | 2 +- internal/command/factory.go | 2 +- 8 files changed, 9 insertions(+), 23 deletions(-) diff --git a/internal/cmd/beta/session_cmd.go b/internal/cmd/beta/session_cmd.go index 6d35e323a..b92287b57 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 bbef39e9a..6da15b79f 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 b6f580401..66b6f8eae 100644 --- a/internal/command/command_terminal.go +++ b/internal/command/command_terminal.go @@ -18,7 +18,7 @@ const ( 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 2a092b3ce..733ae7eab 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 b7b7b4b7f..7a9100607 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 99076e3cd..cb112e024 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 2d110b876..a0124869b 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 3752b7e61..672d4b8ec 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 }