mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-11-04 03:05:26 +01:00 
			
		
		
		
	Check duplicated login name in interact mode when creating new login (#803)
Reviewed-on: https://gitea.com/gitea/tea/pulls/803
This commit is contained in:
		@@ -13,6 +13,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"code.gitea.io/sdk/gitea"
 | 
						"code.gitea.io/sdk/gitea"
 | 
				
			||||||
	"code.gitea.io/tea/modules/auth"
 | 
						"code.gitea.io/tea/modules/auth"
 | 
				
			||||||
 | 
						"code.gitea.io/tea/modules/config"
 | 
				
			||||||
	"code.gitea.io/tea/modules/task"
 | 
						"code.gitea.io/tea/modules/task"
 | 
				
			||||||
	"code.gitea.io/tea/modules/theme"
 | 
						"code.gitea.io/tea/modules/theme"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -57,14 +58,32 @@ func CreateLogin() error {
 | 
				
			|||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						validateFunc := func(s string) error {
 | 
				
			||||||
 | 
							if err := huh.ValidateNotEmpty()(s); err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							logins, err := config.GetLogins()
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							for _, login := range logins {
 | 
				
			||||||
 | 
								if login.Name == name {
 | 
				
			||||||
 | 
									return fmt.Errorf("Login with name '%s' already exists", name)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := huh.NewInput().
 | 
						if err := huh.NewInput().
 | 
				
			||||||
		Title("Name of new Login: ").
 | 
							Title("Name of new Login: ").
 | 
				
			||||||
		Value(&name).
 | 
							Value(&name).
 | 
				
			||||||
		Validate(huh.ValidateNotEmpty()).
 | 
							Validate(validateFunc).
 | 
				
			||||||
		WithTheme(theme.GetTheme()).
 | 
							WithTheme(theme.GetTheme()).
 | 
				
			||||||
		Run(); err != nil {
 | 
							Run(); err != nil {
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	printTitleAndContent("Name of new Login: ", name)
 | 
						printTitleAndContent("Name of new Login: ", name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	loginMethod, err := promptSelectV2("Login with: ", []string{"token", "ssh-key/certificate", "oauth"})
 | 
						loginMethod, err := promptSelectV2("Login with: ", []string{"token", "ssh-key/certificate", "oauth"})
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user