mirror of
https://gitea.com/gitea/tea.git
synced 2025-04-11 12:06:10 +02:00

It is very common to set `$EDITOR` to an terminal editor. To do so, we have to attach the stdin and stdout to interact with it. Otherwise the command would do nothing (when using `.Run()`) as it silently fails or hang the command (using `.Start()`) because it waits forever for input. Also attaching stderr to make debugging easier if someone has a non-compatible or broken `$EDITOR` set. Reviewed-on: https://gitea.com/gitea/tea/pulls/706 Reviewed-by: Lunny Xiao <lunny@noreply.gitea.com> Co-authored-by: Vincent Neubauer <v.neubauer@darlor.de> Co-committed-by: Vincent Neubauer <v.neubauer@darlor.de>
41 lines
949 B
Go
41 lines
949 B
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package login
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
|
"code.gitea.io/tea/modules/config"
|
|
|
|
"github.com/skratchdot/open-golang/open"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// CmdLoginEdit represents to login a gitea server.
|
|
var CmdLoginEdit = cli.Command{
|
|
Name: "edit",
|
|
Aliases: []string{"e"},
|
|
Usage: "Edit Gitea logins",
|
|
Description: `Edit Gitea logins`,
|
|
ArgsUsage: " ", // command does not accept arguments
|
|
Action: runLoginEdit,
|
|
Flags: []cli.Flag{&flags.OutputFlag},
|
|
}
|
|
|
|
func runLoginEdit(_ *cli.Context) error {
|
|
if e, ok := os.LookupEnv("EDITOR"); ok && e != "" {
|
|
cmd := exec.Command(e, config.GetConfigPath())
|
|
cmd.Stdin = os.Stdin
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
if err := cmd.Run(); err != nil {
|
|
log.Fatal(err.Error())
|
|
}
|
|
}
|
|
return open.Start(config.GetConfigPath())
|
|
}
|