File: login.go

package info (click to toggle)
tea-cli 0.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,648 kB
  • sloc: makefile: 116; sh: 17
file content (53 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package cmd

import (
	"context"
	"fmt"

	"code.gitea.io/tea/cmd/login"
	"code.gitea.io/tea/modules/config"
	"code.gitea.io/tea/modules/print"

	"github.com/urfave/cli/v3"
)

// CmdLogin represents to login a gitea server.
var CmdLogin = cli.Command{
	Name:        "logins",
	Aliases:     []string{"login"},
	Category:    catSetup,
	Usage:       "Log in to a Gitea server",
	Description: `Log in to a Gitea server`,
	ArgsUsage:   "[<login name>]",
	Action:      runLogins,
	Commands: []*cli.Command{
		&login.CmdLoginList,
		&login.CmdLoginAdd,
		&login.CmdLoginEdit,
		&login.CmdLoginDelete,
		&login.CmdLoginSetDefault,
		&login.CmdLoginHelper,
		&login.CmdLoginOAuthRefresh,
	},
}

func runLogins(ctx context.Context, cmd *cli.Command) error {
	if cmd.Args().Len() == 1 {
		return runLoginDetail(cmd.Args().First())
	}
	return login.RunLoginList(ctx, cmd)
}

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)
	return nil
}