mirror of
https://github.com/tailscale/tailscale.git
synced 2025-03-28 20:12:27 +00:00
cmd/tailscale/cli: clean up how optional commands get registered
Both @agottardo and I tripped over this today. Updates #cleanup Change-Id: I64380a03bfc952b9887b1512dbcadf26499ff1cd Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
8b9d5fd6bc
commit
e12b2a7267
@ -21,23 +21,21 @@ var advertiseArgs struct {
|
|||||||
|
|
||||||
// TODO(naman): This flag may move to set.go or serve_v2.go after the WIPCode
|
// TODO(naman): This flag may move to set.go or serve_v2.go after the WIPCode
|
||||||
// envknob is not needed.
|
// envknob is not needed.
|
||||||
var advertiseCmd = &ffcli.Command{
|
func advertiseCmd() *ffcli.Command {
|
||||||
Name: "advertise",
|
|
||||||
ShortUsage: "tailscale advertise --services=<services>",
|
|
||||||
ShortHelp: "Advertise this node as a destination for a service",
|
|
||||||
Exec: runAdvertise,
|
|
||||||
FlagSet: (func() *flag.FlagSet {
|
|
||||||
fs := newFlagSet("advertise")
|
|
||||||
fs.StringVar(&advertiseArgs.services, "services", "", "comma-separated services to advertise; each must start with \"svc:\" (e.g. \"svc:idp,svc:nas,svc:database\")")
|
|
||||||
return fs
|
|
||||||
})(),
|
|
||||||
}
|
|
||||||
|
|
||||||
func maybeAdvertiseCmd() []*ffcli.Command {
|
|
||||||
if !envknob.UseWIPCode() {
|
if !envknob.UseWIPCode() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return []*ffcli.Command{advertiseCmd}
|
return &ffcli.Command{
|
||||||
|
Name: "advertise",
|
||||||
|
ShortUsage: "tailscale advertise --services=<services>",
|
||||||
|
ShortHelp: "Advertise this node as a destination for a service",
|
||||||
|
Exec: runAdvertise,
|
||||||
|
FlagSet: (func() *flag.FlagSet {
|
||||||
|
fs := newFlagSet("advertise")
|
||||||
|
fs.StringVar(&advertiseArgs.services, "services", "", "comma-separated services to advertise; each must start with \"svc:\" (e.g. \"svc:idp,svc:nas,svc:database\")")
|
||||||
|
return fs
|
||||||
|
})(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runAdvertise(ctx context.Context, args []string) error {
|
func runAdvertise(ctx context.Context, args []string) error {
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"tailscale.com/cmd/tailscale/cli/ffcomplete"
|
"tailscale.com/cmd/tailscale/cli/ffcomplete"
|
||||||
"tailscale.com/envknob"
|
"tailscale.com/envknob"
|
||||||
"tailscale.com/paths"
|
"tailscale.com/paths"
|
||||||
|
"tailscale.com/util/slicesx"
|
||||||
"tailscale.com/version/distro"
|
"tailscale.com/version/distro"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -182,7 +183,7 @@ For help on subcommands, add --help after: "tailscale status --help".
|
|||||||
This CLI is still under active development. Commands and flags will
|
This CLI is still under active development. Commands and flags will
|
||||||
change in the future.
|
change in the future.
|
||||||
`),
|
`),
|
||||||
Subcommands: append([]*ffcli.Command{
|
Subcommands: nonNilCmds(
|
||||||
upCmd,
|
upCmd,
|
||||||
downCmd,
|
downCmd,
|
||||||
setCmd,
|
setCmd,
|
||||||
@ -214,7 +215,8 @@ change in the future.
|
|||||||
debugCmd,
|
debugCmd,
|
||||||
driveCmd,
|
driveCmd,
|
||||||
idTokenCmd,
|
idTokenCmd,
|
||||||
}, maybeAdvertiseCmd()...),
|
advertiseCmd(),
|
||||||
|
),
|
||||||
FlagSet: rootfs,
|
FlagSet: rootfs,
|
||||||
Exec: func(ctx context.Context, args []string) error {
|
Exec: func(ctx context.Context, args []string) error {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
@ -239,6 +241,10 @@ change in the future.
|
|||||||
return rootCmd
|
return rootCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func nonNilCmds(cmds ...*ffcli.Command) []*ffcli.Command {
|
||||||
|
return slicesx.Filter(cmds[:0], cmds, func(c *ffcli.Command) bool { return c != nil })
|
||||||
|
}
|
||||||
|
|
||||||
func fatalf(format string, a ...any) {
|
func fatalf(format string, a ...any) {
|
||||||
if Fatalf != nil {
|
if Fatalf != nil {
|
||||||
Fatalf(format, a...)
|
Fatalf(format, a...)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user