mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-30 12:42:31 +00:00

The approach is lifted from cobra: `tailscale completion bash` emits a bash script for configuring the shell's autocomplete: . <( tailscale completion bash ) so that typing: tailscale st<TAB> invokes: tailscale completion __complete -- st RELNOTE=tailscale CLI now supports shell tab-completion Fixes #3793 Signed-off-by: Paul Scott <paul@tailscale.com>
38 lines
792 B
Go
38 lines
792 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package cli
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/peterbourgon/ff/v3/ffcli"
|
|
"tailscale.com/envknob"
|
|
)
|
|
|
|
var idTokenCmd = &ffcli.Command{
|
|
Name: "id-token",
|
|
ShortUsage: "tailscale id-token <aud>",
|
|
ShortHelp: "Fetch an OIDC id-token for the Tailscale machine",
|
|
LongHelp: hidden,
|
|
Exec: runIDToken,
|
|
}
|
|
|
|
func runIDToken(ctx context.Context, args []string) error {
|
|
if !envknob.UseWIPCode() {
|
|
return errors.New("tailscale id-token: works-in-progress require TAILSCALE_USE_WIP_CODE=1 envvar")
|
|
}
|
|
if len(args) != 1 {
|
|
return errors.New("usage: tailscale id-token <aud>")
|
|
}
|
|
|
|
tr, err := localClient.IDToken(ctx, args[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
outln(tr.IDToken)
|
|
return nil
|
|
}
|