Fix login edit to check config existence (#987)

Fix https://gitea.com/gitea/tea/issues/561

Reviewed-on: https://gitea.com/gitea/tea/pulls/987
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Minjie Fang <wingsallen@gmail.com>
Co-committed-by: Minjie Fang <wingsallen@gmail.com>
This commit is contained in:
Minjie Fang
2026-05-10 01:28:06 +00:00
committed by Lunny Xiao
parent 19dd8b1b4b
commit 2b64762a32

View File

@@ -5,11 +5,13 @@ package login
import ( import (
"context" "context"
"fmt"
"os" "os"
"os/exec" "os/exec"
"code.gitea.io/tea/cmd/flags" "code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/config" "code.gitea.io/tea/modules/config"
"code.gitea.io/tea/modules/utils"
"github.com/skratchdot/open-golang/open" "github.com/skratchdot/open-golang/open"
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
@@ -27,12 +29,17 @@ var CmdLoginEdit = cli.Command{
} }
func runLoginEdit(_ context.Context, _ *cli.Command) error { func runLoginEdit(_ context.Context, _ *cli.Command) error {
ymlPath := config.GetConfigPath()
if e, ok := os.LookupEnv("EDITOR"); ok && e != "" { if e, ok := os.LookupEnv("EDITOR"); ok && e != "" {
cmd := exec.Command(e, config.GetConfigPath()) cmd := exec.Command(e, ymlPath)
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
return cmd.Run() return cmd.Run()
} }
return open.Start(config.GetConfigPath()) if exist, _ := utils.FileExist(ymlPath); !exist {
fmt.Printf("Config file does not exist, please run login add first\n")
return nil
}
return open.Start(ymlPath)
} }