@@ -24,7 +24,7 @@ var switchCmd = &ffcli.Command{
2424 LongHelp : `"tailscale switch" switches between logged in accounts. You can
2525use the ID that's returned from 'tailnet switch -list'
2626to pick which profile you want to switch to. Alternatively, you
27- can use the Tailnet or the account names to switch as well.
27+ can use the Tailnet, account names, or display names to switch as well.
2828
2929This command is currently in alpha and may change in the future.` ,
3030
@@ -46,7 +46,7 @@ func init() {
4646 seen := make (map [string ]bool , 3 * len (all ))
4747 wordfns := []func (prof ipn.LoginProfile ) string {
4848 func (prof ipn.LoginProfile ) string { return string (prof .ID ) },
49- func (prof ipn.LoginProfile ) string { return prof .NetworkProfile .DomainName },
49+ func (prof ipn.LoginProfile ) string { return prof .NetworkProfile .DisplayNameOrDefault () },
5050 func (prof ipn.LoginProfile ) string { return prof .Name },
5151 }
5252
@@ -57,7 +57,7 @@ func init() {
5757 continue
5858 }
5959 seen [word ] = true
60- words = append (words , fmt .Sprintf ("%s\t id: %s, tailnet: %s, account: %s" , word , prof .ID , prof .NetworkProfile .DomainName , prof .Name ))
60+ words = append (words , fmt .Sprintf ("%s\t id: %s, tailnet: %s, account: %s" , word , prof .ID , prof .NetworkProfile .DisplayNameOrDefault () , prof .Name ))
6161 }
6262 }
6363 return words , ffcomplete .ShellCompDirectiveNoFileComp , nil
@@ -86,7 +86,7 @@ func listProfiles(ctx context.Context) error {
8686 }
8787 printRow (
8888 string (prof .ID ),
89- prof .NetworkProfile .DomainName ,
89+ prof .NetworkProfile .DisplayNameOrDefault () ,
9090 name ,
9191 )
9292 }
@@ -107,7 +107,7 @@ func switchProfile(ctx context.Context, args []string) error {
107107 os .Exit (1 )
108108 }
109109 var profID ipn.ProfileID
110- // Allow matching by ID, Tailnet, or Account
110+ // Allow matching by ID, Tailnet, Account, or Display Name
111111 // in that order.
112112 for _ , p := range all {
113113 if p .ID == ipn .ProfileID (args [0 ]) {
@@ -131,6 +131,14 @@ func switchProfile(ctx context.Context, args []string) error {
131131 }
132132 }
133133 }
134+ if profID == "" {
135+ for _ , p := range all {
136+ if p .NetworkProfile .DisplayName == args [0 ] {
137+ profID = p .ID
138+ break
139+ }
140+ }
141+ }
134142 if profID == "" {
135143 errf ("No profile named %q\n " , args [0 ])
136144 os .Exit (1 )
0 commit comments