mirror of
https://gitea.com/gitea/tea.git
synced 2025-10-30 16:55:25 +01:00
When there is no login detected, list all possible logins to select
This commit is contained in:
@@ -306,3 +306,39 @@ var tokenScopeOpts = []string{
|
||||
string(gitea.AccessTokenScopeReadApplication),
|
||||
string(gitea.AccessTokenScopeSudo),
|
||||
}
|
||||
|
||||
func LoginSelect() (*config.Login, error) {
|
||||
logins, err := config.GetLogins()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(logins) == 0 {
|
||||
return nil, errors.New("no gitea login configured")
|
||||
}
|
||||
if len(logins) == 1 {
|
||||
return &logins[0], nil
|
||||
}
|
||||
|
||||
loginNames := make([]string, 0, len(logins))
|
||||
for _, l := range logins {
|
||||
loginNames = append(loginNames, l.Name)
|
||||
}
|
||||
|
||||
defaultLogin, _ := config.GetDefaultLogin()
|
||||
var defaultValue string
|
||||
if defaultLogin != nil {
|
||||
defaultValue = defaultLogin.Name
|
||||
}
|
||||
|
||||
loginName, err := promptSelect("Select gitea login: ", loginNames, "", "", defaultValue)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, l := range logins {
|
||||
if l.Name == loginName {
|
||||
return &l, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("login name '%s' does not exist", loginName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user