cmd/tailscale,feature/featuretags: make webbrowser and colorable deps omittable

Add new "webbrowser" and "colorable" feature tags so that the
github.com/toqueteos/webbrowser and mattn/go-colorable packages
can be excluded from minbox builds.

Updates #12614

Change-Id: Iabd38b242f5a56aa10ef2050113785283f4e1fe8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2026-02-08 04:46:09 +00:00
committed by Brad Fitzpatrick
parent 5eaaf9786b
commit a3215f1f9d
12 changed files with 119 additions and 23 deletions
-16
View File
@@ -21,8 +21,6 @@ import (
"text/tabwriter"
"time"
"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
"github.com/peterbourgon/ff/v3/ffcli"
"tailscale.com/client/local"
"tailscale.com/cmd/tailscale/cli/ffcomplete"
@@ -484,20 +482,6 @@ func countFlags(fs *flag.FlagSet) (n int) {
return n
}
// colorableOutput returns a colorable writer if stdout is a terminal (not, say,
// redirected to a file or pipe), the Stdout writer is os.Stdout (we're not
// embedding the CLI in wasm or a mobile app), and NO_COLOR is not set (see
// https://no-color.org/). If any of those is not the case, ok is false
// and w is Stdout.
func colorableOutput() (w io.Writer, ok bool) {
if Stdout != os.Stdout ||
os.Getenv("NO_COLOR") != "" ||
!isatty.IsTerminal(os.Stdout.Fd()) {
return Stdout, false
}
return colorable.NewColorableStdout(), true
}
type commandDoc struct {
Name string
Desc string
+28
View File
@@ -0,0 +1,28 @@
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
//go:build !ts_omit_colorable
package cli
import (
"io"
"os"
"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
)
// colorableOutput returns a colorable writer if stdout is a terminal (not, say,
// redirected to a file or pipe), the Stdout writer is os.Stdout (we're not
// embedding the CLI in wasm or a mobile app), and NO_COLOR is not set (see
// https://no-color.org/). If any of those is not the case, ok is false
// and w is Stdout.
func colorableOutput() (w io.Writer, ok bool) {
if Stdout != os.Stdout ||
os.Getenv("NO_COLOR") != "" ||
!isatty.IsTerminal(os.Stdout.Fd()) {
return Stdout, false
}
return colorable.NewColorableStdout(), true
}
+12
View File
@@ -0,0 +1,12 @@
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
//go:build ts_omit_colorable
package cli
import "io"
func colorableOutput() (w io.Writer, ok bool) {
return Stdout, false
}
+12
View File
@@ -0,0 +1,12 @@
// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
//go:build !ts_omit_webbrowser
package cli
import "github.com/toqueteos/webbrowser"
func init() {
hookOpenURL.Set(webbrowser.Open)
}
+5 -2
View File
@@ -18,7 +18,6 @@ import (
"text/tabwriter"
"github.com/peterbourgon/ff/v3/ffcli"
"github.com/toqueteos/webbrowser"
"golang.org/x/net/idna"
"tailscale.com/feature"
"tailscale.com/ipn"
@@ -113,7 +112,9 @@ func runStatus(ctx context.Context, args []string) error {
ln.Close()
}()
if statusArgs.browser {
go webbrowser.Open(statusURL)
if f, ok := hookOpenURL.GetOk(); ok {
go f(statusURL)
}
}
err = http.Serve(ln, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.RequestURI != "/" {
@@ -252,6 +253,8 @@ func runStatus(ctx context.Context, args []string) error {
return nil
}
var hookOpenURL feature.Hook[func(string) error]
var hookPrintFunnelStatus feature.Hook[func(context.Context)]
// isRunningOrStarting reports whether st is in state Running or Starting.
+1 -3
View File
@@ -21,8 +21,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
github.com/klauspost/compress/internal/snapref from github.com/klauspost/compress/zstd
github.com/klauspost/compress/zstd from tailscale.com/util/zstdframe
github.com/klauspost/compress/zstd/internal/xxhash from github.com/klauspost/compress/zstd
github.com/mattn/go-colorable from tailscale.com/cmd/tailscale/cli
github.com/mattn/go-isatty from github.com/mattn/go-colorable+
github.com/mattn/go-isatty from tailscale.com/util/prompt
💣 github.com/mdlayher/netlink from github.com/jsimonetti/rtnetlink+
💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+
💣 github.com/mdlayher/socket from github.com/mdlayher/netlink
@@ -38,7 +37,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
github.com/tailscale/wireguard-go/rwcancel from github.com/tailscale/wireguard-go/device+
github.com/tailscale/wireguard-go/tai64n from github.com/tailscale/wireguard-go/device
💣 github.com/tailscale/wireguard-go/tun from github.com/tailscale/wireguard-go/device+
github.com/toqueteos/webbrowser from tailscale.com/cmd/tailscale/cli
💣 go4.org/mem from tailscale.com/control/controlbase+
go4.org/netipx from tailscale.com/ipn/ipnlocal+
tailscale.com from tailscale.com/version
+2
View File
@@ -295,6 +295,8 @@ func TestMinTailscaledWithCLI(t *testing.T) {
"archive/tar": "unexpected archive/tar dep",
"tailscale.com/feature/conn25": "unexpected conn25 dep",
"regexp": "unexpected regexp dep; bloats binary",
"github.com/toqueteos/webbrowser": "unexpected webbrowser dep with ts_omit_webbrowser",
"github.com/mattn/go-colorable": "unexpected go-colorable dep with ts_omit_colorable",
},
}.Check(t)
}