mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-24 16:11:04 +00:00
Merge pull request #486 from jesseduffield/add-environ-to-cmd
This commit is contained in:
commit
b2525f4629
13 changed files with 36 additions and 37 deletions
2
.github/workflows/cd.yml
vendored
2
.github/workflows/cd.yml
vendored
|
|
@ -16,7 +16,7 @@ jobs:
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v1
|
uses: actions/setup-go@v1
|
||||||
with:
|
with:
|
||||||
go-version: 1.18.x
|
go-version: 1.20.x
|
||||||
- name: Run goreleaser
|
- name: Run goreleaser
|
||||||
uses: goreleaser/goreleaser-action@v1
|
uses: goreleaser/goreleaser-action@v1
|
||||||
with:
|
with:
|
||||||
|
|
|
||||||
10
.github/workflows/ci.yml
vendored
10
.github/workflows/ci.yml
vendored
|
|
@ -1,7 +1,7 @@
|
||||||
name: Continuous Integration
|
name: Continuous Integration
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GO_VERSION: 1.18
|
GO_VERSION: 1.20
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
|
@ -27,7 +27,7 @@ jobs:
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v1
|
uses: actions/setup-go@v1
|
||||||
with:
|
with:
|
||||||
go-version: 1.18.x
|
go-version: 1.20.x
|
||||||
- name: Cache build
|
- name: Cache build
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
|
|
@ -49,7 +49,7 @@ jobs:
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v1
|
uses: actions/setup-go@v1
|
||||||
with:
|
with:
|
||||||
go-version: 1.18.x
|
go-version: 1.20.x
|
||||||
- name: Cache build
|
- name: Cache build
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
|
|
@ -77,7 +77,7 @@ jobs:
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v1
|
uses: actions/setup-go@v1
|
||||||
with:
|
with:
|
||||||
go-version: 1.18.x
|
go-version: 1.20.x
|
||||||
- name: Cache build
|
- name: Cache build
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
|
|
@ -104,7 +104,7 @@ jobs:
|
||||||
- name: Setup Go
|
- name: Setup Go
|
||||||
uses: actions/setup-go@v1
|
uses: actions/setup-go@v1
|
||||||
with:
|
with:
|
||||||
go-version: 1.18.x
|
go-version: 1.20.x
|
||||||
- name: Cache build
|
- name: Cache build
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
|
|
|
||||||
|
|
@ -26,4 +26,5 @@ linters-settings:
|
||||||
max-func-lines: 0
|
max-func-lines: 0
|
||||||
|
|
||||||
run:
|
run:
|
||||||
go: 1.18
|
go: '1.20'
|
||||||
|
timeout: 10m
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
ARG BASE_IMAGE_BUILDER=golang
|
ARG BASE_IMAGE_BUILDER=golang
|
||||||
ARG ALPINE_VERSION=3.15
|
ARG ALPINE_VERSION=3.15
|
||||||
ARG GO_VERSION=1.18
|
ARG GO_VERSION=1.20
|
||||||
|
|
||||||
FROM ${BASE_IMAGE_BUILDER}:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder
|
FROM ${BASE_IMAGE_BUILDER}:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder
|
||||||
ARG GOARCH=amd64
|
ARG GOARCH=amd64
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -1,6 +1,6 @@
|
||||||
module github.com/jesseduffield/lazydocker
|
module github.com/jesseduffield/lazydocker
|
||||||
|
|
||||||
go 1.18
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/OpenPeeDeeP/xdg v0.2.1-0.20190312153938-4ba9e1eb294c
|
github.com/OpenPeeDeeP/xdg v0.2.1-0.20190312153938-4ba9e1eb294c
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ func (c *Container) Attach() (*exec.Cmd, error) {
|
||||||
|
|
||||||
c.Log.Warn(fmt.Sprintf("attaching to container %s", c.Name))
|
c.Log.Warn(fmt.Sprintf("attaching to container %s", c.Name))
|
||||||
// TODO: use SDK
|
// TODO: use SDK
|
||||||
cmd := c.OSCommand.PrepareSubProcess("docker", "attach", "--sig-proxy=false", c.ID)
|
cmd := c.OSCommand.NewCmd("docker", "attach", "--sig-proxy=false", c.ID)
|
||||||
return cmd, nil
|
return cmd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
|
|
||||||
"github.com/jesseduffield/lazydocker/pkg/config"
|
"github.com/jesseduffield/lazydocker/pkg/config"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/i18n"
|
"github.com/jesseduffield/lazydocker/pkg/i18n"
|
||||||
|
|
@ -31,7 +31,7 @@ func NewDummyAppConfig() *config.AppConfig {
|
||||||
// NewDummyLog creates a new dummy Log for testing
|
// NewDummyLog creates a new dummy Log for testing
|
||||||
func NewDummyLog() *logrus.Entry {
|
func NewDummyLog() *logrus.Entry {
|
||||||
log := logrus.New()
|
log := logrus.New()
|
||||||
log.Out = ioutil.Discard
|
log.Out = io.Discard
|
||||||
return log.WithField("test", "test")
|
return log.WithField("test", "test")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package commands
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -87,7 +87,7 @@ func (c *OSCommand) RunExecutable(cmd *exec.Cmd) error {
|
||||||
// ExecutableFromString takes a string like `docker ps -a` and returns an executable command for it
|
// ExecutableFromString takes a string like `docker ps -a` and returns an executable command for it
|
||||||
func (c *OSCommand) ExecutableFromString(commandStr string) *exec.Cmd {
|
func (c *OSCommand) ExecutableFromString(commandStr string) *exec.Cmd {
|
||||||
splitCmd := str.ToArgv(commandStr)
|
splitCmd := str.ToArgv(commandStr)
|
||||||
return c.command(splitCmd[0], splitCmd[1:]...)
|
return c.NewCmd(splitCmd[0], splitCmd[1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same as ExecutableFromString but cancellable via a context
|
// Same as ExecutableFromString but cancellable via a context
|
||||||
|
|
@ -96,6 +96,12 @@ func (c *OSCommand) ExecutableFromStringContext(ctx context.Context, commandStr
|
||||||
return exec.CommandContext(ctx, splitCmd[0], splitCmd[1:]...)
|
return exec.CommandContext(ctx, splitCmd[0], splitCmd[1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *OSCommand) NewCmd(cmdName string, commandArgs ...string) *exec.Cmd {
|
||||||
|
cmd := c.command(cmdName, commandArgs...)
|
||||||
|
cmd.Env = os.Environ()
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
func (c *OSCommand) NewCommandStringWithShell(commandStr string) string {
|
func (c *OSCommand) NewCommandStringWithShell(commandStr string) string {
|
||||||
var quotedCommand string
|
var quotedCommand string
|
||||||
// Windows does not seem to like quotes around the command
|
// Windows does not seem to like quotes around the command
|
||||||
|
|
@ -187,12 +193,7 @@ func (c *OSCommand) EditFile(filename string) (*exec.Cmd, error) {
|
||||||
return nil, errors.New("No editor defined in $VISUAL or $EDITOR")
|
return nil, errors.New("No editor defined in $VISUAL or $EDITOR")
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.PrepareSubProcess(editor, filename), nil
|
return c.NewCmd(editor, filename), nil
|
||||||
}
|
|
||||||
|
|
||||||
// PrepareSubProcess iniPrepareSubProcessrocess then tells the Gui to switch to it
|
|
||||||
func (c *OSCommand) PrepareSubProcess(cmdName string, commandArgs ...string) *exec.Cmd {
|
|
||||||
return c.command(cmdName, commandArgs...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quote wraps a message in platform-specific quotation marks
|
// Quote wraps a message in platform-specific quotation marks
|
||||||
|
|
@ -239,7 +240,7 @@ func (c *OSCommand) AppendLineToFile(filename, line string) error {
|
||||||
|
|
||||||
// CreateTempFile writes a string to a new temp file and returns the file's name
|
// CreateTempFile writes a string to a new temp file and returns the file's name
|
||||||
func (c *OSCommand) CreateTempFile(filename, content string) (string, error) {
|
func (c *OSCommand) CreateTempFile(filename, content string) (string, error) {
|
||||||
tmpfile, err := ioutil.TempFile("", filename)
|
tmpfile, err := os.CreateTemp("", filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Log.Error(err)
|
c.Log.Error(err)
|
||||||
return "", WrapError(err)
|
return "", WrapError(err)
|
||||||
|
|
@ -301,7 +302,7 @@ func (c *OSCommand) GetLazydockerPath() string {
|
||||||
|
|
||||||
// RunCustomCommand returns the pointer to a custom command
|
// RunCustomCommand returns the pointer to a custom command
|
||||||
func (c *OSCommand) RunCustomCommand(command string) *exec.Cmd {
|
func (c *OSCommand) RunCustomCommand(command string) *exec.Cmd {
|
||||||
return c.PrepareSubProcess(c.Platform.shell, c.Platform.shellArg, command)
|
return c.NewCmd(c.Platform.shell, c.Platform.shellArg, command)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PipeCommands runs a heap of commands and pipes their inputs/outputs together like A | B | C
|
// 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 {
|
||||||
c.Log.Error(err)
|
c.Log.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if b, err := ioutil.ReadAll(stderr); err == nil {
|
if b, err := io.ReadAll(stderr); err == nil {
|
||||||
if len(b) > 0 {
|
if len(b) > 0 {
|
||||||
finalErrors = append(finalErrors, string(b))
|
finalErrors = append(finalErrors, string(b))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -90,7 +89,7 @@ func TestOSCommandEditFile(t *testing.T) {
|
||||||
|
|
||||||
assert.EqualValues(t, "nano", name)
|
assert.EqualValues(t, "nano", name)
|
||||||
|
|
||||||
return nil
|
return exec.Command("exit", "0")
|
||||||
},
|
},
|
||||||
func(env string) string {
|
func(env string) string {
|
||||||
if env == "VISUAL" {
|
if env == "VISUAL" {
|
||||||
|
|
@ -112,7 +111,7 @@ func TestOSCommandEditFile(t *testing.T) {
|
||||||
|
|
||||||
assert.EqualValues(t, "emacs", name)
|
assert.EqualValues(t, "emacs", name)
|
||||||
|
|
||||||
return nil
|
return exec.Command("exit", "0")
|
||||||
},
|
},
|
||||||
func(env string) string {
|
func(env string) string {
|
||||||
if env == "EDITOR" {
|
if env == "EDITOR" {
|
||||||
|
|
@ -134,7 +133,7 @@ func TestOSCommandEditFile(t *testing.T) {
|
||||||
|
|
||||||
assert.EqualValues(t, "vi", name)
|
assert.EqualValues(t, "vi", name)
|
||||||
|
|
||||||
return nil
|
return exec.Command("exit", "0")
|
||||||
},
|
},
|
||||||
func(env string) string {
|
func(env string) string {
|
||||||
return ""
|
return ""
|
||||||
|
|
@ -290,7 +289,7 @@ func TestOSCommandCreateTempFile(t *testing.T) {
|
||||||
func(path string, err error) {
|
func(path string, err error) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
content, err := ioutil.ReadFile(path)
|
content, err := os.ReadFile(path)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "content", string(content))
|
assert.Equal(t, "content", string(content))
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -37,7 +36,7 @@ func NewSSHHandler(oSCommand CmdKiller) *SSHHandler {
|
||||||
return (&net.Dialer{}).DialContext(ctx, network, addr)
|
return (&net.Dialer{}).DialContext(ctx, network, addr)
|
||||||
},
|
},
|
||||||
startCmd: func(cmd *exec.Cmd) error { return cmd.Start() },
|
startCmd: func(cmd *exec.Cmd) error { return cmd.Start() },
|
||||||
tempDir: ioutil.TempDir,
|
tempDir: os.MkdirTemp,
|
||||||
getenv: os.Getenv,
|
getenv: os.Getenv,
|
||||||
setenv: os.Setenv,
|
setenv: os.Setenv,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -569,7 +568,7 @@ func loadUserConfig(configDir string, base *UserConfig) (*UserConfig, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := ioutil.ReadFile(fileName)
|
content, err := os.ReadFile(fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
|
@ -65,8 +65,8 @@ func (gui *Gui) runCommand(cmd *exec.Cmd, msg string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Stdin = nil
|
cmd.Stdin = nil
|
||||||
cmd.Stdout = ioutil.Discard
|
cmd.Stdout = io.Discard
|
||||||
cmd.Stderr = ioutil.Discard
|
cmd.Stderr = io.Discard
|
||||||
|
|
||||||
gui.promptToReturn()
|
gui.promptToReturn()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ func newDevelopmentLogger(config *config.AppConfig) *logrus.Logger {
|
||||||
|
|
||||||
func newProductionLogger() *logrus.Logger {
|
func newProductionLogger() *logrus.Logger {
|
||||||
log := logrus.New()
|
log := logrus.New()
|
||||||
log.Out = ioutil.Discard
|
log.Out = io.Discard
|
||||||
log.SetLevel(logrus.ErrorLevel)
|
log.SetLevel(logrus.ErrorLevel)
|
||||||
return log
|
return log
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue