From 83402e2753cf67049c1989e61f5fe96eb79529e5 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 9 Apr 2021 18:20:50 -0700 Subject: [PATCH] cmd/tailscale/cli: show nicer status output when logged out Also nicer output when running "down". Fixes #1680 Signed-off-by: Brad Fitzpatrick --- cmd/tailscale/cli/down.go | 5 ++--- cmd/tailscale/cli/status.go | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cmd/tailscale/cli/down.go b/cmd/tailscale/cli/down.go index 90a0a8e71..0bbdad2be 100644 --- a/cmd/tailscale/cli/down.go +++ b/cmd/tailscale/cli/down.go @@ -8,6 +8,7 @@ import ( "context" "fmt" "log" + "os" "time" "github.com/peterbourgon/ff/v2/ffcli" @@ -33,10 +34,9 @@ func runDown(ctx context.Context, args []string) error { return fmt.Errorf("error fetching current status: %w", err) } if st.BackendState == "Stopped" { - log.Printf("already stopped") + fmt.Fprintf(os.Stderr, "Tailscale was already stopped.\n") return nil } - log.Printf("was in state %q", st.BackendState) c, bc, ctx, cancel := connect(ctx) defer cancel() @@ -51,7 +51,6 @@ func runDown(ctx context.Context, args []string) error { log.Fatal(*n.ErrMessage) } if n.State != nil { - log.Printf("now in state %q", *n.State) if *n.State == ipn.Stopped { cancel() } diff --git a/cmd/tailscale/cli/status.go b/cmd/tailscale/cli/status.go index 72b843f2d..091db8bbc 100644 --- a/cmd/tailscale/cli/status.go +++ b/cmd/tailscale/cli/status.go @@ -106,9 +106,24 @@ func runStatus(ctx context.Context, args []string) error { return err } - if st.BackendState == ipn.Stopped.String() { + switch st.BackendState { + default: + fmt.Fprintf(os.Stderr, "unexpected state: %s\n", st.BackendState) + os.Exit(1) + case ipn.Stopped.String(): fmt.Println("Tailscale is stopped.") os.Exit(1) + case ipn.NeedsLogin.String(): + fmt.Println("Logged out.") + if st.AuthURL != "" { + fmt.Printf("\nLog in at: %s\n", st.AuthURL) + } + os.Exit(1) + case ipn.NeedsMachineAuth.String(): + fmt.Println("Machine is not yet authorized by tailnet admin.") + os.Exit(1) + case ipn.Running.String(): + // Run below. } var buf bytes.Buffer