1
0
mirror of https://gitea.com/gitea/tea.git synced 2024-06-23 06:35:38 +00:00
tea/cmd/login.go
6543 c063329e9a [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>
2020-12-12 21:28:37 +08:00

51 lines
1.1 KiB
Go

// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package cmd
import (
"fmt"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/cmd/login"
"code.gitea.io/tea/modules/config"
"code.gitea.io/tea/modules/print"
"github.com/urfave/cli/v2"
)
// CmdLogin represents to login a gitea server.
var CmdLogin = cli.Command{
Name: "logins",
Aliases: []string{"login"},
Usage: "Log in to a Gitea server",
Description: `Log in to a Gitea server`,
ArgsUsage: "[<login name>]",
Action: runLogins,
Subcommands: []*cli.Command{
&login.CmdLoginList,
&login.CmdLoginAdd,
&login.CmdLoginEdit,
&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 {
l := config.GetLoginByName(name)
if l == nil {
fmt.Printf("Login '%s' do not exist\n\n", name)
return nil
}
print.LoginDetails(l, flags.GlobalOutputValue)
return nil
}