Skip to content

Commit 1ad3a20

Browse files
committed
Address review comments + Add some tests
1 parent d008e31 commit 1ad3a20

File tree

5 files changed

+94
-20
lines changed

5 files changed

+94
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Added
66

7-
- Add support for CLI global flag configurations.
7+
- Add support for CLI global flag configurations through the `coder.globalFlags` setting.
88

99
## [1.10.1](https://github.com/coder/vscode-coder/releases/tag/v1.10.1) 2025-08-13
1010

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"default": false
122122
},
123123
"coder.globalFlags": {
124-
"markdownDescription": "Global flags to pass to every Coder CLI invocation. Enter each flag as a separate array item; values are passed verbatim and in order. Do **not** include the `coder` command itself. See the [CLI reference](https://coder.com/docs/reference/cli) for available global flags.\n\nNote that the `#coder.headerCommand#` setting **takes precedence** and will override any `--header-command` value specified here.",
124+
"markdownDescription": "Global flags to pass to every Coder CLI invocation. Enter each flag as a separate array item; values are passed verbatim and in order. Do **not** include the `coder` command itself. See the [CLI reference](https://coder.com/docs/reference/cli) for available global flags.\n\nNote that the `#coder.headerCommand#` setting **takes precedence** and will override any `--header-command` value specified here. The `--global-config` flag is explicitly ignored.",
125125
"type": "array",
126126
"items": {
127127
"type": "string"

src/globalFlags.test.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { it, expect, describe } from "vitest";
2+
import { WorkspaceConfiguration } from "vscode";
3+
import { getGlobalFlags } from "./globalFlags";
4+
5+
describe("Global flags suite", () => {
6+
it("should return empty array when no global flags configured", () => {
7+
const config = {
8+
get: () => undefined,
9+
} as unknown as WorkspaceConfiguration;
10+
11+
expect(getGlobalFlags(config, "")).toStrictEqual([]);
12+
});
13+
14+
it("should return global flags from config", () => {
15+
const config = {
16+
get: (key: string) =>
17+
key === "coder.globalFlags"
18+
? ["--verbose", "--disable-direct-connections"]
19+
: undefined,
20+
} as unknown as WorkspaceConfiguration;
21+
22+
expect(getGlobalFlags(config, "")).toStrictEqual([
23+
"--verbose",
24+
"--disable-direct-connections",
25+
]);
26+
});
27+
28+
it("should filter out '--global-config' flags", () => {
29+
const config = {
30+
get: (key: string) =>
31+
key === "coder.globalFlags"
32+
? [
33+
"-v",
34+
"--global-config=/path/to/config",
35+
"--disable-direct-connections",
36+
]
37+
: undefined,
38+
} as unknown as WorkspaceConfiguration;
39+
40+
expect(getGlobalFlags(config, "")).toStrictEqual([
41+
"-v",
42+
"--disable-direct-connections",
43+
]);
44+
});
45+
46+
it("should add '--global-config' args when configDir provided", () => {
47+
const config = {
48+
get: (key: string) =>
49+
key === "coder.globalFlags"
50+
? ["-v", '--global-config "/ignored/path"']
51+
: undefined,
52+
} as unknown as WorkspaceConfiguration;
53+
54+
expect(getGlobalFlags(config, "/path/to/config")).toStrictEqual([
55+
"-v",
56+
"--global-config",
57+
'"/path/to/config"',
58+
]);
59+
});
60+
61+
it("should filter out '--header-command' when header args present", () => {
62+
const config = {
63+
get: (key: string) => {
64+
if (key === "coder.headerCommand") {
65+
return "echo test";
66+
}
67+
if (key === "coder.globalFlags") {
68+
return ["-v", "--header-command=custom", "--no-feature-warning"];
69+
}
70+
return undefined;
71+
},
72+
} as unknown as WorkspaceConfiguration;
73+
74+
const result = getGlobalFlags(config, "");
75+
expect(result).toStrictEqual([
76+
"-v",
77+
"--no-feature-warning",
78+
"--header-command",
79+
"'echo test'",
80+
]);
81+
});
82+
});

src/globalFlags.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,23 @@ import { escapeCommandArg } from "./util";
44

55
export function getGlobalFlags(
66
configs: WorkspaceConfiguration,
7-
configDir?: string,
7+
configDir: string,
88
): string[] {
99
const globalFlags = configs.get<string[]>("coder.globalFlags") || [];
1010
const headerArgs = getHeaderArgs(configs);
1111
const globalConfigArgs = configDir
1212
? ["--global-config", escapeCommandArg(configDir)]
1313
: [];
1414

15+
let filteredGlobalFlags = globalFlags.filter(
16+
(flag) => !flag.startsWith("--global-config"),
17+
);
1518
// Precedence of "coder.headerCommand" is higher than "coder.globalConfig" with the "--header-command" flag
16-
let filteredGlobalFlags = globalFlags;
1719
if (headerArgs.length > 0) {
1820
filteredGlobalFlags = globalFlags.filter(
1921
(flag) => !flag.startsWith("--header-command"),
2022
);
2123
}
2224

23-
if (globalConfigArgs.length > 0) {
24-
filteredGlobalFlags = globalFlags.filter(
25-
(flag) => !flag.startsWith("--global-config"),
26-
);
27-
}
2825
return [...filteredGlobalFlags, ...headerArgs, ...globalConfigArgs];
2926
}

src/remote.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ export class Remote {
762762
? `${AuthorityPrefix}.${label}--`
763763
: `${AuthorityPrefix}--`;
764764

765-
const globalConfigs = this.globalConfigs(featureSet, label);
765+
const globalConfigs = this.globalConfigs(label);
766766

767767
const proxyCommand = featureSet.wildcardSSH
768768
? `${escapeCommandArg(binaryPath)}${globalConfigs} ssh --stdio --usage-app=vscode --disable-autostart --network-info-dir ${escapeCommandArg(this.storage.getNetworkInfoPath())}${await this.formatLogArg(logDir)} --ssh-host-prefix ${hostPrefix} %h`
@@ -824,17 +824,12 @@ export class Remote {
824824
return sshConfig.getRaw();
825825
}
826826

827-
private globalConfigs(featureSet: FeatureSet, label: string): string {
827+
private globalConfigs(label: string): string {
828828
const vscodeConfig = vscode.workspace.getConfiguration();
829-
let args: string[];
830-
if (featureSet.wildcardSSH) {
831-
args = getGlobalFlags(
832-
vscodeConfig,
833-
path.dirname(this.storage.getSessionTokenPath(label)),
834-
);
835-
} else {
836-
args = getGlobalFlags(vscodeConfig);
837-
}
829+
const args: string[] = getGlobalFlags(
830+
vscodeConfig,
831+
path.dirname(this.storage.getSessionTokenPath(label)),
832+
);
838833
return args.length === 0 ? "" : ` ${args.join(" ")}`;
839834
}
840835

0 commit comments

Comments
 (0)