cmd/tailscale/cli: add, use log.Fatalf indirection for js/wasm

Updates #3157

Change-Id: I97a4962a44bd36313ff68388e3de0d852a8fa869
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/3202/head
Brad Fitzpatrick 3 years ago
parent 4a65b07e34
commit 675f9cd199

@ -173,10 +173,17 @@ change in the future.
} }
func fatalf(format string, a ...interface{}) { func fatalf(format string, a ...interface{}) {
if Fatalf != nil {
Fatalf(format, a...)
return
}
log.SetFlags(0) log.SetFlags(0)
log.Fatalf(format, a...) log.Fatalf(format, a...)
} }
// Fatalf, if non-nil, is used instead of log.Fatalf.
var Fatalf func(format string, a ...interface{})
var rootArgs struct { var rootArgs struct {
socket string socket string
} }

@ -174,7 +174,7 @@ func runDebug(ctx context.Context, args []string) error {
if debugArgs.file == "get" { if debugArgs.file == "get" {
wfs, err := tailscale.WaitingFiles(ctx) wfs, err := tailscale.WaitingFiles(ctx)
if err != nil { if err != nil {
log.Fatal(err) fatalf("%v\n", err)
} }
e := json.NewEncoder(Stdout) e := json.NewEncoder(Stdout)
e.SetIndent("", "\t") e.SetIndent("", "\t")

@ -7,7 +7,6 @@ package cli
import ( import (
"context" "context"
"fmt" "fmt"
"log"
"github.com/peterbourgon/ff/v3/ffcli" "github.com/peterbourgon/ff/v3/ffcli"
"tailscale.com/client/tailscale" "tailscale.com/client/tailscale"
@ -24,7 +23,7 @@ var downCmd = &ffcli.Command{
func runDown(ctx context.Context, args []string) error { func runDown(ctx context.Context, args []string) error {
if len(args) > 0 { if len(args) > 0 {
log.Fatalf("too many non-flag arguments: %q", args) return fmt.Errorf("too many non-flag arguments: %q", args)
} }
st, err := tailscale.Status(ctx) st, err := tailscale.Status(ctx)

@ -415,7 +415,7 @@ func waitForFile(ctx context.Context) error {
fileWaiting := make(chan bool, 1) fileWaiting := make(chan bool, 1)
bc.SetNotifyCallback(func(n ipn.Notify) { bc.SetNotifyCallback(func(n ipn.Notify) {
if n.ErrMessage != nil { if n.ErrMessage != nil {
log.Fatal(*n.ErrMessage) fatalf("Notify.ErrMessage: %v\n", *n.ErrMessage)
} }
if n.FilesWaiting != nil { if n.FilesWaiting != nil {
select { select {

@ -6,7 +6,7 @@ package cli
import ( import (
"context" "context"
"log" "fmt"
"strings" "strings"
"github.com/peterbourgon/ff/v3/ffcli" "github.com/peterbourgon/ff/v3/ffcli"
@ -28,7 +28,7 @@ a reauthentication.
func runLogout(ctx context.Context, args []string) error { func runLogout(ctx context.Context, args []string) error {
if len(args) > 0 { if len(args) > 0 {
log.Fatalf("too many non-flag arguments: %q", args) return fmt.Errorf("too many non-flag arguments: %q", args)
} }
return tailscale.Logout(ctx) return tailscale.Logout(ctx)
} }

@ -82,7 +82,7 @@ func runNetcheck(ctx context.Context, args []string) error {
c.Logf("GetReport took %v; err=%v", d.Round(time.Millisecond), err) c.Logf("GetReport took %v; err=%v", d.Round(time.Millisecond), err)
} }
if err != nil { if err != nil {
log.Fatalf("netcheck: %v", err) return fmt.Errorf("netcheck: %w", err)
} }
if err := printReport(dm, report); err != nil { if err := printReport(dm, report); err != nil {
return err return err

@ -74,7 +74,7 @@ func runPing(ctx context.Context, args []string) error {
prc := make(chan *ipnstate.PingResult, 1) prc := make(chan *ipnstate.PingResult, 1)
bc.SetNotifyCallback(func(n ipn.Notify) { bc.SetNotifyCallback(func(n ipn.Notify) {
if n.ErrMessage != nil { if n.ErrMessage != nil {
log.Fatal(*n.ErrMessage) fatalf("Notify.ErrMessage: %v", *n.ErrMessage)
} }
if pr := n.PingResult; pr != nil && pr.IP == ip { if pr := n.PingResult; pr != nil && pr.IP == ip {
prc <- pr prc <- pr

@ -7,7 +7,7 @@ package cli
import ( import (
"context" "context"
"flag" "flag"
"log" "fmt"
"github.com/peterbourgon/ff/v3/ffcli" "github.com/peterbourgon/ff/v3/ffcli"
"tailscale.com/client/tailscale" "tailscale.com/client/tailscale"
@ -32,7 +32,7 @@ var versionArgs struct {
func runVersion(ctx context.Context, args []string) error { func runVersion(ctx context.Context, args []string) error {
if len(args) > 0 { if len(args) > 0 {
log.Fatalf("too many non-flag arguments: %q", args) return fmt.Errorf("too many non-flag arguments: %q", args)
} }
if !versionArgs.daemon { if !versionArgs.daemon {
outln(version.String()) outln(version.String())

@ -114,7 +114,7 @@ func tlsConfigFromEnvironment() *tls.Config {
func runWeb(ctx context.Context, args []string) error { func runWeb(ctx context.Context, args []string) error {
if len(args) > 0 { if len(args) > 0 {
log.Fatalf("too many non-flag arguments: %q", args) return fmt.Errorf("too many non-flag arguments: %q", args)
} }
if webArgs.cgi { if webArgs.cgi {

Loading…
Cancel
Save