Add Detail View for Login (#212)

Impruve & Refactor AddLogin

Impruve login comands

Remove unused Package + Vars

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/212
Reviewed-by: Norwin <noerw@noreply.gitea.io>
Reviewed-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
6543
2020-10-02 15:57:48 +00:00
parent 3ee5501257
commit e23f56e81c
8 changed files with 119 additions and 72 deletions

View File

@ -5,7 +5,11 @@
package cmd
import (
"fmt"
"code.gitea.io/tea/cmd/login"
"code.gitea.io/tea/modules/config"
"code.gitea.io/tea/modules/print"
"github.com/urfave/cli/v2"
)
@ -16,7 +20,8 @@ var CmdLogin = cli.Command{
Aliases: []string{"login"},
Usage: "Log in to a Gitea server",
Description: `Log in to a Gitea server`,
Action: login.RunLoginAddInteractive, // TODO show list if no arg & detail if login as arg
ArgsUsage: "[<login name>]",
Action: runLogins,
Subcommands: []*cli.Command{
&login.CmdLoginList,
&login.CmdLoginAdd,
@ -24,3 +29,25 @@ var CmdLogin = cli.Command{
&login.CmdLoginSetDefault,
},
}
func runLogins(ctx *cli.Context) error {
if ctx.Args().Len() == 1 {
return runLoginDetail(ctx.Args().First())
}
return login.RunLoginList(ctx)
}
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)
return nil
}
print.LoginDetails(l)
return nil
}

View File

@ -15,7 +15,7 @@ import (
var CmdLoginAdd = cli.Command{
Name: "add",
Usage: "Add a Gitea login",
Description: `Add a Gitea login`,
Description: `Add a Gitea login, without args it will create one interactively`,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
@ -23,12 +23,11 @@ var CmdLoginAdd = cli.Command{
Usage: "Login name",
},
&cli.StringFlag{
Name: "url",
Aliases: []string{"u"},
Value: "https://try.gitea.io",
EnvVars: []string{"GITEA_SERVER_URL"},
Usage: "Server URL",
Required: true,
Name: "url",
Aliases: []string{"u"},
Value: "https://gitea.com",
EnvVars: []string{"GITEA_SERVER_URL"},
Usage: "Server URL",
},
&cli.StringFlag{
Name: "token",
@ -65,7 +64,12 @@ var CmdLoginAdd = cli.Command{
}
func runLoginAdd(ctx *cli.Context) error {
// TODO: if no args -> interactive
// if no args create login interactive
if ctx.Args().Len() == 0 {
return interact.CreateLogin()
}
// else use args to add login
return config.AddLogin(
ctx.String("name"),
ctx.String("token"),
@ -75,9 +79,3 @@ func runLoginAdd(ctx *cli.Context) error {
ctx.String("url"),
ctx.Bool("insecure"))
}
// RunLoginAddInteractive create login interactive
// TODO: should be unexported
func RunLoginAddInteractive(_ *cli.Context) error {
return interact.CreateLogin()
}

View File

@ -21,11 +21,12 @@ var CmdLoginList = cli.Command{
Aliases: []string{"list"},
Usage: "List Gitea logins",
Description: `List Gitea logins`,
Action: runLoginList,
Action: RunLoginList,
Flags: []cli.Flag{&flags.OutputFlag},
}
func runLoginList(ctx *cli.Context) error {
// RunLoginList list all logins
func RunLoginList(ctx *cli.Context) error {
err := config.LoadConfig()
if err != nil {
log.Fatal(err)