Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit e0fd6a8

Browse files
authored
Add help update script (#40)
1 parent 6e0608b commit e0fd6a8

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
function Replace-TextInFile {
2+
Param(
3+
[Parameter(Mandatory)]
4+
[string] $FilePath,
5+
[Parameter(Mandatory)]
6+
[string] $Pattern,
7+
[string] $Replacement
8+
)
9+
10+
$input = [System.IO.File]::ReadAllText($FilePath)
11+
$output = $input -creplace $Pattern, $Replacement
12+
if (($input.Length -ne $output.Length) -and ($input -ne $output)) {
13+
[System.IO.File]::WriteAllText(
14+
$FilePath,
15+
$output
16+
)
17+
}
18+
}
19+
20+
function Update-FileContent {
21+
param(
22+
[Parameter(Mandatory)]
23+
[ValidateScript({
24+
Test-Path $_ -PathType Container
25+
}, ErrorMessage="Source dir '{0}' is not a directory")]
26+
[string] $SourceDir,
27+
[Parameter(Mandatory)]
28+
[string] $Pattern,
29+
[string] $Replacement
30+
)
31+
32+
Get-ChildItem -Path $SourceDir -Filter *.cs -Recurse -File | ForEach-Object {
33+
Replace-TextInFile -FilePath $_ -Pattern $Pattern -Replacement $Replacement
34+
}
35+
}
36+
37+
function Update-MeUserIdHelp {
38+
param(
39+
[string] $WorkspaceRootDir = "."
40+
)
41+
$usersDir = Join-Path -Path $WorkspaceRootDir -ChildPath src\generated\Users
42+
Update-FileContent -SourceDir $usersDir -Pattern 'userIdOption = new Option<string>\("--user-id", description: "(.+)"\)' -Replacement 'userIdOption = new Option<string>("--user-id", description: "$1. Use ''me'' for the currently signed in user.")'
43+
}
44+
45+
function Update-UsersMeAlias {
46+
param(
47+
[string] $WorkspaceRootDir = "."
48+
)
49+
$usersRb = Join-Path -Path $WorkspaceRootDir -ChildPath src\generated\GraphClient.cs
50+
Replace-TextInFile -FilePath $usersRb -Pattern 'command = new Command\("users"\);(\r?\n\s*)' -Replacement 'command = new Command("users");$1command.AddAlias("me");$1'
51+
}

0 commit comments

Comments
 (0)