mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-29 07:09:33 +00:00
cmd/tailscale: use tailnet display name on cli (#17079)
Updates cli to use tailnet display name Updates tailscale/corp#32108 Signed-off-by: nikiUppal-TS <nikita@tailscale.com>
This commit is contained in:
@@ -24,7 +24,7 @@ var switchCmd = &ffcli.Command{
|
|||||||
LongHelp: `"tailscale switch" switches between logged in accounts. You can
|
LongHelp: `"tailscale switch" switches between logged in accounts. You can
|
||||||
use the ID that's returned from 'tailnet switch -list'
|
use the ID that's returned from 'tailnet switch -list'
|
||||||
to pick which profile you want to switch to. Alternatively, you
|
to pick which profile you want to switch to. Alternatively, you
|
||||||
can use the Tailnet or the account names to switch as well.
|
can use the Tailnet, account names, or display names to switch as well.
|
||||||
|
|
||||||
This command is currently in alpha and may change in the future.`,
|
This command is currently in alpha and may change in the future.`,
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ func init() {
|
|||||||
seen := make(map[string]bool, 3*len(all))
|
seen := make(map[string]bool, 3*len(all))
|
||||||
wordfns := []func(prof ipn.LoginProfile) string{
|
wordfns := []func(prof ipn.LoginProfile) string{
|
||||||
func(prof ipn.LoginProfile) string { return string(prof.ID) },
|
func(prof ipn.LoginProfile) string { return string(prof.ID) },
|
||||||
func(prof ipn.LoginProfile) string { return prof.NetworkProfile.DomainName },
|
func(prof ipn.LoginProfile) string { return prof.NetworkProfile.DisplayNameOrDefault() },
|
||||||
func(prof ipn.LoginProfile) string { return prof.Name },
|
func(prof ipn.LoginProfile) string { return prof.Name },
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ func init() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
seen[word] = true
|
seen[word] = true
|
||||||
words = append(words, fmt.Sprintf("%s\tid: %s, tailnet: %s, account: %s", word, prof.ID, prof.NetworkProfile.DomainName, prof.Name))
|
words = append(words, fmt.Sprintf("%s\tid: %s, tailnet: %s, account: %s", word, prof.ID, prof.NetworkProfile.DisplayNameOrDefault(), prof.Name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return words, ffcomplete.ShellCompDirectiveNoFileComp, nil
|
return words, ffcomplete.ShellCompDirectiveNoFileComp, nil
|
||||||
@@ -86,7 +86,7 @@ func listProfiles(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
printRow(
|
printRow(
|
||||||
string(prof.ID),
|
string(prof.ID),
|
||||||
prof.NetworkProfile.DomainName,
|
prof.NetworkProfile.DisplayNameOrDefault(),
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ func switchProfile(ctx context.Context, args []string) error {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
var profID ipn.ProfileID
|
var profID ipn.ProfileID
|
||||||
// Allow matching by ID, Tailnet, or Account
|
// Allow matching by ID, Tailnet, Account, or Display Name
|
||||||
// in that order.
|
// in that order.
|
||||||
for _, p := range all {
|
for _, p := range all {
|
||||||
if p.ID == ipn.ProfileID(args[0]) {
|
if p.ID == ipn.ProfileID(args[0]) {
|
||||||
@@ -131,6 +131,14 @@ func switchProfile(ctx context.Context, args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if profID == "" {
|
||||||
|
for _, p := range all {
|
||||||
|
if p.NetworkProfile.DisplayName == args[0] {
|
||||||
|
profID = p.ID
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if profID == "" {
|
if profID == "" {
|
||||||
errf("No profile named %q\n", args[0])
|
errf("No profile named %q\n", args[0])
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package ipn
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"cmp"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1001,6 +1002,13 @@ func (n NetworkProfile) RequiresBackfill() bool {
|
|||||||
return n == NetworkProfile{}
|
return n == NetworkProfile{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DisplayNameOrDefault will always return a non-empty string.
|
||||||
|
// If there is a defined display name, it will return that.
|
||||||
|
// If they did not it will default to their domain name.
|
||||||
|
func (n NetworkProfile) DisplayNameOrDefault() string {
|
||||||
|
return cmp.Or(n.DisplayName, n.DomainName)
|
||||||
|
}
|
||||||
|
|
||||||
// LoginProfile represents a single login profile as managed
|
// LoginProfile represents a single login profile as managed
|
||||||
// by the ProfileManager.
|
// by the ProfileManager.
|
||||||
type LoginProfile struct {
|
type LoginProfile struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user