mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
add some more linters
This commit is contained in:
@ -26,11 +26,13 @@ func (self *cmdObjRunner) runWithCredentialHandling(cmdObj ICmdObj) error {
|
||||
case PROMPT:
|
||||
return self.RunAndDetectCredentialRequest(cmdObj, self.guiIO.promptForCredentialFn)
|
||||
case FAIL:
|
||||
return self.RunAndDetectCredentialRequest(cmdObj, func(CredentialName) string { return "\n" })
|
||||
return self.RunAndDetectCredentialRequest(cmdObj, func(CredentialType) string { return "\n" })
|
||||
case NONE:
|
||||
// we should never land here
|
||||
return errors.New("runWithCredentialHandling called but cmdObj does not have a a credential strategy")
|
||||
}
|
||||
|
||||
// we should never land here
|
||||
return errors.New("runWithCredentialHandling called but cmdObj does not have a a credential strategy")
|
||||
return errors.New("unexpected credential strategy")
|
||||
}
|
||||
|
||||
func (self *cmdObjRunner) Run(cmdObj ICmdObj) error {
|
||||
|
@ -13,27 +13,27 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
||||
type CredentialName string
|
||||
type CredentialType int
|
||||
|
||||
const (
|
||||
Password CredentialName = "password"
|
||||
Username = "username"
|
||||
Passphrase = "passphrase"
|
||||
Password CredentialType = iota
|
||||
Username
|
||||
Passphrase
|
||||
)
|
||||
|
||||
// RunAndDetectCredentialRequest detect a username / password / passphrase question in a command
|
||||
// promptUserForCredential is a function that gets executed when this function detect you need to fillin a password or passphrase
|
||||
// The promptUserForCredential argument will be "username", "password" or "passphrase" and expects the user's password/passphrase or username back
|
||||
func (self *cmdObjRunner) RunAndDetectCredentialRequest(cmdObj ICmdObj, promptUserForCredential func(CredentialName) string) error {
|
||||
func (self *cmdObjRunner) RunAndDetectCredentialRequest(cmdObj ICmdObj, promptUserForCredential func(CredentialType) string) error {
|
||||
ttyText := ""
|
||||
err := self.RunCommandWithOutputLive(cmdObj, func(word string) string {
|
||||
ttyText = ttyText + " " + word
|
||||
|
||||
prompts := map[string]CredentialName{
|
||||
`.+'s password:`: "password",
|
||||
`Password\s*for\s*'.+':`: "password",
|
||||
`Username\s*for\s*'.+':`: "username",
|
||||
`Enter\s*passphrase\s*for\s*key\s*'.+':`: "passphrase",
|
||||
prompts := map[string]CredentialType{
|
||||
`.+'s password:`: Password,
|
||||
`Password\s*for\s*'.+':`: Password,
|
||||
`Username\s*for\s*'.+':`: Username,
|
||||
`Enter\s*passphrase\s*for\s*key\s*'.+':`: Passphrase,
|
||||
}
|
||||
|
||||
for pattern, askFor := range prompts {
|
||||
|
@ -27,10 +27,10 @@ type guiIO struct {
|
||||
// this allows us to request info from the user like username/password, in the event
|
||||
// that a command requests it.
|
||||
// the 'credential' arg is something like 'username' or 'password'
|
||||
promptForCredentialFn func(credential CredentialName) string
|
||||
promptForCredentialFn func(credential CredentialType) string
|
||||
}
|
||||
|
||||
func NewGuiIO(log *logrus.Entry, logCommandFn func(string, bool), newCmdWriterFn func() io.Writer, promptForCredentialFn func(CredentialName) string) *guiIO {
|
||||
func NewGuiIO(log *logrus.Entry, logCommandFn func(string, bool), newCmdWriterFn func() io.Writer, promptForCredentialFn func(CredentialType) string) *guiIO {
|
||||
return &guiIO{
|
||||
log: log,
|
||||
logCommandFn: logCommandFn,
|
||||
@ -44,6 +44,6 @@ func NewNullGuiIO(log *logrus.Entry) *guiIO {
|
||||
log: log,
|
||||
logCommandFn: func(string, bool) {},
|
||||
newCmdWriterFn: func() io.Writer { return ioutil.Discard },
|
||||
promptForCredentialFn: func(CredentialName) string { return "" },
|
||||
promptForCredentialFn: func(CredentialType) string { return "" },
|
||||
}
|
||||
}
|
||||
|
@ -190,6 +190,7 @@ func TestOSCommandCreateTempFile(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
s := s
|
||||
t.Run(s.testName, func(t *testing.T) {
|
||||
s.test(NewDummyOSCommand().CreateTempFile(s.filename, s.content))
|
||||
})
|
||||
|
Reference in New Issue
Block a user