Skip to content

Commit 85cfb3b

Browse files
committed
extract formatLogArg method on Remote
1 parent 5a05f66 commit 85cfb3b

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/remote.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,26 @@ export class Remote {
541541
}
542542
}
543543

544+
/**
545+
* Format's the --log-dir argument for the ProxyCommand
546+
*/
547+
private async formatLogArg(): Promise<string> {
548+
if (!supportsCoderAgentLogDirFlag(this.coderVersion)) {
549+
return ""
550+
}
551+
552+
// If the proxyLogDirectory is not set in the extension settings we don't send one.
553+
// Question for Asher: How do VSCode extension settings behave in terms of semver for the extension?
554+
const logDir = expandPath(String(vscode.workspace.getConfiguration().get("coder.proxyLogDirectory") ?? "").trim())
555+
if (!logDir) {
556+
return ""
557+
}
558+
559+
await fs.mkdir(logDir, { recursive: true })
560+
this.storage.writeToCoderOutputChannel(`Your logs are being written to ${logDir}`)
561+
return ` --log-dir ${escape(logDir)}`
562+
}
563+
544564
// updateSSHConfig updates the SSH configuration with a wildcard that handles
545565
// all Coder entries.
546566
private async updateSSHConfig(restClient: Api, label: string, hostName: string) {
@@ -634,20 +654,12 @@ export class Remote {
634654
if (typeof headerCommand === "string" && headerCommand.trim().length > 0) {
635655
headerArg = ` --header-command ${escapeSubcommand(headerCommand)}`
636656
}
637-
let logArg = ""
638-
if (supportsCoderAgentLogDirFlag(this.coderVersion)) {
639-
const logDir = expandPath(String(vscode.workspace.getConfiguration().get("coder.proxyLogDirectory") ?? "").trim())
640-
if (logDir) {
641-
await fs.mkdir(logDir, { recursive: true })
642-
logArg = ` --log-dir ${escape(logDir)}`
643-
this.storage.writeToCoderOutputChannel(`Your logs are being written to ${logDir}`)
644-
}
645-
}
657+
646658
const sshValues: SSHValues = {
647659
Host: label ? `${AuthorityPrefix}.${label}--*` : `${AuthorityPrefix}--*`,
648660
ProxyCommand: `${escape(binaryPath)}${headerArg} vscodessh --network-info-dir ${escape(
649661
this.storage.getNetworkInfoPath(),
650-
)}${logArg} --session-token-file ${escape(this.storage.getSessionTokenPath(label))} --url-file ${escape(
662+
)}${await this.formatLogArg()} --session-token-file ${escape(this.storage.getSessionTokenPath(label))} --url-file ${escape(
651663
this.storage.getUrlPath(label),
652664
)} %h`,
653665
ConnectTimeout: "0",

0 commit comments

Comments
 (0)