Skip to content

Commit b2525f4

Browse files
Merge pull request #486 from jesseduffield/add-environ-to-cmd
2 parents d2fa5e9 + 2dda39d commit b2525f4

File tree

13 files changed

+36
-37
lines changed

13 files changed

+36
-37
lines changed

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Setup Go
1717
uses: actions/setup-go@v1
1818
with:
19-
go-version: 1.18.x
19+
go-version: 1.20.x
2020
- name: Run goreleaser
2121
uses: goreleaser/goreleaser-action@v1
2222
with:

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Continuous Integration
22

33
env:
4-
GO_VERSION: 1.18
4+
GO_VERSION: 1.20
55

66
on:
77
push:
@@ -27,7 +27,7 @@ jobs:
2727
- name: Setup Go
2828
uses: actions/setup-go@v1
2929
with:
30-
go-version: 1.18.x
30+
go-version: 1.20.x
3131
- name: Cache build
3232
uses: actions/cache@v1
3333
with:
@@ -49,7 +49,7 @@ jobs:
4949
- name: Setup Go
5050
uses: actions/setup-go@v1
5151
with:
52-
go-version: 1.18.x
52+
go-version: 1.20.x
5353
- name: Cache build
5454
uses: actions/cache@v1
5555
with:
@@ -77,7 +77,7 @@ jobs:
7777
- name: Setup Go
7878
uses: actions/setup-go@v1
7979
with:
80-
go-version: 1.18.x
80+
go-version: 1.20.x
8181
- name: Cache build
8282
uses: actions/cache@v1
8383
with:
@@ -104,7 +104,7 @@ jobs:
104104
- name: Setup Go
105105
uses: actions/setup-go@v1
106106
with:
107-
go-version: 1.18.x
107+
go-version: 1.20.x
108108
- name: Cache build
109109
uses: actions/cache@v1
110110
with:

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ linters-settings:
2626
max-func-lines: 0
2727

2828
run:
29-
go: 1.18
29+
go: '1.20'
30+
timeout: 10m

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG BASE_IMAGE_BUILDER=golang
22
ARG ALPINE_VERSION=3.15
3-
ARG GO_VERSION=1.18
3+
ARG GO_VERSION=1.20
44

55
FROM ${BASE_IMAGE_BUILDER}:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder
66
ARG GOARCH=amd64

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/jesseduffield/lazydocker
22

3-
go 1.18
3+
go 1.20
44

55
require (
66
github.com/OpenPeeDeeP/xdg v0.2.1-0.20190312153938-4ba9e1eb294c

pkg/commands/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (c *Container) Attach() (*exec.Cmd, error) {
100100

101101
c.Log.Warn(fmt.Sprintf("attaching to container %s", c.Name))
102102
// TODO: use SDK
103-
cmd := c.OSCommand.PrepareSubProcess("docker", "attach", "--sig-proxy=false", c.ID)
103+
cmd := c.OSCommand.NewCmd("docker", "attach", "--sig-proxy=false", c.ID)
104104
return cmd, nil
105105
}
106106

pkg/commands/dummies.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package commands
22

33
import (
4-
"io/ioutil"
4+
"io"
55

66
"github.com/jesseduffield/lazydocker/pkg/config"
77
"github.com/jesseduffield/lazydocker/pkg/i18n"
@@ -31,7 +31,7 @@ func NewDummyAppConfig() *config.AppConfig {
3131
// NewDummyLog creates a new dummy Log for testing
3232
func NewDummyLog() *logrus.Entry {
3333
log := logrus.New()
34-
log.Out = ioutil.Discard
34+
log.Out = io.Discard
3535
return log.WithField("test", "test")
3636
}
3737

pkg/commands/os.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package commands
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"os"
88
"os/exec"
99
"path/filepath"
@@ -87,7 +87,7 @@ func (c *OSCommand) RunExecutable(cmd *exec.Cmd) error {
8787
// ExecutableFromString takes a string like `docker ps -a` and returns an executable command for it
8888
func (c *OSCommand) ExecutableFromString(commandStr string) *exec.Cmd {
8989
splitCmd := str.ToArgv(commandStr)
90-
return c.command(splitCmd[0], splitCmd[1:]...)
90+
return c.NewCmd(splitCmd[0], splitCmd[1:]...)
9191
}
9292

9393
// Same as ExecutableFromString but cancellable via a context
@@ -96,6 +96,12 @@ func (c *OSCommand) ExecutableFromStringContext(ctx context.Context, commandStr
9696
return exec.CommandContext(ctx, splitCmd[0], splitCmd[1:]...)
9797
}
9898

99+
func (c *OSCommand) NewCmd(cmdName string, commandArgs ...string) *exec.Cmd {
100+
cmd := c.command(cmdName, commandArgs...)
101+
cmd.Env = os.Environ()
102+
return cmd
103+
}
104+
99105
func (c *OSCommand) NewCommandStringWithShell(commandStr string) string {
100106
var quotedCommand string
101107
// Windows does not seem to like quotes around the command
@@ -187,12 +193,7 @@ func (c *OSCommand) EditFile(filename string) (*exec.Cmd, error) {
187193
return nil, errors.New("No editor defined in $VISUAL or $EDITOR")
188194
}
189195

190-
return c.PrepareSubProcess(editor, filename), nil
191-
}
192-
193-
// PrepareSubProcess iniPrepareSubProcessrocess then tells the Gui to switch to it
194-
func (c *OSCommand) PrepareSubProcess(cmdName string, commandArgs ...string) *exec.Cmd {
195-
return c.command(cmdName, commandArgs...)
196+
return c.NewCmd(editor, filename), nil
196197
}
197198

198199
// Quote wraps a message in platform-specific quotation marks
@@ -239,7 +240,7 @@ func (c *OSCommand) AppendLineToFile(filename, line string) error {
239240

240241
// CreateTempFile writes a string to a new temp file and returns the file's name
241242
func (c *OSCommand) CreateTempFile(filename, content string) (string, error) {
242-
tmpfile, err := ioutil.TempFile("", filename)
243+
tmpfile, err := os.CreateTemp("", filename)
243244
if err != nil {
244245
c.Log.Error(err)
245246
return "", WrapError(err)
@@ -301,7 +302,7 @@ func (c *OSCommand) GetLazydockerPath() string {
301302

302303
// RunCustomCommand returns the pointer to a custom command
303304
func (c *OSCommand) RunCustomCommand(command string) *exec.Cmd {
304-
return c.PrepareSubProcess(c.Platform.shell, c.Platform.shellArg, command)
305+
return c.NewCmd(c.Platform.shell, c.Platform.shellArg, command)
305306
}
306307

307308
// PipeCommands runs a heap of commands and pipes their inputs/outputs together like A | B | C
@@ -341,7 +342,7 @@ func (c *OSCommand) PipeCommands(commandStrings ...string) error {
341342
c.Log.Error(err)
342343
}
343344

344-
if b, err := ioutil.ReadAll(stderr); err == nil {
345+
if b, err := io.ReadAll(stderr); err == nil {
345346
if len(b) > 0 {
346347
finalErrors = append(finalErrors, string(b))
347348
}

pkg/commands/os_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package commands
22

33
import (
44
"fmt"
5-
"io/ioutil"
65
"os"
76
"os/exec"
87
"testing"
@@ -90,7 +89,7 @@ func TestOSCommandEditFile(t *testing.T) {
9089

9190
assert.EqualValues(t, "nano", name)
9291

93-
return nil
92+
return exec.Command("exit", "0")
9493
},
9594
func(env string) string {
9695
if env == "VISUAL" {
@@ -112,7 +111,7 @@ func TestOSCommandEditFile(t *testing.T) {
112111

113112
assert.EqualValues(t, "emacs", name)
114113

115-
return nil
114+
return exec.Command("exit", "0")
116115
},
117116
func(env string) string {
118117
if env == "EDITOR" {
@@ -134,7 +133,7 @@ func TestOSCommandEditFile(t *testing.T) {
134133

135134
assert.EqualValues(t, "vi", name)
136135

137-
return nil
136+
return exec.Command("exit", "0")
138137
},
139138
func(env string) string {
140139
return ""
@@ -290,7 +289,7 @@ func TestOSCommandCreateTempFile(t *testing.T) {
290289
func(path string, err error) {
291290
assert.NoError(t, err)
292291

293-
content, err := ioutil.ReadFile(path)
292+
content, err := os.ReadFile(path)
294293
assert.NoError(t, err)
295294

296295
assert.Equal(t, "content", string(content))

pkg/commands/ssh/ssh.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"net"
98
"net/url"
109
"os"
@@ -37,7 +36,7 @@ func NewSSHHandler(oSCommand CmdKiller) *SSHHandler {
3736
return (&net.Dialer{}).DialContext(ctx, network, addr)
3837
},
3938
startCmd: func(cmd *exec.Cmd) error { return cmd.Start() },
40-
tempDir: ioutil.TempDir,
39+
tempDir: os.MkdirTemp,
4140
getenv: os.Getenv,
4241
setenv: os.Setenv,
4342
}

0 commit comments

Comments
 (0)