Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08a2dc3

Browse files
committed
Address review comments + Add some tests
1 parentbefd9ae commit08a2dc3

File tree

5 files changed

+93
-34
lines changed

5 files changed

+93
-34
lines changed

‎CHANGELOG.md‎

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

99
###Added
1010

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

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

‎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 thatthe `#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 thatfor `--header-command`, precedence is: `#coder.headerCommand#` setting, then `CODER_HEADER_COMMAND` environment variable, then the value specified here. The`--global-config` flag is explicitly ignored.",
125125
"type":"array",
126126
"items": {
127127
"type":"string"

‎src/globalFlags.test.ts‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 global-config and header args when no global flags configured",()=>{
7+
constconfig={
8+
get:()=>undefined,
9+
}asunknownasWorkspaceConfiguration;
10+
11+
expect(getGlobalFlags(config,"/config/dir")).toStrictEqual([
12+
"--global-config",
13+
'"/config/dir"',
14+
]);
15+
});
16+
17+
it("should return global flags from config with global-config appended",()=>{
18+
constconfig={
19+
get:(key:string)=>
20+
key==="coder.globalFlags"
21+
?["--verbose","--disable-direct-connections"]
22+
:undefined,
23+
}asunknownasWorkspaceConfiguration;
24+
25+
expect(getGlobalFlags(config,"/config/dir")).toStrictEqual([
26+
"--verbose",
27+
"--disable-direct-connections",
28+
"--global-config",
29+
'"/config/dir"',
30+
]);
31+
});
32+
33+
it("should not filter duplicate global-config flags, last takes precedence",()=>{
34+
constconfig={
35+
get:(key:string)=>
36+
key==="coder.globalFlags"
37+
?[
38+
"-v",
39+
"--global-config /path/to/ignored",
40+
"--disable-direct-connections",
41+
]
42+
:undefined,
43+
}asunknownasWorkspaceConfiguration;
44+
45+
expect(getGlobalFlags(config,"/config/dir")).toStrictEqual([
46+
"-v",
47+
"--global-config /path/to/ignored",
48+
"--disable-direct-connections",
49+
"--global-config",
50+
'"/config/dir"',
51+
]);
52+
});
53+
54+
it("should not filter header-command flags, header args appended at end",()=>{
55+
constconfig={
56+
get:(key:string)=>{
57+
if(key==="coder.headerCommand"){
58+
return"echo test";
59+
}
60+
if(key==="coder.globalFlags"){
61+
return["-v","--header-command custom","--no-feature-warning"];
62+
}
63+
returnundefined;
64+
},
65+
}asunknownasWorkspaceConfiguration;
66+
67+
constresult=getGlobalFlags(config,"/config/dir");
68+
expect(result).toStrictEqual([
69+
"-v",
70+
"--header-command custom",// ignored by CLI
71+
"--no-feature-warning",
72+
"--global-config",
73+
'"/config/dir"',
74+
"--header-command",
75+
"'echo test'",
76+
]);
77+
});
78+
});

‎src/globalFlags.ts‎

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

55
exportfunctiongetGlobalFlags(
66
configs:WorkspaceConfiguration,
7-
configDir?:string,
7+
configDir:string,
88
):string[]{
9-
constglobalFlags=configs.get<string[]>("coder.globalFlags")||[];
10-
constheaderArgs=getHeaderArgs(configs);
11-
constglobalConfigArgs=configDir
12-
?["--global-config",escapeCommandArg(configDir)]
13-
:[];
14-
15-
// Precedence of "coder.headerCommand" is higher than "coder.globalConfig" with the "--header-command" flag
16-
letfilteredGlobalFlags=globalFlags;
17-
if(headerArgs.length>0){
18-
filteredGlobalFlags=globalFlags.filter(
19-
(flag)=>!flag.startsWith("--header-command"),
20-
);
21-
}
22-
23-
if(globalConfigArgs.length>0){
24-
filteredGlobalFlags=globalFlags.filter(
25-
(flag)=>!flag.startsWith("--global-config"),
26-
);
27-
}
28-
return[...filteredGlobalFlags, ...headerArgs, ...globalConfigArgs];
9+
// Last takes precedence/overrides previous ones
10+
return[
11+
...(configs.get<string[]>("coder.globalFlags")||[]),
12+
...["--global-config",escapeCommandArg(configDir)],
13+
...getHeaderArgs(configs),
14+
];
2915
}

‎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-
constglobalConfigs=this.globalConfigs(featureSet,label);
765+
constglobalConfigs=this.globalConfigs(label);
766766

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

827-
privateglobalConfigs(featureSet:FeatureSet,label:string):string{
827+
privateglobalConfigs(label:string):string{
828828
constvscodeConfig=vscode.workspace.getConfiguration();
829-
letargs: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+
constargs:string[]=getGlobalFlags(
830+
vscodeConfig,
831+
path.dirname(this.storage.getSessionTokenPath(label)),
832+
);
838833
returnargs.length===0 ?"" :`${args.join(" ")}`;
839834
}
840835

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp