mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-02 18:08:30 +02:00
[Refactor] unexport config.Config var & move login tasks to task module (#288)
Unexport generateToken() move CreateLogin into task Create func config.SetDefaultLogin() Unexport loadConfig() & saveConfig unexport config var make SetDefaultLogin() case insensitive update func descriptions move FindSSHKey to task module Reviewed-on: https://gitea.com/gitea/tea/pulls/288 Reviewed-by: Norwin <noerw@noreply.gitea.io> Reviewed-by: Andrew Thornton <art27@cantab.net> Co-Authored-By: 6543 <6543@obermui.de> Co-Committed-By: 6543 <6543@obermui.de>
This commit is contained in:
@ -39,10 +39,6 @@ func runLogins(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
func runLoginDetail(name string) error {
|
||||
if err := config.LoadConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
l := config.GetLoginByName(name)
|
||||
if l == nil {
|
||||
fmt.Printf("Login '%s' do not exist\n\n", name)
|
||||
|
@ -5,8 +5,8 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
@ -70,7 +70,7 @@ func runLoginAdd(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
// else use args to add login
|
||||
return config.AddLogin(
|
||||
return task.CreateLogin(
|
||||
ctx.String("name"),
|
||||
ctx.String("token"),
|
||||
ctx.String("user"),
|
||||
|
@ -24,9 +24,6 @@ var CmdLoginSetDefault = cli.Command{
|
||||
}
|
||||
|
||||
func runLoginSetDefault(ctx *cli.Context) error {
|
||||
if err := config.LoadConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
if ctx.Args().Len() == 0 {
|
||||
l, err := config.GetDefaultLogin()
|
||||
if err != nil {
|
||||
@ -35,18 +32,7 @@ func runLoginSetDefault(ctx *cli.Context) error {
|
||||
fmt.Printf("Default Login: %s\n", l.Name)
|
||||
return nil
|
||||
}
|
||||
loginExist := false
|
||||
for i := range config.Config.Logins {
|
||||
config.Config.Logins[i].Default = false
|
||||
if config.Config.Logins[i].Name == ctx.Args().First() {
|
||||
config.Config.Logins[i].Default = true
|
||||
loginExist = true
|
||||
}
|
||||
}
|
||||
|
||||
if !loginExist {
|
||||
return fmt.Errorf("login '%s' not found", ctx.Args().First())
|
||||
}
|
||||
|
||||
return config.SaveConfig()
|
||||
name := ctx.Args().First()
|
||||
return config.SetDefaultLogin(name)
|
||||
}
|
||||
|
@ -21,6 +21,6 @@ var CmdLoginEdit = cli.Command{
|
||||
Flags: []cli.Flag{&flags.OutputFlag},
|
||||
}
|
||||
|
||||
func runLoginEdit(ctx *cli.Context) error {
|
||||
func runLoginEdit(_ *cli.Context) error {
|
||||
return open.Start(config.GetConfigPath())
|
||||
}
|
||||
|
@ -25,12 +25,12 @@ var CmdLoginList = cli.Command{
|
||||
}
|
||||
|
||||
// RunLoginList list all logins
|
||||
func RunLoginList(ctx *cli.Context) error {
|
||||
err := config.LoadConfig()
|
||||
func RunLoginList(_ *cli.Context) error {
|
||||
logins, err := config.GetLogins()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
print.LoginsList(config.Config.Logins, flags.GlobalOutputValue)
|
||||
print.LoginsList(logins, flags.GlobalOutputValue)
|
||||
return nil
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ var CmdLogout = cli.Command{
|
||||
}
|
||||
|
||||
func runLogout(ctx *cli.Context) error {
|
||||
err := config.LoadConfig()
|
||||
logins, err := config.GetLogins()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -40,8 +40,8 @@ func runLogout(ctx *cli.Context) error {
|
||||
name = ctx.String("name")
|
||||
} else if len(ctx.Args().First()) != 0 {
|
||||
name = ctx.Args().First()
|
||||
} else if len(config.Config.Logins) == 1 {
|
||||
name = config.Config.Logins[0].Name
|
||||
} else if len(logins) == 1 {
|
||||
name = logins[0].Name
|
||||
} else {
|
||||
return errors.New("Please specify a login name")
|
||||
}
|
||||
|
Reference in New Issue
Block a user