1
0
mirror of https://gitea.com/Sirherobrine23/tea.git synced 2024-07-07 09:15:52 -03:00
tea/modules/interact/login.go
Norwin de5a00e807 Refactor addLoginMain() (#201)
simplify NormalizeURL

drop noisy log line

must have been introduced recently?

dont use PascalCase for default login names

...for readability.

🔥 opinionated commit

create GenerateLoginName()

fixes

fixup! Merge branch 'master' into refactor-loginMain

move GetOwnerAndRepo() to modules/utils/parse.go

Merge branch 'master' into refactor-loginMain

make linter happy

refactor addLoginMain()

Co-authored-by: Norwin Roosen <git@nroo.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/201
Reviewed-by: 6543 <6543@noreply.gitea.io>
Reviewed-by: Andrew Thornton <art27@cantab.net>
2020-09-30 19:44:22 +00:00

86 lines
2.0 KiB
Go

// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package interact
import (
"fmt"
"strings"
"code.gitea.io/tea/modules/config"
)
// CreateLogin create an login interactive
func CreateLogin() error {
var stdin, name, token, user, passwd, sshKey, giteaURL string
var insecure = false
fmt.Print("URL of Gitea instance: ")
if _, err := fmt.Scanln(&stdin); err != nil {
stdin = ""
}
giteaURL = strings.TrimSpace(stdin)
if len(giteaURL) == 0 {
fmt.Println("URL is required!")
return nil
}
name, err := config.GenerateLoginName(giteaURL, "")
if err != nil {
return err
}
fmt.Print("Name of new Login [" + name + "]: ")
if _, err := fmt.Scanln(&stdin); err != nil {
stdin = ""
}
if len(strings.TrimSpace(stdin)) != 0 {
name = strings.TrimSpace(stdin)
}
fmt.Print("Do you have a token [Yes/no]: ")
if _, err := fmt.Scanln(&stdin); err != nil {
stdin = ""
}
if len(stdin) != 0 && strings.ToLower(stdin[:1]) == "n" {
fmt.Print("Username: ")
if _, err := fmt.Scanln(&stdin); err != nil {
stdin = ""
}
user = strings.TrimSpace(stdin)
fmt.Print("Password: ")
if _, err := fmt.Scanln(&stdin); err != nil {
stdin = ""
}
passwd = strings.TrimSpace(stdin)
} else {
fmt.Print("Token: ")
if _, err := fmt.Scanln(&stdin); err != nil {
stdin = ""
}
token = strings.TrimSpace(stdin)
}
fmt.Print("Set Optional settings [yes/No]: ")
if _, err := fmt.Scanln(&stdin); err != nil {
stdin = ""
}
if len(stdin) != 0 && strings.ToLower(stdin[:1]) == "y" {
fmt.Print("SSH Key Path: ")
if _, err := fmt.Scanln(&stdin); err != nil {
stdin = ""
}
sshKey = strings.TrimSpace(stdin)
fmt.Print("Allow Insecure connections [yes/No]: ")
if _, err := fmt.Scanln(&stdin); err != nil {
stdin = ""
}
insecure = len(stdin) != 0 && strings.ToLower(stdin[:1]) == "y"
}
return config.AddLogin(name, token, user, passwd, sshKey, giteaURL, insecure)
}