summaryrefslogtreecommitdiffstats
path: root/pkg/commands/os.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-02-11 21:02:53 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-02-11 21:02:53 +1100
commit3d343e9b574a2c99ebf5b30dc9a4dac2886f6d73 (patch)
treeef6b2f8c08a29349bcc56a16260dfefdb3ee872d /pkg/commands/os.go
parenta3656154906c1117f9c9bbe100aa585e43417897 (diff)
parent3a607061a2303d9f45d308de652fbebe7300b43c (diff)
Merge branch 'master' into feature/rebasing
Diffstat (limited to 'pkg/commands/os.go')
-rw-r--r--pkg/commands/os.go33
1 files changed, 32 insertions, 1 deletions
diff --git a/pkg/commands/os.go b/pkg/commands/os.go
index 829034eb8..186887b5d 100644
--- a/pkg/commands/os.go
+++ b/pkg/commands/os.go
@@ -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
}