cmd/tailscale/cli: omit "file" subcommand if taildrop is omitted from build

Updates #15812
Updates #12614

Change-Id: Ic945b26a127ba15399abdaab8fe43b1cfa64d874
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2025-05-06 21:18:46 -07:00 committed by Brad Fitzpatrick
parent 7cc2837594
commit 48dacf1bf7
2 changed files with 26 additions and 9 deletions

View File

@ -207,6 +207,8 @@ func noDupFlagify(c *ffcli.Command) {
} }
} }
var fileCmd func() *ffcli.Command
func newRootCmd() *ffcli.Command { func newRootCmd() *ffcli.Command {
rootfs := newFlagSet("tailscale") rootfs := newFlagSet("tailscale")
rootfs.Func("socket", "path to tailscaled socket", func(s string) error { rootfs.Func("socket", "path to tailscaled socket", func(s string) error {
@ -247,7 +249,7 @@ change in the future.
serveCmd(), serveCmd(),
versionCmd, versionCmd,
webCmd, webCmd,
fileCmd, nilOrCall(fileCmd),
bugReportCmd, bugReportCmd,
certCmd, certCmd,
netlockCmd, netlockCmd,
@ -286,6 +288,13 @@ func nonNilCmds(cmds ...*ffcli.Command) []*ffcli.Command {
return slicesx.AppendNonzero(cmds[:0], cmds) return slicesx.AppendNonzero(cmds[:0], cmds)
} }
func nilOrCall(f func() *ffcli.Command) *ffcli.Command {
if f == nil {
return nil
}
return f()
}
func fatalf(format string, a ...any) { func fatalf(format string, a ...any) {
if Fatalf != nil { if Fatalf != nil {
Fatalf(format, a...) Fatalf(format, a...)

View File

@ -1,6 +1,8 @@
// Copyright (c) Tailscale Inc & AUTHORS // Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause // SPDX-License-Identifier: BSD-3-Clause
//go:build !ts_omit_taildrop
package cli package cli
import ( import (
@ -38,7 +40,12 @@ import (
"tailscale.com/version" "tailscale.com/version"
) )
var fileCmd = &ffcli.Command{ func init() {
fileCmd = getFileCmd
}
func getFileCmd() *ffcli.Command {
return &ffcli.Command{
Name: "file", Name: "file",
ShortUsage: "tailscale file <cp|get> ...", ShortUsage: "tailscale file <cp|get> ...",
ShortHelp: "Send or receive files", ShortHelp: "Send or receive files",
@ -46,6 +53,7 @@ var fileCmd = &ffcli.Command{
fileCpCmd, fileCpCmd,
fileGetCmd, fileGetCmd,
}, },
}
} }
type countingReader struct { type countingReader struct {