cmd/tailscale/cli: add "help" alias for --help

Fixes #14053

Change-Id: I0a13e11af089f02b0656fea0d316543c67591fb5
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
andrew/dnscache-hard-code-localhost
Brad Fitzpatrick 1 week ago committed by Brad Fitzpatrick
parent bfe5cd8760
commit f593d3c5c0

@ -93,8 +93,13 @@ func Run(args []string) (err error) {
args = CleanUpArgs(args) args = CleanUpArgs(args)
if len(args) == 1 && (args[0] == "-V" || args[0] == "--version") { if len(args) == 1 {
switch args[0] {
case "-V", "--version":
args = []string{"version"} args = []string{"version"}
case "help":
args = []string{"--help"}
}
} }
var warnOnce sync.Once var warnOnce sync.Once

@ -9,6 +9,7 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"io"
"net/netip" "net/netip"
"reflect" "reflect"
"strings" "strings"
@ -1480,3 +1481,33 @@ func TestParseNLArgs(t *testing.T) {
}) })
} }
} }
func TestHelpAlias(t *testing.T) {
var stdout, stderr bytes.Buffer
tstest.Replace[io.Writer](t, &Stdout, &stdout)
tstest.Replace[io.Writer](t, &Stderr, &stderr)
gotExit0 := false
defer func() {
if !gotExit0 {
t.Error("expected os.Exit(0) to be called")
return
}
if !strings.Contains(stderr.String(), "SUBCOMMANDS") {
t.Errorf("expected help output to contain SUBCOMMANDS; got stderr=%q; stdout=%q", stderr.String(), stdout.String())
}
}()
defer func() {
if e := recover(); e != nil {
if strings.Contains(fmt.Sprint(e), "unexpected call to os.Exit(0)") {
gotExit0 = true
} else {
t.Errorf("unexpected panic: %v", e)
}
}
}()
err := Run([]string{"help"})
if err != nil {
t.Fatalf("Run: %v", err)
}
}

Loading…
Cancel
Save