2020-12-14 05:28:54 -05:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2018-09-03 02:43:00 -04: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 11:57:48 -04:00
|
|
|
"fmt"
|
|
|
|
|
2020-09-30 01:11:33 -04:00
|
|
|
"code.gitea.io/tea/cmd/login"
|
2020-10-02 11:57:48 -04:00
|
|
|
"code.gitea.io/tea/modules/config"
|
|
|
|
"code.gitea.io/tea/modules/print"
|
2018-09-03 02:43:00 -04:00
|
|
|
|
2020-01-04 12:44:25 -05:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-09-03 02:43:00 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// CmdLogin represents to login a gitea server.
|
|
|
|
var CmdLogin = cli.Command{
|
2020-10-02 11:46:51 -04:00
|
|
|
Name: "logins",
|
|
|
|
Aliases: []string{"login"},
|
2020-12-21 08:37:20 -05:00
|
|
|
Category: catSetup,
|
2019-11-03 15:34:41 -05:00
|
|
|
Usage: "Log in to a Gitea server",
|
|
|
|
Description: `Log in to a Gitea server`,
|
2020-10-02 11:57:48 -04:00
|
|
|
ArgsUsage: "[<login name>]",
|
|
|
|
Action: runLogins,
|
2020-01-04 12:44:25 -05:00
|
|
|
Subcommands: []*cli.Command{
|
2020-09-30 01:11:33 -04:00
|
|
|
&login.CmdLoginList,
|
|
|
|
&login.CmdLoginAdd,
|
|
|
|
&login.CmdLoginEdit,
|
2020-12-14 05:28:54 -05:00
|
|
|
&login.CmdLoginDelete,
|
2020-09-30 01:11:33 -04:00
|
|
|
&login.CmdLoginSetDefault,
|
2018-09-03 02:43:00 -04:00
|
|
|
},
|
|
|
|
}
|
2020-10-02 11:57:48 -04: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 12:38:22 -05:00
|
|
|
print.LoginDetails(l)
|
2020-10-02 11:57:48 -04:00
|
|
|
return nil
|
|
|
|
}
|