Skip to content

Commit

Permalink
Removed some lazygit code
Browse files Browse the repository at this point in the history
  • Loading branch information
mjarkk committed Jul 6, 2019
1 parent cf31c23 commit fddbc7c
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 260 deletions.
416 changes: 223 additions & 193 deletions coverage.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/commands/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/sirupsen/logrus"
)

// DockerCommand is our main git interface
// DockerCommand is our main docker interface
type DockerCommand struct {
Log *logrus.Entry
OSCommand *OSCommand
Expand Down Expand Up @@ -59,7 +59,7 @@ func (c *DockerCommand) NewCommandObject(obj CommandObject) CommandObject {
return defaultObj
}

// NewDockerCommand it runs git commands
// NewDockerCommand it runs docker commands
func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*DockerCommand, error) {
cli, err := client.NewEnvClient()
if err != nil {
Expand Down
35 changes: 14 additions & 21 deletions pkg/commands/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/jesseduffield/lazydocker/pkg/utils"
"github.com/mgutz/str"
"github.com/sirupsen/logrus"
gitconfig "github.com/tcnksm/go-gitconfig"
)

// Platform stores the os state
Expand All @@ -33,23 +32,21 @@ type Platform struct {

// OSCommand holds all the os commands
type OSCommand struct {
Log *logrus.Entry
Platform *Platform
Config *config.AppConfig
command func(string, ...string) *exec.Cmd
getGlobalGitConfig func(string) (string, error)
getenv func(string) string
Log *logrus.Entry
Platform *Platform
Config *config.AppConfig
command func(string, ...string) *exec.Cmd
getenv func(string) string
}

// NewOSCommand os command runner
func NewOSCommand(log *logrus.Entry, config *config.AppConfig) *OSCommand {
return &OSCommand{
Log: log,
Platform: getPlatform(),
Config: config,
command: exec.Command,
getGlobalGitConfig: gitconfig.Global,
getenv: os.Getenv,
Log: log,
Platform: getPlatform(),
Config: config,
command: exec.Command,
getenv: os.Getenv,
}
}

Expand Down Expand Up @@ -79,7 +76,7 @@ func (c *OSCommand) RunExecutable(cmd *exec.Cmd) error {
return err
}

// ExecutableFromString takes a string like `git status` 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 {
splitCmd := str.ToArgv(commandStr)
// c.Log.Info(splitCmd)
Expand Down Expand Up @@ -154,11 +151,7 @@ func (c *OSCommand) OpenLink(link string) error {
// EditFile opens a file in a subprocess using whatever editor is available,
// falling back to core.editor, VISUAL, EDITOR, then vi
func (c *OSCommand) EditFile(filename string) (*exec.Cmd, error) {
editor, _ := c.getGlobalGitConfig("core.editor")

if editor == "" {
editor = c.getenv("VISUAL")
}
editor := c.getenv("VISUAL")
if editor == "" {
editor = c.getenv("EDITOR")
}
Expand All @@ -168,7 +161,7 @@ func (c *OSCommand) EditFile(filename string) (*exec.Cmd, error) {
}
}
if editor == "" {
return nil, errors.New("No editor defined in $VISUAL, $EDITOR, or git config")
return nil, errors.New("No editor defined in $VISUAL or $EDITOR")
}

return c.PrepareSubProcess(editor, filename), nil
Expand Down Expand Up @@ -265,7 +258,7 @@ func (c *OSCommand) RunPreparedCommand(cmd *exec.Cmd) error {

// GetLazydockerPath returns the path of the currently executed file
func (c *OSCommand) GetLazydockerPath() string {
ex, err := os.Executable() // get the executable path for git to use
ex, err := os.Executable() // get the executable path for docker to use
if err != nil {
ex = os.Args[0] // fallback to the first call argument if needed
}
Expand Down
45 changes: 5 additions & 40 deletions pkg/commands/os_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ func TestOSCommandRunCommand(t *testing.T) {
// TestOSCommandEditFile is a function.
func TestOSCommandEditFile(t *testing.T) {
type scenario struct {
filename string
command func(string, ...string) *exec.Cmd
getenv func(string) string
getGlobalGitConfig func(string) (string, error)
test func(*exec.Cmd, error)
filename string
command func(string, ...string) *exec.Cmd
getenv func(string) string
test func(*exec.Cmd, error)
}

scenarios := []scenario{
Expand All @@ -77,32 +76,8 @@ func TestOSCommandEditFile(t *testing.T) {
func(env string) string {
return ""
},
func(cf string) (string, error) {
return "", nil
},
func(cmd *exec.Cmd, err error) {
assert.EqualError(t, err, "No editor defined in $VISUAL, $EDITOR, or git config")
},
},
{
"test",
func(name string, arg ...string) *exec.Cmd {
if name == "which" {
return exec.Command("exit", "1")
}

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

return nil
},
func(env string) string {
return ""
},
func(cf string) (string, error) {
return "nano", nil
},
func(cmd *exec.Cmd, err error) {
assert.NoError(t, err)
assert.EqualError(t, err, "No editor defined in $VISUAL or $EDITOR")
},
},
{
Expand All @@ -123,9 +98,6 @@ func TestOSCommandEditFile(t *testing.T) {

return ""
},
func(cf string) (string, error) {
return "", nil
},
func(cmd *exec.Cmd, err error) {
assert.NoError(t, err)
},
Expand All @@ -148,9 +120,6 @@ func TestOSCommandEditFile(t *testing.T) {

return ""
},
func(cf string) (string, error) {
return "", nil
},
func(cmd *exec.Cmd, err error) {
assert.NoError(t, err)
},
Expand All @@ -169,9 +138,6 @@ func TestOSCommandEditFile(t *testing.T) {
func(env string) string {
return ""
},
func(cf string) (string, error) {
return "", nil
},
func(cmd *exec.Cmd, err error) {
assert.NoError(t, err)
},
Expand All @@ -181,7 +147,6 @@ func TestOSCommandEditFile(t *testing.T) {
for _, s := range scenarios {
OSCmd := NewDummyOSCommand()
OSCmd.command = s.command
OSCmd.getGlobalGitConfig = s.getGlobalGitConfig
OSCmd.getenv = s.getenv

s.test(OSCmd.EditFile(s.filename))
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type UserConfig struct {
// OS determines what defaults are set for opening files and links
OS OSConfig `yaml:"oS,omitempty"`

// Update is currently not being used, but like lazygit, it may be used down
// Update is currently not being used, but like lazydocker, it may be used down
// the line to help you update automatically.
Update UpdateConfig `yaml:"update,omitempty"`

Expand Down Expand Up @@ -352,13 +352,13 @@ func GetDefaultConfig() UserConfig {
}
}

// AppConfig contains the base configuration fields required for lazygit.
// AppConfig contains the base configuration fields required for lazydocker.
type AppConfig struct {
Debug bool `long:"debug" env:"DEBUG" default:"false"`
Version string `long:"version" env:"VERSION" default:"unversioned"`
Commit string `long:"commit" env:"COMMIT"`
BuildDate string `long:"build-date" env:"BUILD_DATE"`
Name string `long:"name" env:"NAME" default:"lazygit"`
Name string `long:"name" env:"NAME" default:"lazydocker"`
BuildSource string `long:"build-source" env:"BUILD_SOURCE" default:""`
UserConfig *UserConfig
ConfigDir string
Expand Down
2 changes: 1 addition & 1 deletion pkg/i18n/dutch.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func dutchSet() TranslationSet {
RunCustomCommand: "draai een vooraf bedacht aangepaste opdracht",

AnonymousReportingTitle: "Help mee met lazydocker beter maken",
AnonymousReportingPrompt: "Zou je anonieme data rapportage willen aanzetten om lazygit beter te kunnen maken? (enter/esc)",
AnonymousReportingPrompt: "Zou je anonieme data rapportage willen aanzetten om lazydocker beter te kunnen maken? (enter/esc)",

GlobalTitle: "Globaal",
MainTitle: "Hooft",
Expand Down

0 comments on commit fddbc7c

Please sign in to comment.