@@ -307,35 +307,36 @@ class CoderCLIManager(
307
307
Host ${getHostPrefix()} -bg--*
308
308
ProxyCommand ${backgroundProxyArgs.joinToString(" " )} --ssh-host-prefix ${getHostPrefix()} -bg-- %h
309
309
""" .trimIndent()
310
- .plus(" \n " + sshOpts.prependIndent(" " ))
311
- .plus(extraConfig),
310
+ .plus(" \n " + sshOpts.prependIndent(" " ))
311
+ .plus(extraConfig),
312
312
).replace(" \n " , System .lineSeparator()) +
313
313
System .lineSeparator() + endBlock
314
-
315
- } else {
316
- workspaceNames.joinToString(
317
- System .lineSeparator(),
318
- startBlock + System .lineSeparator(),
319
- System .lineSeparator() + endBlock,
320
- transform = {
321
- """
314
+ } else if (workspaceNames.isEmpty()) {
315
+ " "
316
+ } else {
317
+ workspaceNames.joinToString(
318
+ System .lineSeparator(),
319
+ startBlock + System .lineSeparator(),
320
+ System .lineSeparator() + endBlock,
321
+ transform = {
322
+ """
322
323
Host ${getHostName(it.first, currentUser, it.second)}
323
324
ProxyCommand ${proxyArgs.joinToString(" " )} ${getWorkspaceParts(it.first, it.second)}
324
- """ .trimIndent()
325
- .plus(" \n " + sshOpts.prependIndent(" " ))
326
- .plus(extraConfig)
327
- .plus(" \n " )
328
- .plus(
329
- """
325
+ """ .trimIndent()
326
+ .plus(" \n " + sshOpts.prependIndent(" " ))
327
+ .plus(extraConfig)
328
+ .plus(" \n " )
329
+ .plus(
330
+ """
330
331
Host ${getBackgroundHostName(it.first, currentUser, it.second)}
331
332
ProxyCommand ${backgroundProxyArgs.joinToString(" " )} ${getWorkspaceParts(it.first, it.second)}
332
- """ .trimIndent()
333
- .plus(" \n " + sshOpts.prependIndent(" " ))
334
- .plus(extraConfig),
335
- ).replace(" \n " , System .lineSeparator())
336
- },
337
- )
338
- }
333
+ """ .trimIndent()
334
+ .plus(" \n " + sshOpts.prependIndent(" " ))
335
+ .plus(extraConfig),
336
+ ).replace(" \n " , System .lineSeparator())
337
+ },
338
+ )
339
+ }
339
340
340
341
if (contents == null ) {
341
342
logger.info(" No existing SSH config to modify" )
@@ -478,15 +479,13 @@ class CoderCLIManager(
478
479
*
479
480
* Throws if the command execution fails.
480
481
*/
481
- fun startWorkspace (workspaceOwner : String , workspaceName : String ): String {
482
- return exec(
483
- " --global-config" ,
484
- coderConfigPath.toString(),
485
- " start" ,
486
- " --yes" ,
487
- workspaceOwner+ " /" + workspaceName,
488
- )
489
- }
482
+ fun startWorkspace (workspaceOwner : String , workspaceName : String ): String = exec(
483
+ " --global-config" ,
484
+ coderConfigPath.toString(),
485
+ " start" ,
486
+ " --yes" ,
487
+ workspaceOwner + " /" + workspaceName,
488
+ )
490
489
491
490
private fun exec (vararg args : String ): String {
492
491
val stdout =
@@ -519,8 +518,7 @@ class CoderCLIManager(
519
518
/*
520
519
* This function returns the ssh-host-prefix used for Host entries.
521
520
*/
522
- fun getHostPrefix (): String =
523
- " coder-jetbrains-${deploymentURL.safeHost()} "
521
+ fun getHostPrefix (): String = " coder-jetbrains-${deploymentURL.safeHost()} "
524
522
525
523
/* *
526
524
* This function returns the ssh host name generated for connecting to the workspace.
@@ -529,29 +527,27 @@ class CoderCLIManager(
529
527
workspace : Workspace ,
530
528
currentUser : User ,
531
529
agent : WorkspaceAgent ,
532
- ): String =
533
- if (features.wildcardSSH) {
534
- " ${getHostPrefix()} --${workspace.ownerName} --${workspace.name} .${agent.name} "
530
+ ): String = if (features.wildcardSSH) {
531
+ " ${getHostPrefix()} --${workspace.ownerName} --${workspace.name} .${agent.name} "
532
+ } else {
533
+ // For a user's own workspace, we use the old syntax without a username for backwards compatibility,
534
+ // since the user might have recent connections that still use the old syntax.
535
+ if (currentUser.username == workspace.ownerName) {
536
+ " coder-jetbrains--${workspace.name} .${agent.name} --${deploymentURL.safeHost()} "
535
537
} else {
536
- // For a user's own workspace, we use the old syntax without a username for backwards compatibility,
537
- // since the user might have recent connections that still use the old syntax.
538
- if (currentUser.username == workspace.ownerName) {
539
- " coder-jetbrains--${workspace.name} .${agent.name} --${deploymentURL.safeHost()} "
540
- } else {
541
- " coder-jetbrains--${workspace.ownerName} --${workspace.name} .${agent.name} --${deploymentURL.safeHost()} "
538
+ " coder-jetbrains--${workspace.ownerName} --${workspace.name} .${agent.name} --${deploymentURL.safeHost()} "
542
539
}
543
540
}
544
541
545
542
fun getBackgroundHostName (
546
543
workspace : Workspace ,
547
544
currentUser : User ,
548
545
agent : WorkspaceAgent ,
549
- ): String =
550
- if (features.wildcardSSH) {
551
- " ${getHostPrefix()} -bg--${workspace.ownerName} --${workspace.name} .${agent.name} "
552
- } else {
553
- getHostName(workspace, currentUser, agent) + " --bg"
554
- }
546
+ ): String = if (features.wildcardSSH) {
547
+ " ${getHostPrefix()} -bg--${workspace.ownerName} --${workspace.name} .${agent.name} "
548
+ } else {
549
+ getHostName(workspace, currentUser, agent) + " --bg"
550
+ }
555
551
556
552
companion object {
557
553
val logger = Logger .getInstance(CoderCLIManager ::class .java.simpleName)
0 commit comments