diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index 160ec1677..3ac8f8f2b 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -128,6 +128,8 @@ var subCommands = map[string]*func([]string) error{ "be-child": &beChildFunc, } +var beCLI func() // non-nil if CLI is linked in + func main() { printVersion := false flag.IntVar(&args.verbose, "verbose", 0, "log verbosity level; 0 is default, 1 or higher are increasingly verbose") @@ -143,6 +145,11 @@ func main() { flag.StringVar(&args.birdSocketPath, "bird-socket", "", "path of the bird unix socket") flag.BoolVar(&printVersion, "version", false, "print version information and exit") + if len(os.Args) > 0 && filepath.Base(os.Args[0]) == "tailscale" && beCLI != nil { + beCLI() + return + } + if len(os.Args) > 1 { sub := os.Args[1] if fp, ok := subCommands[sub]; ok { diff --git a/cmd/tailscaled/with_cli.go b/cmd/tailscaled/with_cli.go new file mode 100644 index 000000000..578351fe3 --- /dev/null +++ b/cmd/tailscaled/with_cli.go @@ -0,0 +1,25 @@ +// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build ts_include_cli +// +build ts_include_cli + +package main + +import ( + "fmt" + "os" + + "tailscale.com/cmd/tailscale/cli" +) + +func init() { + beCLI = func() { + args := os.Args[1:] + if err := cli.Run(args); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + } +}