1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-12-13 23:45:45 +02:00

Merge branch 'master' into feature/rebasing

This commit is contained in:
Jesse Duffield
2019-02-11 21:02:53 +11:00
57 changed files with 1496 additions and 174 deletions

View File

@@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"regexp"
"strings"
"github.com/jesseduffield/lazygit/pkg/config"
@@ -57,6 +58,36 @@ func (c *OSCommand) RunCommandWithOutput(command string) (string, error) {
)
}
// RunCommandWithOutputLive runs RunCommandWithOutputLiveWrapper
func (c *OSCommand) RunCommandWithOutputLive(command string, output func(string) string) error {
return RunCommandWithOutputLiveWrapper(c, command, output)
}
// DetectUnamePass detect a username / password question in a command
// ask is a function that gets executen when this function detect you need to fillin a password
// The ask argument will be "username" or "password" and expects the user's password or username back
func (c *OSCommand) DetectUnamePass(command string, ask func(string) string) error {
ttyText := ""
errMessage := c.RunCommandWithOutputLive(command, func(word string) string {
ttyText = ttyText + " " + word
prompts := map[string]string{
"password": `Password\s*for\s*'.+':`,
"username": `Username\s*for\s*'.+':`,
}
for askFor, pattern := range prompts {
if match, _ := regexp.MatchString(pattern, ttyText); match {
ttyText = ""
return ask(askFor)
}
}
return ""
})
return errMessage
}
// RunCommand runs a command and just returns the error
func (c *OSCommand) RunCommand(command string) error {
_, err := c.RunCommandWithOutput(command)
@@ -186,7 +217,7 @@ func (c *OSCommand) CreateTempFile(filename, content string) (string, error) {
return "", err
}
if _, err := tmpfile.Write([]byte(content)); err != nil {
if _, err := tmpfile.WriteString(content); err != nil {
c.Log.Error(err)
return "", err
}