cmd/tailscale/cli: add RunWithContext
Fixes #12778 Change-Id: If9f8b299cef0cb68f93b344845b5c6a5b7554d2c Signed-off-by: DeedleFake <deedlefake@users.noreply.github.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
9f48567bf1
commit
ad8ead9c94
@@ -93,8 +93,8 @@ var localClient = local.Client{
|
||||
Socket: paths.DefaultTailscaledSocket(),
|
||||
}
|
||||
|
||||
// Run runs the CLI. The args do not include the binary name.
|
||||
func Run(args []string) (err error) {
|
||||
// RunWithContext runs the CLI. The args do not include the binary name.
|
||||
func RunWithContext(ctx context.Context, args []string) (err error) {
|
||||
if runtime.GOOS == "linux" && os.Getenv("GOKRAZY_FIRST_START") == "1" && distro.Get() == distro.Gokrazy && os.Getppid() == 1 && len(args) == 0 {
|
||||
// We're running on gokrazy and the user did not specify 'up'.
|
||||
// Don't run the tailscale CLI and spam logs with usage; just exit.
|
||||
@@ -164,7 +164,7 @@ func Run(args []string) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
err = rootCmd.Run(context.Background())
|
||||
err = rootCmd.Run(ctx)
|
||||
if local.IsAccessDeniedError(err) && os.Getuid() != 0 && runtime.GOOS != "windows" {
|
||||
return fmt.Errorf("%v\n\nUse 'sudo tailscale %s'.\nTo not require root, use 'sudo tailscale set --operator=$USER' once.", err, strings.Join(args, " "))
|
||||
}
|
||||
@@ -174,6 +174,11 @@ func Run(args []string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Run is equivalent to calling [RunWithContext] with the background context.
|
||||
func Run(args []string) (err error) {
|
||||
return RunWithContext(context.Background(), args)
|
||||
}
|
||||
|
||||
type onceFlagValue struct {
|
||||
flag.Value
|
||||
set bool
|
||||
|
||||
Reference in New Issue
Block a user