cmd/tailscale/cli: don't ExitOnError on js/wasm

An os.Exit brings down the whole wasm module.

Updates #3157

Change-Id: I3daa97fd854715b901f3dbb04b57d841576b60b1
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-10-27 13:57:05 -07:00
parent b0b0a80318
commit 75de4e9cc2
11 changed files with 20 additions and 12 deletions

View File

@ -29,7 +29,7 @@
ShortHelp: "get TLS certs", ShortHelp: "get TLS certs",
ShortUsage: "cert [flags] <domain>", ShortUsage: "cert [flags] <domain>",
FlagSet: (func() *flag.FlagSet { FlagSet: (func() *flag.FlagSet {
fs := flag.NewFlagSet("cert", flag.ExitOnError) fs := newFlagSet("cert")
fs.StringVar(&certArgs.certFile, "cert-file", "", "output cert file or \"-\" for stdout; defaults to DOMAIN.crt if --cert-file and --key-file are both unset") fs.StringVar(&certArgs.certFile, "cert-file", "", "output cert file or \"-\" for stdout; defaults to DOMAIN.crt if --cert-file and --key-file are both unset")
fs.StringVar(&certArgs.keyFile, "key-file", "", "output cert file or \"-\" for stdout; defaults to DOMAIN.key if --cert-file and --key-file are both unset") fs.StringVar(&certArgs.keyFile, "key-file", "", "output cert file or \"-\" for stdout; defaults to DOMAIN.key if --cert-file and --key-file are both unset")
fs.BoolVar(&certArgs.serve, "serve-demo", false, "if true, serve on port :443 using the cert as a demo, instead of writing out the files to disk") fs.BoolVar(&certArgs.serve, "serve-demo", false, "if true, serve on port :443 using the cert as a demo, instead of writing out the files to disk")

View File

@ -77,6 +77,14 @@ func ActLikeCLI() bool {
return false return false
} }
func newFlagSet(name string) *flag.FlagSet {
onError := flag.ExitOnError
if runtime.GOOS == "js" {
onError = flag.ContinueOnError
}
return flag.NewFlagSet(name, onError)
}
// Run runs the CLI. The args do not include the binary name. // Run runs the CLI. The args do not include the binary name.
func Run(args []string) error { func Run(args []string) error {
if len(args) == 1 && (args[0] == "-V" || args[0] == "--version") { if len(args) == 1 && (args[0] == "-V" || args[0] == "--version") {
@ -90,7 +98,7 @@ func Run(args []string) error {
}) })
}) })
rootfs := flag.NewFlagSet("tailscale", flag.ExitOnError) rootfs := newFlagSet("tailscale")
rootfs.StringVar(&rootArgs.socket, "socket", paths.DefaultTailscaledSocket(), "path to tailscaled's unix socket") rootfs.StringVar(&rootArgs.socket, "socket", paths.DefaultTailscaledSocket(), "path to tailscaled's unix socket")
rootCmd := &ffcli.Command{ rootCmd := &ffcli.Command{

View File

@ -27,7 +27,7 @@
Name: "debug", Name: "debug",
Exec: runDebug, Exec: runDebug,
FlagSet: (func() *flag.FlagSet { FlagSet: (func() *flag.FlagSet {
fs := flag.NewFlagSet("debug", flag.ExitOnError) fs := newFlagSet("debug")
fs.BoolVar(&debugArgs.goroutines, "daemon-goroutines", false, "If true, dump the tailscaled daemon's goroutines") fs.BoolVar(&debugArgs.goroutines, "daemon-goroutines", false, "If true, dump the tailscaled daemon's goroutines")
fs.BoolVar(&debugArgs.ipn, "ipn", false, "If true, subscribe to IPN notifications") fs.BoolVar(&debugArgs.ipn, "ipn", false, "If true, subscribe to IPN notifications")
fs.BoolVar(&debugArgs.prefs, "prefs", false, "If true, dump active prefs") fs.BoolVar(&debugArgs.prefs, "prefs", false, "If true, dump active prefs")

View File

@ -55,7 +55,7 @@
ShortHelp: "Copy file(s) to a host", ShortHelp: "Copy file(s) to a host",
Exec: runCp, Exec: runCp,
FlagSet: (func() *flag.FlagSet { FlagSet: (func() *flag.FlagSet {
fs := flag.NewFlagSet("cp", flag.ExitOnError) fs := newFlagSet("cp")
fs.StringVar(&cpArgs.name, "name", "", "alternate filename to use, especially useful when <file> is \"-\" (stdin)") fs.StringVar(&cpArgs.name, "name", "", "alternate filename to use, especially useful when <file> is \"-\" (stdin)")
fs.BoolVar(&cpArgs.verbose, "verbose", false, "verbose output") fs.BoolVar(&cpArgs.verbose, "verbose", false, "verbose output")
fs.BoolVar(&cpArgs.targets, "targets", false, "list possible file cp targets") fs.BoolVar(&cpArgs.targets, "targets", false, "list possible file cp targets")
@ -304,7 +304,7 @@ func runCpTargets(ctx context.Context, args []string) error {
ShortHelp: "Move files out of the Tailscale file inbox", ShortHelp: "Move files out of the Tailscale file inbox",
Exec: runFileGet, Exec: runFileGet,
FlagSet: (func() *flag.FlagSet { FlagSet: (func() *flag.FlagSet {
fs := flag.NewFlagSet("get", flag.ExitOnError) fs := newFlagSet("get")
fs.BoolVar(&getArgs.wait, "wait", false, "wait for a file to arrive if inbox is empty") fs.BoolVar(&getArgs.wait, "wait", false, "wait for a file to arrive if inbox is empty")
fs.BoolVar(&getArgs.verbose, "verbose", false, "verbose output") fs.BoolVar(&getArgs.verbose, "verbose", false, "verbose output")
return fs return fs

View File

@ -23,7 +23,7 @@
LongHelp: "Shows the Tailscale IP address of the current machine without an argument. With an argument, it shows the IP of a named peer.", LongHelp: "Shows the Tailscale IP address of the current machine without an argument. With an argument, it shows the IP of a named peer.",
Exec: runIP, Exec: runIP,
FlagSet: (func() *flag.FlagSet { FlagSet: (func() *flag.FlagSet {
fs := flag.NewFlagSet("ip", flag.ExitOnError) fs := newFlagSet("ip")
fs.BoolVar(&ipArgs.want4, "4", false, "only print IPv4 address") fs.BoolVar(&ipArgs.want4, "4", false, "only print IPv4 address")
fs.BoolVar(&ipArgs.want6, "6", false, "only print IPv6 address") fs.BoolVar(&ipArgs.want6, "6", false, "only print IPv6 address")
return fs return fs

View File

@ -33,7 +33,7 @@
ShortHelp: "Print an analysis of local network conditions", ShortHelp: "Print an analysis of local network conditions",
Exec: runNetcheck, Exec: runNetcheck,
FlagSet: (func() *flag.FlagSet { FlagSet: (func() *flag.FlagSet {
fs := flag.NewFlagSet("netcheck", flag.ExitOnError) fs := newFlagSet("netcheck")
fs.StringVar(&netcheckArgs.format, "format", "", `output format; empty (for human-readable), "json" or "json-line"`) fs.StringVar(&netcheckArgs.format, "format", "", `output format; empty (for human-readable), "json" or "json-line"`)
fs.DurationVar(&netcheckArgs.every, "every", 0, "if non-zero, do an incremental report with the given frequency") fs.DurationVar(&netcheckArgs.every, "every", 0, "if non-zero, do an incremental report with the given frequency")
fs.BoolVar(&netcheckArgs.verbose, "verbose", false, "verbose logs") fs.BoolVar(&netcheckArgs.verbose, "verbose", false, "verbose logs")

View File

@ -45,7 +45,7 @@
`), `),
Exec: runPing, Exec: runPing,
FlagSet: (func() *flag.FlagSet { FlagSet: (func() *flag.FlagSet {
fs := flag.NewFlagSet("ping", flag.ExitOnError) fs := newFlagSet("ping")
fs.BoolVar(&pingArgs.verbose, "verbose", false, "verbose output") fs.BoolVar(&pingArgs.verbose, "verbose", false, "verbose output")
fs.BoolVar(&pingArgs.untilDirect, "until-direct", true, "stop once a direct path is established") fs.BoolVar(&pingArgs.untilDirect, "until-direct", true, "stop once a direct path is established")
fs.BoolVar(&pingArgs.tsmp, "tsmp", false, "do a TSMP-level ping (through IP + wireguard, but not involving host OS stack)") fs.BoolVar(&pingArgs.tsmp, "tsmp", false, "do a TSMP-level ping (through IP + wireguard, but not involving host OS stack)")

View File

@ -31,7 +31,7 @@
ShortHelp: "Show state of tailscaled and its connections", ShortHelp: "Show state of tailscaled and its connections",
Exec: runStatus, Exec: runStatus,
FlagSet: (func() *flag.FlagSet { FlagSet: (func() *flag.FlagSet {
fs := flag.NewFlagSet("status", flag.ExitOnError) fs := newFlagSet("status")
fs.BoolVar(&statusArgs.json, "json", false, "output in JSON format (WARNING: format subject to change)") fs.BoolVar(&statusArgs.json, "json", false, "output in JSON format (WARNING: format subject to change)")
fs.BoolVar(&statusArgs.web, "web", false, "run webserver with HTML showing status") fs.BoolVar(&statusArgs.web, "web", false, "run webserver with HTML showing status")
fs.BoolVar(&statusArgs.active, "active", false, "filter output to only peers with active sessions (not applicable to web mode)") fs.BoolVar(&statusArgs.active, "active", false, "filter output to only peers with active sessions (not applicable to web mode)")

View File

@ -63,7 +63,7 @@ func effectiveGOOS() string {
var upFlagSet = newUpFlagSet(effectiveGOOS(), &upArgs) var upFlagSet = newUpFlagSet(effectiveGOOS(), &upArgs)
func newUpFlagSet(goos string, upArgs *upArgsT) *flag.FlagSet { func newUpFlagSet(goos string, upArgs *upArgsT) *flag.FlagSet {
upf := flag.NewFlagSet("up", flag.ExitOnError) upf := newFlagSet("up")
upf.BoolVar(&upArgs.qr, "qr", false, "show QR code for login URLs") upf.BoolVar(&upArgs.qr, "qr", false, "show QR code for login URLs")
upf.BoolVar(&upArgs.forceReauth, "force-reauth", false, "force reauthentication") upf.BoolVar(&upArgs.forceReauth, "force-reauth", false, "force reauthentication")

View File

@ -20,7 +20,7 @@
ShortUsage: "version [flags]", ShortUsage: "version [flags]",
ShortHelp: "Print Tailscale version", ShortHelp: "Print Tailscale version",
FlagSet: (func() *flag.FlagSet { FlagSet: (func() *flag.FlagSet {
fs := flag.NewFlagSet("version", flag.ExitOnError) fs := newFlagSet("version")
fs.BoolVar(&versionArgs.daemon, "daemon", false, "also print local node's daemon version") fs.BoolVar(&versionArgs.daemon, "daemon", false, "also print local node's daemon version")
return fs return fs
})(), })(),

View File

@ -76,7 +76,7 @@ type tmplData struct {
`), `),
FlagSet: (func() *flag.FlagSet { FlagSet: (func() *flag.FlagSet {
webf := flag.NewFlagSet("web", flag.ExitOnError) webf := newFlagSet("web")
webf.StringVar(&webArgs.listen, "listen", "localhost:8088", "listen address; use port 0 for automatic") webf.StringVar(&webArgs.listen, "listen", "localhost:8088", "listen address; use port 0 for automatic")
webf.BoolVar(&webArgs.cgi, "cgi", false, "run as CGI script") webf.BoolVar(&webArgs.cgi, "cgi", false, "run as CGI script")
return webf return webf