2020-12-14 10:28:54 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2018-09-03 06:43:00 +00:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-10-02 15:57:48 +00:00
|
|
|
"fmt"
|
|
|
|
|
2020-09-30 05:11:33 +00:00
|
|
|
"code.gitea.io/tea/cmd/login"
|
2020-10-02 15:57:48 +00:00
|
|
|
"code.gitea.io/tea/modules/config"
|
|
|
|
"code.gitea.io/tea/modules/print"
|
2018-09-03 06:43:00 +00:00
|
|
|
|
2020-01-04 17:44:25 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-09-03 06:43:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// CmdLogin represents to login a gitea server.
|
|
|
|
var CmdLogin = cli.Command{
|
2020-10-02 15:46:51 +00:00
|
|
|
Name: "logins",
|
|
|
|
Aliases: []string{"login"},
|
2019-11-03 20:34:41 +00:00
|
|
|
Usage: "Log in to a Gitea server",
|
|
|
|
Description: `Log in to a Gitea server`,
|
2020-10-02 15:57:48 +00:00
|
|
|
ArgsUsage: "[<login name>]",
|
|
|
|
Action: runLogins,
|
2020-01-04 17:44:25 +00:00
|
|
|
Subcommands: []*cli.Command{
|
2020-09-30 05:11:33 +00:00
|
|
|
&login.CmdLoginList,
|
|
|
|
&login.CmdLoginAdd,
|
|
|
|
&login.CmdLoginEdit,
|
2020-12-14 10:28:54 +00:00
|
|
|
&login.CmdLoginDelete,
|
2020-09-30 05:11:33 +00:00
|
|
|
&login.CmdLoginSetDefault,
|
2018-09-03 06:43:00 +00:00
|
|
|
},
|
|
|
|
}
|
2020-10-02 15:57:48 +00:00
|
|
|
|
|
|
|
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 {
|
|
|
|
l := config.GetLoginByName(name)
|
|
|
|
if l == nil {
|
|
|
|
fmt.Printf("Login '%s' do not exist\n\n", name)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-12-15 17:38:22 +00:00
|
|
|
print.LoginDetails(l)
|
2020-10-02 15:57:48 +00:00
|
|
|
return nil
|
|
|
|
}
|