From 891e7986cce17a3c5ff24047a2e5c6158dd66d67 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 29 Sep 2021 14:35:00 -0700 Subject: [PATCH] cmd/tailscale: make cert give hints on usage failure Like mentioning which cert domain(s) are valid. --- cmd/tailscale/cli/cert.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/tailscale/cli/cert.go b/cmd/tailscale/cli/cert.go index 1b3470724..9d6861c1a 100644 --- a/cmd/tailscale/cli/cert.go +++ b/cmd/tailscale/cli/cert.go @@ -18,6 +18,7 @@ "github.com/peterbourgon/ff/v3/ffcli" "tailscale.com/atomicfile" "tailscale.com/client/tailscale" + "tailscale.com/ipn" ) var certCmd = &ffcli.Command{ @@ -61,7 +62,19 @@ func runCert(ctx context.Context, args []string) error { } if len(args) != 1 { - return fmt.Errorf("Usage: tailscale cert [flags] ") + var hint bytes.Buffer + if st, err := tailscale.Status(ctx); err == nil { + if st.BackendState != ipn.Running.String() { + fmt.Fprintf(&hint, "\nTailscale is not running.\n") + } else if len(st.CertDomains) == 0 { + fmt.Fprintf(&hint, "\nHTTPS cert support is not enabled/configurfed for your tailnet.\n") + } else if len(st.CertDomains) == 1 { + fmt.Fprintf(&hint, "\nFor domain, use %q.\n", st.CertDomains[0]) + } else { + fmt.Fprintf(&hint, "\nValid domain options: %q.\n", st.CertDomains) + } + } + return fmt.Errorf("Usage: tailscale cert [flags] %s", hint.Bytes()) } domain := args[0]