diff --git a/cmd/tailscale/cli/cli.go b/cmd/tailscale/cli/cli.go index 623b4a3bd..f8d5e0880 100644 --- a/cmd/tailscale/cli/cli.go +++ b/cmd/tailscale/cli/cli.go @@ -68,11 +68,6 @@ change in the future. Exec: func(context.Context, []string) error { return flag.ErrHelp }, } - // Don't advertise the debug command, but it exists. - if strSliceContains(args, "debug") { - rootCmd.Subcommands = append(rootCmd.Subcommands, debugCmd) - } - if err := rootCmd.Parse(args); err != nil { return err } @@ -134,12 +129,3 @@ func pump(ctx context.Context, bc *ipn.BackendClient, conn net.Conn) { bc.GotNotifyMsg(msg) } } - -func strSliceContains(ss []string, s string) bool { - for _, v := range ss { - if v == s { - return true - } - } - return false -} diff --git a/cmd/tailscale/depaware.txt b/cmd/tailscale/depaware.txt index 559f214db..659a3c4f3 100644 --- a/cmd/tailscale/depaware.txt +++ b/cmd/tailscale/depaware.txt @@ -39,7 +39,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/cmd/tailscale/cli from tailscale.com/cmd/tailscale tailscale.com/control/controlclient from tailscale.com/ipn+ tailscale.com/derp from tailscale.com/derp/derphttp+ - tailscale.com/derp/derphttp from tailscale.com/cmd/tailscale/cli+ + tailscale.com/derp/derphttp from tailscale.com/net/netcheck+ tailscale.com/derp/derpmap from tailscale.com/cmd/tailscale/cli tailscale.com/disco from tailscale.com/derp+ tailscale.com/internal/deepprint from tailscale.com/ipn+ @@ -58,7 +58,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/net/stun from tailscale.com/net/netcheck+ tailscale.com/net/tlsdial from tailscale.com/control/controlclient+ tailscale.com/net/tsaddr from tailscale.com/ipn+ - 💣 tailscale.com/net/tshttpproxy from tailscale.com/cmd/tailscale/cli+ + 💣 tailscale.com/net/tshttpproxy from tailscale.com/control/controlclient+ tailscale.com/paths from tailscale.com/cmd/tailscale/cli tailscale.com/portlist from tailscale.com/ipn tailscale.com/safesocket from tailscale.com/cmd/tailscale/cli @@ -67,7 +67,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep W tailscale.com/tsconst from tailscale.com/net/interfaces tailscale.com/tstime from tailscale.com/wgengine/magicsock tailscale.com/types/empty from tailscale.com/control/controlclient+ - tailscale.com/types/key from tailscale.com/cmd/tailscale/cli+ + tailscale.com/types/key from tailscale.com/derp+ tailscale.com/types/logger from tailscale.com/cmd/tailscale/cli+ tailscale.com/types/nettype from tailscale.com/wgengine/magicsock tailscale.com/types/opt from tailscale.com/control/controlclient+ @@ -83,7 +83,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/wgengine from tailscale.com/ipn tailscale.com/wgengine/filter from tailscale.com/control/controlclient+ tailscale.com/wgengine/magicsock from tailscale.com/wgengine - 💣 tailscale.com/wgengine/monitor from tailscale.com/cmd/tailscale/cli+ + 💣 tailscale.com/wgengine/monitor from tailscale.com/wgengine tailscale.com/wgengine/router from tailscale.com/cmd/tailscale/cli+ tailscale.com/wgengine/router/dns from tailscale.com/ipn+ tailscale.com/wgengine/tsdns from tailscale.com/ipn+ diff --git a/cmd/tailscale/cli/debug.go b/cmd/tailscaled/debug.go similarity index 86% rename from cmd/tailscale/cli/debug.go rename to cmd/tailscaled/debug.go index 7873a65de..91ccb070a 100644 --- a/cmd/tailscale/cli/debug.go +++ b/cmd/tailscaled/debug.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package cli +package main import ( "context" @@ -18,7 +18,6 @@ import ( "os" "time" - "github.com/peterbourgon/ff/v2/ffcli" "tailscale.com/derp/derphttp" "tailscale.com/derp/derpmap" "tailscale.com/net/interfaces" @@ -28,28 +27,24 @@ import ( "tailscale.com/wgengine/monitor" ) -var debugCmd = &ffcli.Command{ - Name: "debug", - Exec: runDebug, - FlagSet: (func() *flag.FlagSet { - fs := flag.NewFlagSet("debug", flag.ExitOnError) - fs.BoolVar(&debugArgs.monitor, "monitor", false, "If true, run link monitor forever. Precludes all other options.") - fs.StringVar(&debugArgs.getURL, "get-url", "", "If non-empty, fetch provided URL.") - fs.StringVar(&debugArgs.derpCheck, "derp", "", "if non-empty, test a DERP ping via named region code") - return fs - })(), -} - var debugArgs struct { monitor bool getURL string derpCheck string } -func runDebug(ctx context.Context, args []string) error { - if len(args) > 0 { - return errors.New("unknown arguments") +func debugMode(args []string) error { + fs := flag.NewFlagSet("debug", flag.ExitOnError) + fs.BoolVar(&debugArgs.monitor, "monitor", false, "If true, run link monitor forever. Precludes all other options.") + fs.StringVar(&debugArgs.getURL, "get-url", "", "If non-empty, fetch provided URL.") + fs.StringVar(&debugArgs.derpCheck, "derp", "", "if non-empty, test a DERP ping via named region code") + if err := fs.Parse(args); err != nil { + return err + } + if len(fs.Args()) > 0 { + return errors.New("unknown non-flag debug subcommand arguments") } + ctx := context.Background() if debugArgs.derpCheck != "" { return checkDerp(ctx, debugArgs.derpCheck) } diff --git a/cmd/tailscaled/depaware.txt b/cmd/tailscaled/depaware.txt index 77ef9073c..45f4f3a08 100644 --- a/cmd/tailscaled/depaware.txt +++ b/cmd/tailscaled/depaware.txt @@ -71,6 +71,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/control/controlclient from tailscale.com/ipn+ tailscale.com/derp from tailscale.com/derp/derphttp+ tailscale.com/derp/derphttp from tailscale.com/net/netcheck+ + tailscale.com/derp/derpmap from tailscale.com/cmd/tailscaled tailscale.com/disco from tailscale.com/derp+ tailscale.com/internal/deepprint from tailscale.com/ipn+ tailscale.com/ipn from tailscale.com/ipn/ipnserver @@ -123,7 +124,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/wgengine from tailscale.com/cmd/tailscaled+ tailscale.com/wgengine/filter from tailscale.com/control/controlclient+ tailscale.com/wgengine/magicsock from tailscale.com/cmd/tailscaled+ - 💣 tailscale.com/wgengine/monitor from tailscale.com/wgengine + 💣 tailscale.com/wgengine/monitor from tailscale.com/wgengine+ tailscale.com/wgengine/netstack from tailscale.com/cmd/tailscaled tailscale.com/wgengine/router from tailscale.com/cmd/tailscaled+ tailscale.com/wgengine/router/dns from tailscale.com/ipn+ diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index a8acf514c..9e9aaced8 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -93,6 +93,13 @@ func main() { log.Fatalf("fixConsoleOutput: %v", err) } + if len(os.Args) > 1 && os.Args[1] == "debug" { + if err := debugMode(os.Args[2:]); err != nil { + log.Fatal(err) + } + return + } + flag.Parse() if flag.NArg() > 0 { log.Fatalf("tailscaled does not take non-flag arguments: %q", flag.Args())