mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-20 13:41:41 +00:00
cmd/tailscale: fix help message for serve funnel
We currently print out "run tailscale serve --help" when the subcmd might be funnel. This PR ensures the right subcmd is passed. Updates #8489 Signed-off-by: Marwan Sulaiman <marwan@tailscale.com>
This commit is contained in:
parent
d3bc575f35
commit
f5a7551382
@ -100,6 +100,12 @@ func buildShortUsage(subcmd string) string {
|
|||||||
}, "\n ")
|
}, "\n ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// errHelpFunc is standard error text that prompts users to
|
||||||
|
// run `$subcmd --help` for information on how to use serve.
|
||||||
|
var errHelpFunc = func(m serveMode) error {
|
||||||
|
return fmt.Errorf("try `tailscale %s --help` for usage info", infoMap[m].Name)
|
||||||
|
}
|
||||||
|
|
||||||
// newServeV2Command returns a new "serve" subcommand using e as its environment.
|
// newServeV2Command returns a new "serve" subcommand using e as its environment.
|
||||||
func newServeV2Command(e *serveEnv, subcmd serveMode) *ffcli.Command {
|
func newServeV2Command(e *serveEnv, subcmd serveMode) *ffcli.Command {
|
||||||
if subcmd != serve && subcmd != funnel {
|
if subcmd != serve && subcmd != funnel {
|
||||||
@ -158,19 +164,19 @@ func validateArgs(subcmd serveMode, args []string) error {
|
|||||||
fmt.Fprintf(os.Stderr, "\t- %s\n", translation)
|
fmt.Fprintf(os.Stderr, "\t- %s\n", translation)
|
||||||
}
|
}
|
||||||
fmt.Fprint(os.Stderr, "\nPlease see https://tailscale.com/kb/1242/tailscale-serve for more information.\n")
|
fmt.Fprint(os.Stderr, "\nPlease see https://tailscale.com/kb/1242/tailscale-serve for more information.\n")
|
||||||
return errHelp
|
return errHelpFunc(subcmd)
|
||||||
}
|
}
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return flag.ErrHelp
|
return flag.ErrHelp
|
||||||
}
|
}
|
||||||
if len(args) > 2 {
|
if len(args) > 2 {
|
||||||
fmt.Fprintf(os.Stderr, "Error: invalid number of arguments (%d)\n", len(args))
|
fmt.Fprintf(os.Stderr, "Error: invalid number of arguments (%d)\n", len(args))
|
||||||
return errHelp
|
return errHelpFunc(subcmd)
|
||||||
}
|
}
|
||||||
turnOff := args[len(args)-1] == "off"
|
turnOff := args[len(args)-1] == "off"
|
||||||
if len(args) == 2 && !turnOff {
|
if len(args) == 2 && !turnOff {
|
||||||
fmt.Fprintln(os.Stderr, "Error: invalid argument format")
|
fmt.Fprintln(os.Stderr, "Error: invalid argument format")
|
||||||
return errHelp
|
return errHelpFunc(subcmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Given the two checks above, we can assume there
|
// Given the two checks above, we can assume there
|
||||||
@ -225,7 +231,7 @@ func (e *serveEnv) runServeCombined(subcmd serveMode) execFunc {
|
|||||||
srvType, srvPort, err := srvTypeAndPortFromFlags(e)
|
srvType, srvPort, err := srvTypeAndPortFromFlags(e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error: %v\n\n", err)
|
fmt.Fprintf(os.Stderr, "error: %v\n\n", err)
|
||||||
return errHelp
|
return errHelpFunc(subcmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
sc, err := e.lc.GetServeConfig(ctx)
|
sc, err := e.lc.GetServeConfig(ctx)
|
||||||
@ -295,7 +301,7 @@ func (e *serveEnv) runServeCombined(subcmd serveMode) execFunc {
|
|||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error: %v\n\n", err)
|
fmt.Fprintf(os.Stderr, "error: %v\n\n", err)
|
||||||
return errHelp
|
return errHelpFunc(subcmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := e.lc.SetServeConfig(ctx, parentSC); err != nil {
|
if err := e.lc.SetServeConfig(ctx, parentSC); err != nil {
|
||||||
|
@ -370,15 +370,15 @@ func TestServeDevConfigMutations(t *testing.T) {
|
|||||||
add(step{reset: true})
|
add(step{reset: true})
|
||||||
add(step{ // !somehost, must be localhost or 127.0.0.1
|
add(step{ // !somehost, must be localhost or 127.0.0.1
|
||||||
command: cmd("serve --tls-terminated-tcp=443 --bg tcp://somehost:5432"),
|
command: cmd("serve --tls-terminated-tcp=443 --bg tcp://somehost:5432"),
|
||||||
wantErr: exactErr(errHelp, "errHelp"),
|
wantErr: exactErrMsg(errHelp),
|
||||||
})
|
})
|
||||||
add(step{ // bad target port, too low
|
add(step{ // bad target port, too low
|
||||||
command: cmd("serve --tls-terminated-tcp=443 --bg tcp://somehost:0"),
|
command: cmd("serve --tls-terminated-tcp=443 --bg tcp://somehost:0"),
|
||||||
wantErr: exactErr(errHelp, "errHelp"),
|
wantErr: exactErrMsg(errHelp),
|
||||||
})
|
})
|
||||||
add(step{ // bad target port, too high
|
add(step{ // bad target port, too high
|
||||||
command: cmd("serve --tls-terminated-tcp=443 --bg tcp://somehost:65536"),
|
command: cmd("serve --tls-terminated-tcp=443 --bg tcp://somehost:65536"),
|
||||||
wantErr: exactErr(errHelp, "errHelp"),
|
wantErr: exactErrMsg(errHelp),
|
||||||
})
|
})
|
||||||
add(step{ // support shorthand
|
add(step{ // support shorthand
|
||||||
command: cmd("serve --tls-terminated-tcp=443 --bg 5432"),
|
command: cmd("serve --tls-terminated-tcp=443 --bg 5432"),
|
||||||
@ -508,7 +508,7 @@ func TestServeDevConfigMutations(t *testing.T) {
|
|||||||
})
|
})
|
||||||
add(step{ // bad path
|
add(step{ // bad path
|
||||||
command: cmd("serve --https=443 --bg bad/path"),
|
command: cmd("serve --https=443 --bg bad/path"),
|
||||||
wantErr: exactErr(errHelp, "errHelp"),
|
wantErr: exactErrMsg(errHelp),
|
||||||
})
|
})
|
||||||
add(step{reset: true})
|
add(step{reset: true})
|
||||||
add(step{
|
add(step{
|
||||||
@ -1283,3 +1283,14 @@ func TestIsLegacyInvocation(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// exactErrMsg returns an error checker that wants exactly the provided want error.
|
||||||
|
// If optName is non-empty, it's used in the error message.
|
||||||
|
func exactErrMsg(want error) func(error) string {
|
||||||
|
return func(got error) string {
|
||||||
|
if got.Error() == want.Error() {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("got error %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user