diff --git a/cmd/tailscale/cli/cli.go b/cmd/tailscale/cli/cli.go index 2c952a1c0..929b63958 100644 --- a/cmd/tailscale/cli/cli.go +++ b/cmd/tailscale/cli/cli.go @@ -78,7 +78,9 @@ func CleanUpArgs(args []string) []string { return out } -var localClient tailscale.LocalClient +var localClient = tailscale.LocalClient{ + Socket: paths.DefaultTailscaledSocket(), +} // Run runs the CLI. The args do not include the binary name. func Run(args []string) (err error) { @@ -139,13 +141,6 @@ func Run(args []string) (err error) { return } - localClient.Socket = rootArgs.socket - rootCmd.FlagSet.Visit(func(f *flag.Flag) { - if f.Name == "socket" { - localClient.UseSocketOnly = true - } - }) - err = rootCmd.Run(context.Background()) if tailscale.IsAccessDeniedError(err) && os.Getuid() != 0 && runtime.GOOS != "windows" { return fmt.Errorf("%v\n\nUse 'sudo tailscale %s' or 'tailscale up --operator=$USER' to not require root.", err, strings.Join(args, " ")) @@ -158,7 +153,12 @@ func Run(args []string) (err error) { func newRootCmd() *ffcli.Command { rootfs := newFlagSet("tailscale") - rootfs.StringVar(&rootArgs.socket, "socket", paths.DefaultTailscaledSocket(), "path to tailscaled socket") + rootfs.Func("socket", "path to tailscaled socket", func(s string) error { + localClient.Socket = s + localClient.UseSocketOnly = true + return nil + }) + rootfs.Lookup("socket").DefValue = localClient.Socket rootCmd := &ffcli.Command{ Name: "tailscale", @@ -236,10 +236,6 @@ func fatalf(format string, a ...any) { // Fatalf, if non-nil, is used instead of log.Fatalf. var Fatalf func(format string, a ...any) -var rootArgs struct { - socket string -} - type cmdWalk struct { *ffcli.Command parents []*ffcli.Command diff --git a/cmd/tailscale/cli/ssh.go b/cmd/tailscale/cli/ssh.go index 1aceb10bb..68a6193af 100644 --- a/cmd/tailscale/cli/ssh.go +++ b/cmd/tailscale/cli/ssh.go @@ -110,8 +110,8 @@ func runSSH(ctx context.Context, args []string) error { // mode, so 'nc' isn't very useful. if runtime.GOOS != "darwin" { socketArg := "" - if rootArgs.socket != "" && rootArgs.socket != paths.DefaultTailscaledSocket() { - socketArg = fmt.Sprintf("--socket=%q", rootArgs.socket) + if localClient.Socket != "" && localClient.Socket != paths.DefaultTailscaledSocket() { + socketArg = fmt.Sprintf("--socket=%q", localClient.Socket) } argv = append(argv,