mirror of
https://gitea.com/gitea/tea.git
synced 2026-09-15 19:38:13 +02:00
Implements #1087. Adds `tea login status [<login name>] [-o <format>]`, which verifies the stored token for one or all configured logins and reports: - login name/URL and default status - whether the token is valid (via `GET /api/v1/user`) - auth method and token expiry - whether the git credential helper is configured Machine-readable output is available via the usual `-o` formats with fields `name`, `url`, `user`, `valid`, `auth_method`, `token_expiry`, `helper`, and `default`. Reviewed-on: https://gitea.com/gitea/tea/pulls/1105 Reviewed-by: bircni <bircni@icloud.com>
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"gitea.dev/tea/cmd/login"
|
|
"gitea.dev/tea/modules/config"
|
|
"gitea.dev/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,
|
|
&login.CmdLoginStatus,
|
|
},
|
|
}
|
|
|
|
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, err := config.GetLoginByName(name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if l == nil {
|
|
fmt.Printf("Login '%s' do not exist\n\n", name)
|
|
return nil
|
|
}
|
|
|
|
print.LoginDetails(l)
|
|
return nil
|
|
}
|