Skip to content

Commit

Permalink
F
Browse files Browse the repository at this point in the history
  • Loading branch information
adambabik committed Oct 13, 2024
1 parent bea4638 commit d76e4ee
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 23 deletions.
14 changes: 2 additions & 12 deletions internal/cmd/beta/session_cmd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package beta

import (
"bytes"
"os"
"os/exec"
"strconv"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
},
)
Expand Down
2 changes: 1 addition & 1 deletion internal/command/command_inline_shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type inlineShellCommand struct {
internalCommand

debug bool
envCollector EnvCollector
envCollector envCollector
logger *zap.Logger
session *Session
}
Expand Down
2 changes: 1 addition & 1 deletion internal/command/command_terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var introMsg = []byte(
type terminalCommand struct {
internalCommand

envCollector EnvCollector
envCollector envCollector
logger *zap.Logger
session *Session
stdinWriter io.Writer
Expand Down
6 changes: 1 addition & 5 deletions internal/command/env_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,15 @@ 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)

// 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.
Expand Down
2 changes: 1 addition & 1 deletion internal/command/env_collector_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion internal/command/env_collector_fifo_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type envCollectorFifo struct {
temp *tempDirectory
}

var _ EnvCollector = (*envCollectorFifo)(nil)
var _ envCollector = (*envCollectorFifo)(nil)

func newEnvCollectorFifo(
scanner envScanner,
Expand Down
2 changes: 1 addition & 1 deletion internal/command/env_collector_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type envCollectorFile struct {
temp *tempDirectory
}

var _ EnvCollector = (*envCollectorFile)(nil)
var _ envCollector = (*envCollectorFile)(nil)

func newEnvCollectorFile(
scanner envScanner,
Expand Down
2 changes: 1 addition & 1 deletion internal/command/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit d76e4ee

Please sign in to comment.