From 44baa3463f32ba770f5a8e93ba8ab98deefca656 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 15 Jul 2020 18:56:07 -0700 Subject: [PATCH] cmd/tailscale/cli: add initial predicate func ActLikeCLI --- cmd/tailscale/cli/cli.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/tailscale/cli/cli.go b/cmd/tailscale/cli/cli.go index 684389ee3..1cadb0d6a 100644 --- a/cmd/tailscale/cli/cli.go +++ b/cmd/tailscale/cli/cli.go @@ -23,6 +23,21 @@ import ( "tailscale.com/safesocket" ) +// ActLikeCLI reports whether a GUI application should act like the +// CLI based on os.Args, GOOS, the context the process is running in +// (pty, parent PID), etc. +func ActLikeCLI() bool { + if len(os.Args) < 2 { + // TODO: on Windows & Mac, show usage if we're being run with a pty. + return false + } + switch os.Args[1] { + case "up", "status", "netcheck": + return true + } + return false +} + // Run runs the CLI. The args do npot include the binary name. func Run(args []string) error { rootfs := flag.NewFlagSet("tailscale", flag.ExitOnError)