cmd/tailscale/cli: show nicer status output when logged out

Also nicer output when running "down".

Fixes #1680

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/1687/head
Brad Fitzpatrick 3 years ago
parent 5c5acadb2a
commit 83402e2753

@ -8,6 +8,7 @@ import (
"context" "context"
"fmt" "fmt"
"log" "log"
"os"
"time" "time"
"github.com/peterbourgon/ff/v2/ffcli" "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) return fmt.Errorf("error fetching current status: %w", err)
} }
if st.BackendState == "Stopped" { if st.BackendState == "Stopped" {
log.Printf("already stopped") fmt.Fprintf(os.Stderr, "Tailscale was already stopped.\n")
return nil return nil
} }
log.Printf("was in state %q", st.BackendState)
c, bc, ctx, cancel := connect(ctx) c, bc, ctx, cancel := connect(ctx)
defer cancel() defer cancel()
@ -51,7 +51,6 @@ func runDown(ctx context.Context, args []string) error {
log.Fatal(*n.ErrMessage) log.Fatal(*n.ErrMessage)
} }
if n.State != nil { if n.State != nil {
log.Printf("now in state %q", *n.State)
if *n.State == ipn.Stopped { if *n.State == ipn.Stopped {
cancel() cancel()
} }

@ -106,9 +106,24 @@ func runStatus(ctx context.Context, args []string) error {
return err 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.") fmt.Println("Tailscale is stopped.")
os.Exit(1) 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 var buf bytes.Buffer

Loading…
Cancel
Save