-
Notifications
You must be signed in to change notification settings - Fork 514
Expand file tree
/
Copy pathmigrate-arguments-syntax.ps1
More file actions
143 lines (123 loc) · 5.51 KB
/
migrate-arguments-syntax.ps1
File metadata and controls
143 lines (123 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Migration Script: $ARGUMENTS syntax (v2.1.19 breaking change)
#
# Purpose: Update custom commands from old dot notation to new bracket syntax
# Breaking Change: $ARGUMENTS.0 → $ARGUMENTS[0] (introduced in Claude Code v2.1.19)
#
# Usage:
# .\migrate-arguments-syntax.ps1 # Preview changes
# .\migrate-arguments-syntax.ps1 -Apply # Apply changes
#
# Safety: Creates backups before modifying files
param(
[switch]$Apply
)
# Configuration
$BackupDir = Join-Path $env:USERPROFILE ".claude\backups\arguments-migration-$(Get-Date -Format 'yyyyMMdd-HHmmss')"
# Directories to scan
$ScanDirs = @(
(Join-Path $env:USERPROFILE ".claude\commands"),
(Join-Path $env:USERPROFILE ".claude\skills"),
".claude\commands",
".claude\skills"
)
Write-Host "╔═══════════════════════════════════════════════════════════╗" -ForegroundColor Blue
Write-Host "║ Claude Code v2.1.19 - `$ARGUMENTS Syntax Migration ║" -ForegroundColor Blue
Write-Host "╚═══════════════════════════════════════════════════════════╝" -ForegroundColor Blue
Write-Host ""
Write-Host "Breaking Change: " -NoNewline -ForegroundColor Yellow
Write-Host "`$ARGUMENTS.N → `$ARGUMENTS[N]"
Write-Host ""
# Check if any scan directories exist
$foundDirs = $false
foreach ($dir in $ScanDirs) {
if (Test-Path $dir) {
$foundDirs = $true
break
}
}
if (-not $foundDirs) {
Write-Host "✓ No custom commands/skills directories found" -ForegroundColor Green
Write-Host " Nothing to migrate."
exit 0
}
# Find files with old syntax
Write-Host "Scanning for files with old `$ARGUMENTS.N syntax..."
Write-Host ""
$affectedFiles = @()
foreach ($dir in $ScanDirs) {
if (-not (Test-Path $dir)) {
continue
}
# Find .md files with $ARGUMENTS.N pattern
Get-ChildItem -Path $dir -Filter "*.md" -Recurse -ErrorAction SilentlyContinue | ForEach-Object {
$content = Get-Content $_.FullName -Raw
if ($content -match '\$ARGUMENTS\.[0-9]') {
$affectedFiles += $_.FullName
}
}
}
# Report findings
if ($affectedFiles.Count -eq 0) {
Write-Host "✓ No files need migration" -ForegroundColor Green
Write-Host " All custom commands already use the new syntax."
exit 0
}
Write-Host "Found $($affectedFiles.Count) file(s) with old syntax:" -ForegroundColor Yellow
Write-Host ""
# Preview changes
foreach ($file in $affectedFiles) {
Write-Host "📄 $file" -ForegroundColor Blue
# Show occurrences
$lineNum = 0
Get-Content $file | ForEach-Object {
$lineNum++
if ($_ -match '\$ARGUMENTS\.[0-9]') {
Write-Host " Line ${lineNum}: $_" -ForegroundColor Yellow
}
}
Write-Host ""
}
# Apply changes if requested
if ($Apply) {
Write-Host "Creating backups in: $BackupDir" -ForegroundColor Yellow
New-Item -ItemType Directory -Path $BackupDir -Force | Out-Null
foreach ($file in $affectedFiles) {
# Create backup
$fileName = Split-Path $file -Leaf
$backupPath = Join-Path $BackupDir $fileName
Copy-Item $file $backupPath
Write-Host "✓ Backed up: $fileName" -ForegroundColor Green
# Apply migration
$content = Get-Content $file -Raw
$newContent = $content -replace '\$ARGUMENTS\.([0-9])', '$ARGUMENTS[$1]'
Set-Content -Path $file -Value $newContent -NoNewline
Write-Host "✓ Migrated: $file" -ForegroundColor Green
}
Write-Host ""
Write-Host "╔═══════════════════════════════════════════════════════════╗" -ForegroundColor Green
Write-Host "║ ✓ Migration Complete ║" -ForegroundColor Green
Write-Host "╚═══════════════════════════════════════════════════════════╝" -ForegroundColor Green
Write-Host ""
Write-Host "Backups saved to: $BackupDir"
Write-Host ""
Write-Host "Changes applied:"
Write-Host " • `$ARGUMENTS.0 → `$ARGUMENTS[0]"
Write-Host " • `$ARGUMENTS.1 → `$ARGUMENTS[1]"
Write-Host " • etc."
Write-Host ""
Write-Host "You can also use shorthand: `$0, `$1, `$2, ..."
} else {
Write-Host "═══════════════════════════════════════════════════════════" -ForegroundColor Yellow
Write-Host "DRY RUN MODE - No changes applied" -ForegroundColor Yellow
Write-Host "═══════════════════════════════════════════════════════════" -ForegroundColor Yellow
Write-Host ""
Write-Host "To apply these changes, run:"
Write-Host " .\migrate-arguments-syntax.ps1 -Apply" -ForegroundColor Green
Write-Host ""
Write-Host "This will:"
Write-Host " 1. Create backups in %USERPROFILE%\.claude\backups\"
Write-Host " 2. Update all files to new bracket syntax"
Write-Host " 3. Preserve original files in backup directory"
}
Write-Host ""
Write-Host "Documentation: https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md#2119"