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