Add git helper (#612)

Add support to tea login with helper same another tools and `gh`

Reviewed-on: https://gitea.com/gitea/tea/pulls/612
Reviewed-by: 6543 <6543@obermui.de>
Co-authored-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
Co-committed-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
This commit is contained in:
Matheus Sampaio Queiroga
2024-08-26 11:34:36 +00:00
committed by 6543
parent a35bf931ae
commit 2984ad4964
9 changed files with 226 additions and 186 deletions

View File

@ -18,10 +18,11 @@ import (
func CreateLogin() error {
var (
name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint string
insecure, sshAgent, versionCheck bool
insecure, sshAgent, versionCheck, helper bool
)
versionCheck = true
helper = false
promptI := &survey.Input{Message: "URL of Gitea instance: "}
if err := survey.AskOne(promptI, &giteaURL, survey.WithValidator(survey.Required)); err != nil {
@ -38,12 +39,12 @@ func CreateLogin() error {
return err
}
promptI = &survey.Input{Message: "Name of new Login [" + name + "]: "}
promptI = &survey.Input{Message: "Name of new Login: ", Default: name}
if err := survey.AskOne(promptI, &name); err != nil {
return err
}
loginMethod, err := promptSelect("Login with: ", []string{"token", "ssh-key/certificate"}, "", "")
loginMethod, err := promptSelectV2("Login with: ", []string{"token", "ssh-key/certificate"})
if err != nil {
return err
}
@ -145,6 +146,14 @@ func CreateLogin() error {
return err
}
promptYN = &survey.Confirm{
Message: "Add git helper: ",
Default: false,
}
if err = survey.AskOne(promptYN, &helper); err != nil {
return err
}
promptYN = &survey.Confirm{
Message: "Check version of Gitea instance: ",
Default: true,
@ -155,7 +164,7 @@ func CreateLogin() error {
}
return task.CreateLogin(name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint, insecure, sshAgent, versionCheck)
return task.CreateLogin(name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint, insecure, sshAgent, versionCheck, helper)
}
var tokenScopeOpts = []string{

View File

@ -127,6 +127,24 @@ func promptMultiSelect(prompt string, options []string, customVal string) ([]str
return promptCustomVal(prompt, customVal, selection)
}
// promptSelectV2 creates a generic select prompt
func promptSelectV2(prompt string, options []string) (string, error) {
if len(options) == 0 {
return "", nil
}
var selection string
promptA := &survey.Select{
Message: prompt,
Options: options,
VimMode: true,
Default: options[0],
}
if err := survey.AskOne(promptA, &selection); err != nil {
return "", err
}
return selection, nil
}
// promptSelect creates a generic select prompt, with processing of custom values or none-option.
func promptSelect(prompt string, options []string, customVal, noneVal string) (string, error) {
var selection string