Skip to content

Commit 9acd526

Browse files
author
Andrew Hall
authored
Allow multiple forms for the featureflag script (#10304)
It was tedious to get the actual argument right, so this checks for multiple forms and tries to correct them. The following should be supported now: eng\scripts\featureflag.ps1 -set -flag Razor.LSP.ForceRuntimeCodeGeneration -enable eng\scripts\featureflag.ps1 -set -flag Razor\LSP\ForceRuntimeCodeGeneration -enable eng\scripts\featureflag.ps1 -set -flag FeatureFlags.Razor.LSP.ForceRuntimeCodeGeneration -enable eng\scripts\featureflag.ps1 -set -flag FeatureFlags\Razor\LSP\ForceRuntimeCodeGeneration -enable This should make copying the value from code easier to figure out. We could also just assume feature flags start with FeatureFlags\LSP\Razor\<flagname> but that's not inherantly true, just happens to be for now.
1 parent 8558b71 commit 9acd526

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

eng/scripts/featureflag.ps1

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[CmdletBinding(PositionalBinding=$false)]
1+
[CmdletBinding(PositionalBinding = $false)]
22
param(
33
[string]$flag = $null,
44
[switch]$enable,
@@ -9,53 +9,59 @@ param(
99
)
1010

1111
if ($null -eq $flag -or '' -eq $flag) {
12-
throw "Specify a -flag to set"
12+
throw "Specify a -flag to set"
1313
}
1414

1515
if ($flag.EndsWith("\")) {
1616
throw "Provided flag '$flag' ends with '\', which is not valid"
1717
}
1818

19-
$value = 0
19+
if ($set -and $get) {
20+
throw "Use only one of set or get"
21+
}
2022

21-
if ($enable)
22-
{
23-
$value = 1
23+
if (-not ($set -or $get)) {
24+
throw "Specify one of -set or -get"
2425
}
2526

26-
# If the flag contains \ assume that the intention was to provide a full path, otherwise use the default for razor lsp feature flags
27-
if (-not $flag.Contains("\"))
28-
{
29-
$flag = "FeatureFlags\Razor\LSP\" + $flag
27+
if ($set) {
28+
if ($enable -and $disable) {
29+
throw "Use only one of -enable or -disable"
30+
}
31+
32+
if (-not ($enable -or $disable)) {
33+
throw "Specify one of -enable or -disable"
34+
}
3035
}
3136

32-
Write-Host "Attempting to modify '$flag' to '$value'"
37+
$value = 0
3338

39+
if ($enable) {
40+
$value = 1
41+
}
3442

3543
$slashIndex = $flag.LastIndexOf("\")
3644

3745
if ($slashIndex -ge 0) {
38-
$flagBase = $flag.Substring(0, $slashIndex)
39-
$flag = $flag.Substring($slashIndex + 1) #+1 to trim the \
40-
}
41-
42-
if ($set -and $get) {
43-
throw "Use only one of set or get"
46+
$flagBase = $flag.Substring(0, $slashIndex)
47+
$flag = $flag.Substring($slashIndex + 1) #+1 to trim the \
4448
}
4549

46-
if (-not ($set -or $get)) {
47-
throw "Specify one of -set or -get"
50+
if ($flag.IndexOf('.') -ge 0) {
51+
Write-Host "Replacing . in $flag with \"
52+
$flag = $flag.Replace(".", "\")
53+
Write-Host "New value for flag: $flag"
4854
}
4955

50-
if ($set)
56+
if (-not ($flag -like "FeatureFlags*"))
5157
{
52-
if ($enable -and $disable) {
53-
throw "Use only one of -enable or -disable"
54-
}
58+
Write-Host "FeatureFlags was not present, modifying $flag"
59+
$flag = "FeatureFlags\" + $flag
60+
Write-Host "New value for flag: $flag"
61+
}
5562

56-
if (-not ($enable -or $disable)) {
57-
throw "Specify one of -enable or -disable"
58-
}
63+
if ($set) {
64+
Write-Host "Attempting to modify '$flag' to '$value'"
5965
}
6066

6167
$engPath = Join-Path $PSScriptRoot ".."
@@ -74,9 +80,10 @@ Write-Host "Running VsRegEdit"
7480
$vsDir = $vsInfo.installationPath.TrimEnd("\")
7581
$vsRegEdit = Join-Path (Join-Path (Join-Path $vsDir 'Common7') 'IDE') 'VsRegEdit.exe'
7682

83+
Write-Host "Current value:"
84+
&$vsRegEdit read "$vsDir" $hive HKCU $flag VALUE dword
85+
7786
if ($set) {
87+
Write-Host "Running $vsRegEdit set `"$vsDir`" $hive HKCU $flag VALUE dword $value"
7888
&$vsRegEdit set "$vsDir" $hive HKCU $flag VALUE dword $value
7989
}
80-
else {
81-
&$vsRegEdit read "$vsDir" $hive HKCU $flag VALUE dword
82-
}

0 commit comments

Comments
 (0)