@drfed/drfed 0.0.0-stage → 0.1.0-dev.561
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +1198 -2
- package/bin/drfed-account.mjs +20 -0
- package/bin/drfed-migrate.mjs +20 -0
- package/bin/drfed-server.mjs +20 -0
- package/bin/drfed-web.mjs +20 -0
- package/completions/bash/drfed-account +219 -0
- package/completions/bash/drfed-migrate +219 -0
- package/completions/bash/drfed-server +219 -0
- package/completions/bash/drfed-web +219 -0
- package/completions/fish/drfed-account.fish +264 -0
- package/completions/fish/drfed-migrate.fish +264 -0
- package/completions/fish/drfed-server.fish +264 -0
- package/completions/fish/drfed-web.fish +264 -0
- package/completions/nu/drfed-account.nu +293 -0
- package/completions/nu/drfed-migrate.nu +293 -0
- package/completions/nu/drfed-server.nu +293 -0
- package/completions/nu/drfed-web.nu +293 -0
- package/completions/pwsh/drfed-account.ps1 +183 -0
- package/completions/pwsh/drfed-migrate.ps1 +183 -0
- package/completions/pwsh/drfed-server.ps1 +183 -0
- package/completions/pwsh/drfed-web.ps1 +183 -0
- package/completions/zsh/_drfed-account +145 -0
- package/completions/zsh/_drfed-migrate +145 -0
- package/completions/zsh/_drfed-server +145 -0
- package/completions/zsh/_drfed-web +145 -0
- package/dist/api-mail-parser.d.mts +106 -0
- package/dist/api-mail-parser.d.mts.map +1 -0
- package/dist/api-mail-parser.mjs +145 -0
- package/dist/api-mail-parser.mjs.map +1 -0
- package/dist/api-mail-settings-BcGaqQ9f.d.mts +142 -0
- package/dist/api-mail-settings-BcGaqQ9f.d.mts.map +1 -0
- package/dist/api-mail-settings.d.mts +2 -0
- package/dist/api-mail-settings.mjs +272 -0
- package/dist/api-mail-settings.mjs.map +1 -0
- package/dist/bounded-mail-runtime.d.mts +9 -0
- package/dist/bounded-mail-runtime.d.mts.map +1 -0
- package/dist/bounded-mail-runtime.mjs +66 -0
- package/dist/bounded-mail-runtime.mjs.map +1 -0
- package/dist/commands/account-create.d.mts +37 -0
- package/dist/commands/account-create.d.mts.map +1 -0
- package/dist/commands/account-create.mjs +87 -0
- package/dist/commands/account-create.mjs.map +1 -0
- package/dist/commands/account-program.d.mts +223 -0
- package/dist/commands/account-program.d.mts.map +1 -0
- package/dist/commands/account-program.mjs +116 -0
- package/dist/commands/account-program.mjs.map +1 -0
- package/dist/commands/account.d.mts +6 -0
- package/dist/commands/account.d.mts.map +1 -0
- package/dist/commands/account.mjs +91 -0
- package/dist/commands/account.mjs.map +1 -0
- package/dist/commands/migrate-program.d.mts +219 -0
- package/dist/commands/migrate-program.d.mts.map +1 -0
- package/dist/commands/migrate-program.mjs +116 -0
- package/dist/commands/migrate-program.mjs.map +1 -0
- package/dist/commands/migrate.d.mts +6 -0
- package/dist/commands/migrate.d.mts.map +1 -0
- package/dist/commands/migrate.mjs +85 -0
- package/dist/commands/migrate.mjs.map +1 -0
- package/dist/commands/web-program.d.mts +213 -0
- package/dist/commands/web-program.d.mts.map +1 -0
- package/dist/commands/web-program.mjs +112 -0
- package/dist/commands/web-program.mjs.map +1 -0
- package/dist/commands/web.d.mts +6 -0
- package/dist/commands/web.d.mts.map +1 -0
- package/dist/commands/web.mjs +184 -0
- package/dist/commands/web.mjs.map +1 -0
- package/dist/configuration-DVVF7xNv.d.mts +432 -0
- package/dist/configuration-DVVF7xNv.d.mts.map +1 -0
- package/dist/configuration.d.mts +2 -0
- package/dist/configuration.mjs +469 -0
- package/dist/configuration.mjs.map +1 -0
- package/dist/data-path.d.mts +9 -0
- package/dist/data-path.d.mts.map +1 -0
- package/dist/data-path.mjs +21 -0
- package/dist/data-path.mjs.map +1 -0
- package/dist/database-runtime.d.mts +26 -0
- package/dist/database-runtime.d.mts.map +1 -0
- package/dist/database-runtime.mjs +92 -0
- package/dist/database-runtime.mjs.map +1 -0
- package/dist/database-settings.d.mts +36 -0
- package/dist/database-settings.d.mts.map +1 -0
- package/dist/database-settings.mjs +67 -0
- package/dist/database-settings.mjs.map +1 -0
- package/dist/diagnostics.d.mts +29 -0
- package/dist/diagnostics.d.mts.map +1 -0
- package/dist/diagnostics.mjs +61 -0
- package/dist/diagnostics.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +344 -0
- package/dist/index.mjs.map +1 -0
- package/dist/jmap-parser.d.mts +35 -0
- package/dist/jmap-parser.d.mts.map +1 -0
- package/dist/jmap-parser.mjs +42 -0
- package/dist/jmap-parser.mjs.map +1 -0
- package/dist/jmap-runtime.d.mts +10 -0
- package/dist/jmap-runtime.d.mts.map +1 -0
- package/dist/jmap-runtime.mjs +17 -0
- package/dist/jmap-runtime.mjs.map +1 -0
- package/dist/jmap-settings-BXNAF1ep.d.mts +41 -0
- package/dist/jmap-settings-BXNAF1ep.d.mts.map +1 -0
- package/dist/jmap-settings.d.mts +2 -0
- package/dist/jmap-settings.mjs +104 -0
- package/dist/jmap-settings.mjs.map +1 -0
- package/dist/logging.d.mts +33 -0
- package/dist/logging.d.mts.map +1 -0
- package/dist/logging.mjs +56 -0
- package/dist/logging.mjs.map +1 -0
- package/dist/mail-parser-DyI4wuQp.d.mts +246 -0
- package/dist/mail-parser-DyI4wuQp.d.mts.map +1 -0
- package/dist/mail-parser.d.mts +2 -0
- package/dist/mail-parser.mjs +100 -0
- package/dist/mail-parser.mjs.map +1 -0
- package/dist/mail-runtime-YROIQ8up.mjs +314 -0
- package/dist/mail-runtime-YROIQ8up.mjs.map +1 -0
- package/dist/mail-runtime.d.mts +68 -0
- package/dist/mail-runtime.d.mts.map +1 -0
- package/dist/mail-runtime.mjs +2 -0
- package/dist/mail-settings-BD1TQ0rt.mjs +427 -0
- package/dist/mail-settings-BD1TQ0rt.mjs.map +1 -0
- package/dist/mail-settings-DjWMAUaE.d.mts +80 -0
- package/dist/mail-settings-DjWMAUaE.d.mts.map +1 -0
- package/dist/mail-settings.d.mts +2 -0
- package/dist/mail-settings.mjs +2 -0
- package/dist/operations.d.mts +32 -0
- package/dist/operations.d.mts.map +1 -0
- package/dist/operations.mjs +55 -0
- package/dist/operations.mjs.map +1 -0
- package/dist/package-D1pbtLwn.mjs +6 -0
- package/dist/package-D1pbtLwn.mjs.map +1 -0
- package/dist/parser-DGIQTgS7.mjs +178 -0
- package/dist/parser-DGIQTgS7.mjs.map +1 -0
- package/dist/parser-TANGHRjL.d.mts +305 -0
- package/dist/parser-TANGHRjL.d.mts.map +1 -0
- package/dist/postgres-settings.d.mts +20 -0
- package/dist/postgres-settings.d.mts.map +1 -0
- package/dist/postgres-settings.mjs +60 -0
- package/dist/postgres-settings.mjs.map +1 -0
- package/dist/query-logger.d.mts +9 -0
- package/dist/query-logger.d.mts.map +1 -0
- package/dist/query-logger.mjs +17 -0
- package/dist/query-logger.mjs.map +1 -0
- package/dist/resources.d.mts +20 -0
- package/dist/resources.d.mts.map +1 -0
- package/dist/resources.mjs +34 -0
- package/dist/resources.mjs.map +1 -0
- package/dist/secret-source-BeZx72Ue.d.mts +21 -0
- package/dist/secret-source-BeZx72Ue.d.mts.map +1 -0
- package/dist/secret-source.d.mts +2 -0
- package/dist/secret-source.mjs +58 -0
- package/dist/secret-source.mjs.map +1 -0
- package/dist/serving.d.mts +82 -0
- package/dist/serving.d.mts.map +1 -0
- package/dist/serving.mjs +138 -0
- package/dist/serving.mjs.map +1 -0
- package/dist/smtp-settings.d.mts +11 -0
- package/dist/smtp-settings.d.mts.map +1 -0
- package/dist/smtp-settings.mjs +38 -0
- package/dist/smtp-settings.mjs.map +1 -0
- package/dist/valueparser.d.mts +46 -0
- package/dist/valueparser.d.mts.map +1 -0
- package/dist/valueparser.mjs +121 -0
- package/dist/valueparser.mjs.map +1 -0
- package/package.json +287 -3
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
|
|
2
|
+
Register-ArgumentCompleter -Native -CommandName drfed-account -ScriptBlock {
|
|
3
|
+
param($wordToComplete, $commandAst, $cursorPosition)
|
|
4
|
+
|
|
5
|
+
# Extract arguments from AST (handles quoted strings properly)
|
|
6
|
+
$arguments = @()
|
|
7
|
+
$commandElements = $commandAst.CommandElements
|
|
8
|
+
|
|
9
|
+
# Determine the range of elements to extract
|
|
10
|
+
# Exclude the last element if it matches wordToComplete (partial input case)
|
|
11
|
+
$maxIndex = $commandElements.Count - 1
|
|
12
|
+
if ($commandElements.Count -gt 1) {
|
|
13
|
+
$lastElement = $commandElements[$commandElements.Count - 1]
|
|
14
|
+
$lastText = if ($lastElement -is [System.Management.Automation.Language.StringConstantExpressionAst]) {
|
|
15
|
+
$lastElement.Value
|
|
16
|
+
} else {
|
|
17
|
+
$lastElement.Extent.Text
|
|
18
|
+
}
|
|
19
|
+
if ($lastText -eq $wordToComplete) {
|
|
20
|
+
$maxIndex = $commandElements.Count - 2
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
for ($i = 1; $i -le $maxIndex; $i++) {
|
|
25
|
+
$element = $commandElements[$i]
|
|
26
|
+
|
|
27
|
+
if ($element -is [System.Management.Automation.Language.StringConstantExpressionAst]) {
|
|
28
|
+
$arguments += $element.Value
|
|
29
|
+
} else {
|
|
30
|
+
$arguments += $element.Extent.Text
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# Build arguments array for completion command
|
|
35
|
+
$completionArgs = @()
|
|
36
|
+
$completionArgs += @('completion', 'pwsh')
|
|
37
|
+
$completionArgs += $arguments
|
|
38
|
+
$completionArgs += $wordToComplete
|
|
39
|
+
|
|
40
|
+
# Call completion command and capture output
|
|
41
|
+
try {
|
|
42
|
+
$output = & drfed-account $completionArgs 2>$null
|
|
43
|
+
if (-not $output) { return }
|
|
44
|
+
|
|
45
|
+
# Parse tab-separated output and create CompletionResult objects
|
|
46
|
+
$output -split "`n" | ForEach-Object {
|
|
47
|
+
$line = $_.Trim()
|
|
48
|
+
if (-not $line) { return }
|
|
49
|
+
|
|
50
|
+
if ($line -match '^__FILE__:') {
|
|
51
|
+
# Parse file completion directive: __FILE__:type:extensions:pattern:hidden
|
|
52
|
+
$directive = ($line -split "`t")[0]
|
|
53
|
+
$parts = $directive -split ':', 5
|
|
54
|
+
$type = $parts[1]
|
|
55
|
+
$extensions = $parts[2]
|
|
56
|
+
$pattern = $parts[3] -replace '%3A', ':' -replace '%25', '%'
|
|
57
|
+
$hidden = $parts[4] -eq '1'
|
|
58
|
+
|
|
59
|
+
# When a pattern is specified, use it as the file matching
|
|
60
|
+
# prefix instead of the current word. If the user has
|
|
61
|
+
# already typed beyond the pattern, keep their input for
|
|
62
|
+
# incremental narrowing. Normalize path separators before
|
|
63
|
+
# comparing so that Windows backslashes match forward slashes
|
|
64
|
+
# in the transported pattern.
|
|
65
|
+
$normalizedPattern = if ($pattern) { $pattern.Replace('\', '/') -replace '^\./','' } else { '' }
|
|
66
|
+
$normalizedWord = if ($wordToComplete) { $wordToComplete.Replace('\', '/') -replace '^\./','' } else { '' }
|
|
67
|
+
$comparison = if ($IsWindows) { [System.StringComparison]::OrdinalIgnoreCase } else { [System.StringComparison]::Ordinal }
|
|
68
|
+
# For wildcard patterns, compare only the directory prefix
|
|
69
|
+
$comparePattern = $normalizedPattern
|
|
70
|
+
if ($comparePattern -match '[*?]') {
|
|
71
|
+
$beforeWild = $comparePattern -replace '[*?].*', ''
|
|
72
|
+
if ($beforeWild.Contains('/')) {
|
|
73
|
+
$comparePattern = $beforeWild.Substring(0, $beforeWild.LastIndexOf('/') + 1)
|
|
74
|
+
} else {
|
|
75
|
+
$comparePattern = ''
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
$prefix = if (($comparePattern -or $normalizedWord) -and $normalizedWord -and $normalizedWord.StartsWith($comparePattern, $comparison) -and $normalizedWord.Length -ge $comparePattern.Length -and $wordToComplete -ne $pattern) {
|
|
79
|
+
$wordToComplete
|
|
80
|
+
} elseif ($pattern) {
|
|
81
|
+
$pattern
|
|
82
|
+
} elseif ($wordToComplete) {
|
|
83
|
+
$wordToComplete
|
|
84
|
+
} else { '' }
|
|
85
|
+
|
|
86
|
+
# Use -Force to include hidden files when requested, or when
|
|
87
|
+
# the prefix basename targets dotfiles (e.g., src/.e)
|
|
88
|
+
$prefixBasename = if ($prefix) { Split-Path -Leaf $prefix } else { '' }
|
|
89
|
+
$forceParam = if ($hidden -or ($prefixBasename -and $prefixBasename.StartsWith('.'))) { @{Force = $true} } else { @{} }
|
|
90
|
+
|
|
91
|
+
# If prefix is a directory without trailing slash, append
|
|
92
|
+
# one so Get-ChildItem lists its contents
|
|
93
|
+
if ($prefix -and (Test-Path -Path $prefix -PathType Container) -and -not $prefix.EndsWith('/') -and -not $prefix.EndsWith('\')) {
|
|
94
|
+
$prefix = $prefix + '/'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Build the glob path—when the prefix contains wildcard
|
|
98
|
+
# characters, use it as-is; otherwise append *
|
|
99
|
+
$globPath = if ($prefix -match '[*?]') { $prefix } else { "${prefix}*" }
|
|
100
|
+
|
|
101
|
+
# Get file system items based on type
|
|
102
|
+
$items = @()
|
|
103
|
+
switch ($type) {
|
|
104
|
+
'file' {
|
|
105
|
+
if ($extensions) {
|
|
106
|
+
# Filter by extensions, always include directories
|
|
107
|
+
$extList = ($extensions -split ',') -replace '^\.',''
|
|
108
|
+
$items = Get-ChildItem @forceParam -Path $globPath -ErrorAction SilentlyContinue |
|
|
109
|
+
Where-Object {
|
|
110
|
+
$_.PSIsContainer -or (($_.Extension -replace '^\.','' ) -in $extList)
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
$items = Get-ChildItem @forceParam -Path $globPath -ErrorAction SilentlyContinue
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
'directory' {
|
|
117
|
+
$items = Get-ChildItem @forceParam -Directory -Path $globPath -ErrorAction SilentlyContinue
|
|
118
|
+
}
|
|
119
|
+
'any' {
|
|
120
|
+
if ($extensions) {
|
|
121
|
+
# Filter by extensions, always include directories
|
|
122
|
+
$extList = ($extensions -split ',') -replace '^\.',''
|
|
123
|
+
$items = Get-ChildItem @forceParam -Path $globPath -ErrorAction SilentlyContinue |
|
|
124
|
+
Where-Object {
|
|
125
|
+
$_.PSIsContainer -or (($_.Extension -replace '^\.','' ) -in $extList)
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
$items = Get-ChildItem @forceParam -Path $globPath -ErrorAction SilentlyContinue
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
# For file/any modes with glob patterns, also add directories
|
|
134
|
+
# from the base directory for navigation
|
|
135
|
+
if ($prefix -match '[*?]' -and $type -ne 'directory') {
|
|
136
|
+
$globDir = Split-Path -Parent $prefix
|
|
137
|
+
if (-not $globDir) { $globDir = '.' }
|
|
138
|
+
$extraDirs = Get-ChildItem @forceParam -Directory -Path "$globDir/*" -ErrorAction SilentlyContinue
|
|
139
|
+
if ($extraDirs) { $items = @($items) + @($extraDirs) | Select-Object -Unique }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
# Filter hidden files unless requested or the prefix targets dotfiles
|
|
143
|
+
if (-not $hidden -and -not ($prefixBasename -and $prefixBasename.StartsWith('.'))) {
|
|
144
|
+
$items = $items | Where-Object { -not $_.Attributes.HasFlag([System.IO.FileAttributes]::Hidden) }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Extract directory prefix to preserve in completion text
|
|
148
|
+
$dirPrefix = if ($prefix -and ($prefix.Contains('/') -or $prefix.Contains('\'))) {
|
|
149
|
+
$slashIdx = [Math]::Max($prefix.LastIndexOf('/'), $prefix.LastIndexOf('\'))
|
|
150
|
+
$prefix.Substring(0, $slashIdx + 1)
|
|
151
|
+
} else { '' }
|
|
152
|
+
|
|
153
|
+
# Create completion results for files
|
|
154
|
+
$items | ForEach-Object {
|
|
155
|
+
$completionText = if ($_.PSIsContainer) { "$dirPrefix$($_.Name)/" } else { "$dirPrefix$($_.Name)" }
|
|
156
|
+
$itemType = if ($_.PSIsContainer) { 'Directory' } else { 'File' }
|
|
157
|
+
[System.Management.Automation.CompletionResult]::new(
|
|
158
|
+
$completionText,
|
|
159
|
+
$completionText,
|
|
160
|
+
'ParameterValue',
|
|
161
|
+
$itemType
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
# Parse literal completion: text\tlistItemText\tdescription
|
|
166
|
+
$parts = $line -split "`t", 3
|
|
167
|
+
$completionText = $parts[0]
|
|
168
|
+
$listItemText = if ($parts.Length -gt 1 -and $parts[1]) { $parts[1] } else { $completionText }
|
|
169
|
+
$toolTip = if ($parts.Length -gt 2 -and $parts[2]) { $parts[2] } else { $completionText }
|
|
170
|
+
|
|
171
|
+
[System.Management.Automation.CompletionResult]::new(
|
|
172
|
+
$completionText,
|
|
173
|
+
$listItemText,
|
|
174
|
+
'ParameterValue',
|
|
175
|
+
$toolTip
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} catch {
|
|
180
|
+
# Silently ignore errors
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
|
|
2
|
+
Register-ArgumentCompleter -Native -CommandName drfed-migrate -ScriptBlock {
|
|
3
|
+
param($wordToComplete, $commandAst, $cursorPosition)
|
|
4
|
+
|
|
5
|
+
# Extract arguments from AST (handles quoted strings properly)
|
|
6
|
+
$arguments = @()
|
|
7
|
+
$commandElements = $commandAst.CommandElements
|
|
8
|
+
|
|
9
|
+
# Determine the range of elements to extract
|
|
10
|
+
# Exclude the last element if it matches wordToComplete (partial input case)
|
|
11
|
+
$maxIndex = $commandElements.Count - 1
|
|
12
|
+
if ($commandElements.Count -gt 1) {
|
|
13
|
+
$lastElement = $commandElements[$commandElements.Count - 1]
|
|
14
|
+
$lastText = if ($lastElement -is [System.Management.Automation.Language.StringConstantExpressionAst]) {
|
|
15
|
+
$lastElement.Value
|
|
16
|
+
} else {
|
|
17
|
+
$lastElement.Extent.Text
|
|
18
|
+
}
|
|
19
|
+
if ($lastText -eq $wordToComplete) {
|
|
20
|
+
$maxIndex = $commandElements.Count - 2
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
for ($i = 1; $i -le $maxIndex; $i++) {
|
|
25
|
+
$element = $commandElements[$i]
|
|
26
|
+
|
|
27
|
+
if ($element -is [System.Management.Automation.Language.StringConstantExpressionAst]) {
|
|
28
|
+
$arguments += $element.Value
|
|
29
|
+
} else {
|
|
30
|
+
$arguments += $element.Extent.Text
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# Build arguments array for completion command
|
|
35
|
+
$completionArgs = @()
|
|
36
|
+
$completionArgs += @('completion', 'pwsh')
|
|
37
|
+
$completionArgs += $arguments
|
|
38
|
+
$completionArgs += $wordToComplete
|
|
39
|
+
|
|
40
|
+
# Call completion command and capture output
|
|
41
|
+
try {
|
|
42
|
+
$output = & drfed-migrate $completionArgs 2>$null
|
|
43
|
+
if (-not $output) { return }
|
|
44
|
+
|
|
45
|
+
# Parse tab-separated output and create CompletionResult objects
|
|
46
|
+
$output -split "`n" | ForEach-Object {
|
|
47
|
+
$line = $_.Trim()
|
|
48
|
+
if (-not $line) { return }
|
|
49
|
+
|
|
50
|
+
if ($line -match '^__FILE__:') {
|
|
51
|
+
# Parse file completion directive: __FILE__:type:extensions:pattern:hidden
|
|
52
|
+
$directive = ($line -split "`t")[0]
|
|
53
|
+
$parts = $directive -split ':', 5
|
|
54
|
+
$type = $parts[1]
|
|
55
|
+
$extensions = $parts[2]
|
|
56
|
+
$pattern = $parts[3] -replace '%3A', ':' -replace '%25', '%'
|
|
57
|
+
$hidden = $parts[4] -eq '1'
|
|
58
|
+
|
|
59
|
+
# When a pattern is specified, use it as the file matching
|
|
60
|
+
# prefix instead of the current word. If the user has
|
|
61
|
+
# already typed beyond the pattern, keep their input for
|
|
62
|
+
# incremental narrowing. Normalize path separators before
|
|
63
|
+
# comparing so that Windows backslashes match forward slashes
|
|
64
|
+
# in the transported pattern.
|
|
65
|
+
$normalizedPattern = if ($pattern) { $pattern.Replace('\', '/') -replace '^\./','' } else { '' }
|
|
66
|
+
$normalizedWord = if ($wordToComplete) { $wordToComplete.Replace('\', '/') -replace '^\./','' } else { '' }
|
|
67
|
+
$comparison = if ($IsWindows) { [System.StringComparison]::OrdinalIgnoreCase } else { [System.StringComparison]::Ordinal }
|
|
68
|
+
# For wildcard patterns, compare only the directory prefix
|
|
69
|
+
$comparePattern = $normalizedPattern
|
|
70
|
+
if ($comparePattern -match '[*?]') {
|
|
71
|
+
$beforeWild = $comparePattern -replace '[*?].*', ''
|
|
72
|
+
if ($beforeWild.Contains('/')) {
|
|
73
|
+
$comparePattern = $beforeWild.Substring(0, $beforeWild.LastIndexOf('/') + 1)
|
|
74
|
+
} else {
|
|
75
|
+
$comparePattern = ''
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
$prefix = if (($comparePattern -or $normalizedWord) -and $normalizedWord -and $normalizedWord.StartsWith($comparePattern, $comparison) -and $normalizedWord.Length -ge $comparePattern.Length -and $wordToComplete -ne $pattern) {
|
|
79
|
+
$wordToComplete
|
|
80
|
+
} elseif ($pattern) {
|
|
81
|
+
$pattern
|
|
82
|
+
} elseif ($wordToComplete) {
|
|
83
|
+
$wordToComplete
|
|
84
|
+
} else { '' }
|
|
85
|
+
|
|
86
|
+
# Use -Force to include hidden files when requested, or when
|
|
87
|
+
# the prefix basename targets dotfiles (e.g., src/.e)
|
|
88
|
+
$prefixBasename = if ($prefix) { Split-Path -Leaf $prefix } else { '' }
|
|
89
|
+
$forceParam = if ($hidden -or ($prefixBasename -and $prefixBasename.StartsWith('.'))) { @{Force = $true} } else { @{} }
|
|
90
|
+
|
|
91
|
+
# If prefix is a directory without trailing slash, append
|
|
92
|
+
# one so Get-ChildItem lists its contents
|
|
93
|
+
if ($prefix -and (Test-Path -Path $prefix -PathType Container) -and -not $prefix.EndsWith('/') -and -not $prefix.EndsWith('\')) {
|
|
94
|
+
$prefix = $prefix + '/'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Build the glob path—when the prefix contains wildcard
|
|
98
|
+
# characters, use it as-is; otherwise append *
|
|
99
|
+
$globPath = if ($prefix -match '[*?]') { $prefix } else { "${prefix}*" }
|
|
100
|
+
|
|
101
|
+
# Get file system items based on type
|
|
102
|
+
$items = @()
|
|
103
|
+
switch ($type) {
|
|
104
|
+
'file' {
|
|
105
|
+
if ($extensions) {
|
|
106
|
+
# Filter by extensions, always include directories
|
|
107
|
+
$extList = ($extensions -split ',') -replace '^\.',''
|
|
108
|
+
$items = Get-ChildItem @forceParam -Path $globPath -ErrorAction SilentlyContinue |
|
|
109
|
+
Where-Object {
|
|
110
|
+
$_.PSIsContainer -or (($_.Extension -replace '^\.','' ) -in $extList)
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
$items = Get-ChildItem @forceParam -Path $globPath -ErrorAction SilentlyContinue
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
'directory' {
|
|
117
|
+
$items = Get-ChildItem @forceParam -Directory -Path $globPath -ErrorAction SilentlyContinue
|
|
118
|
+
}
|
|
119
|
+
'any' {
|
|
120
|
+
if ($extensions) {
|
|
121
|
+
# Filter by extensions, always include directories
|
|
122
|
+
$extList = ($extensions -split ',') -replace '^\.',''
|
|
123
|
+
$items = Get-ChildItem @forceParam -Path $globPath -ErrorAction SilentlyContinue |
|
|
124
|
+
Where-Object {
|
|
125
|
+
$_.PSIsContainer -or (($_.Extension -replace '^\.','' ) -in $extList)
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
$items = Get-ChildItem @forceParam -Path $globPath -ErrorAction SilentlyContinue
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
# For file/any modes with glob patterns, also add directories
|
|
134
|
+
# from the base directory for navigation
|
|
135
|
+
if ($prefix -match '[*?]' -and $type -ne 'directory') {
|
|
136
|
+
$globDir = Split-Path -Parent $prefix
|
|
137
|
+
if (-not $globDir) { $globDir = '.' }
|
|
138
|
+
$extraDirs = Get-ChildItem @forceParam -Directory -Path "$globDir/*" -ErrorAction SilentlyContinue
|
|
139
|
+
if ($extraDirs) { $items = @($items) + @($extraDirs) | Select-Object -Unique }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
# Filter hidden files unless requested or the prefix targets dotfiles
|
|
143
|
+
if (-not $hidden -and -not ($prefixBasename -and $prefixBasename.StartsWith('.'))) {
|
|
144
|
+
$items = $items | Where-Object { -not $_.Attributes.HasFlag([System.IO.FileAttributes]::Hidden) }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Extract directory prefix to preserve in completion text
|
|
148
|
+
$dirPrefix = if ($prefix -and ($prefix.Contains('/') -or $prefix.Contains('\'))) {
|
|
149
|
+
$slashIdx = [Math]::Max($prefix.LastIndexOf('/'), $prefix.LastIndexOf('\'))
|
|
150
|
+
$prefix.Substring(0, $slashIdx + 1)
|
|
151
|
+
} else { '' }
|
|
152
|
+
|
|
153
|
+
# Create completion results for files
|
|
154
|
+
$items | ForEach-Object {
|
|
155
|
+
$completionText = if ($_.PSIsContainer) { "$dirPrefix$($_.Name)/" } else { "$dirPrefix$($_.Name)" }
|
|
156
|
+
$itemType = if ($_.PSIsContainer) { 'Directory' } else { 'File' }
|
|
157
|
+
[System.Management.Automation.CompletionResult]::new(
|
|
158
|
+
$completionText,
|
|
159
|
+
$completionText,
|
|
160
|
+
'ParameterValue',
|
|
161
|
+
$itemType
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
# Parse literal completion: text\tlistItemText\tdescription
|
|
166
|
+
$parts = $line -split "`t", 3
|
|
167
|
+
$completionText = $parts[0]
|
|
168
|
+
$listItemText = if ($parts.Length -gt 1 -and $parts[1]) { $parts[1] } else { $completionText }
|
|
169
|
+
$toolTip = if ($parts.Length -gt 2 -and $parts[2]) { $parts[2] } else { $completionText }
|
|
170
|
+
|
|
171
|
+
[System.Management.Automation.CompletionResult]::new(
|
|
172
|
+
$completionText,
|
|
173
|
+
$listItemText,
|
|
174
|
+
'ParameterValue',
|
|
175
|
+
$toolTip
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} catch {
|
|
180
|
+
# Silently ignore errors
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
|
|
2
|
+
Register-ArgumentCompleter -Native -CommandName drfed-server -ScriptBlock {
|
|
3
|
+
param($wordToComplete, $commandAst, $cursorPosition)
|
|
4
|
+
|
|
5
|
+
# Extract arguments from AST (handles quoted strings properly)
|
|
6
|
+
$arguments = @()
|
|
7
|
+
$commandElements = $commandAst.CommandElements
|
|
8
|
+
|
|
9
|
+
# Determine the range of elements to extract
|
|
10
|
+
# Exclude the last element if it matches wordToComplete (partial input case)
|
|
11
|
+
$maxIndex = $commandElements.Count - 1
|
|
12
|
+
if ($commandElements.Count -gt 1) {
|
|
13
|
+
$lastElement = $commandElements[$commandElements.Count - 1]
|
|
14
|
+
$lastText = if ($lastElement -is [System.Management.Automation.Language.StringConstantExpressionAst]) {
|
|
15
|
+
$lastElement.Value
|
|
16
|
+
} else {
|
|
17
|
+
$lastElement.Extent.Text
|
|
18
|
+
}
|
|
19
|
+
if ($lastText -eq $wordToComplete) {
|
|
20
|
+
$maxIndex = $commandElements.Count - 2
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
for ($i = 1; $i -le $maxIndex; $i++) {
|
|
25
|
+
$element = $commandElements[$i]
|
|
26
|
+
|
|
27
|
+
if ($element -is [System.Management.Automation.Language.StringConstantExpressionAst]) {
|
|
28
|
+
$arguments += $element.Value
|
|
29
|
+
} else {
|
|
30
|
+
$arguments += $element.Extent.Text
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# Build arguments array for completion command
|
|
35
|
+
$completionArgs = @()
|
|
36
|
+
$completionArgs += @('completion', 'pwsh')
|
|
37
|
+
$completionArgs += $arguments
|
|
38
|
+
$completionArgs += $wordToComplete
|
|
39
|
+
|
|
40
|
+
# Call completion command and capture output
|
|
41
|
+
try {
|
|
42
|
+
$output = & drfed-server $completionArgs 2>$null
|
|
43
|
+
if (-not $output) { return }
|
|
44
|
+
|
|
45
|
+
# Parse tab-separated output and create CompletionResult objects
|
|
46
|
+
$output -split "`n" | ForEach-Object {
|
|
47
|
+
$line = $_.Trim()
|
|
48
|
+
if (-not $line) { return }
|
|
49
|
+
|
|
50
|
+
if ($line -match '^__FILE__:') {
|
|
51
|
+
# Parse file completion directive: __FILE__:type:extensions:pattern:hidden
|
|
52
|
+
$directive = ($line -split "`t")[0]
|
|
53
|
+
$parts = $directive -split ':', 5
|
|
54
|
+
$type = $parts[1]
|
|
55
|
+
$extensions = $parts[2]
|
|
56
|
+
$pattern = $parts[3] -replace '%3A', ':' -replace '%25', '%'
|
|
57
|
+
$hidden = $parts[4] -eq '1'
|
|
58
|
+
|
|
59
|
+
# When a pattern is specified, use it as the file matching
|
|
60
|
+
# prefix instead of the current word. If the user has
|
|
61
|
+
# already typed beyond the pattern, keep their input for
|
|
62
|
+
# incremental narrowing. Normalize path separators before
|
|
63
|
+
# comparing so that Windows backslashes match forward slashes
|
|
64
|
+
# in the transported pattern.
|
|
65
|
+
$normalizedPattern = if ($pattern) { $pattern.Replace('\', '/') -replace '^\./','' } else { '' }
|
|
66
|
+
$normalizedWord = if ($wordToComplete) { $wordToComplete.Replace('\', '/') -replace '^\./','' } else { '' }
|
|
67
|
+
$comparison = if ($IsWindows) { [System.StringComparison]::OrdinalIgnoreCase } else { [System.StringComparison]::Ordinal }
|
|
68
|
+
# For wildcard patterns, compare only the directory prefix
|
|
69
|
+
$comparePattern = $normalizedPattern
|
|
70
|
+
if ($comparePattern -match '[*?]') {
|
|
71
|
+
$beforeWild = $comparePattern -replace '[*?].*', ''
|
|
72
|
+
if ($beforeWild.Contains('/')) {
|
|
73
|
+
$comparePattern = $beforeWild.Substring(0, $beforeWild.LastIndexOf('/') + 1)
|
|
74
|
+
} else {
|
|
75
|
+
$comparePattern = ''
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
$prefix = if (($comparePattern -or $normalizedWord) -and $normalizedWord -and $normalizedWord.StartsWith($comparePattern, $comparison) -and $normalizedWord.Length -ge $comparePattern.Length -and $wordToComplete -ne $pattern) {
|
|
79
|
+
$wordToComplete
|
|
80
|
+
} elseif ($pattern) {
|
|
81
|
+
$pattern
|
|
82
|
+
} elseif ($wordToComplete) {
|
|
83
|
+
$wordToComplete
|
|
84
|
+
} else { '' }
|
|
85
|
+
|
|
86
|
+
# Use -Force to include hidden files when requested, or when
|
|
87
|
+
# the prefix basename targets dotfiles (e.g., src/.e)
|
|
88
|
+
$prefixBasename = if ($prefix) { Split-Path -Leaf $prefix } else { '' }
|
|
89
|
+
$forceParam = if ($hidden -or ($prefixBasename -and $prefixBasename.StartsWith('.'))) { @{Force = $true} } else { @{} }
|
|
90
|
+
|
|
91
|
+
# If prefix is a directory without trailing slash, append
|
|
92
|
+
# one so Get-ChildItem lists its contents
|
|
93
|
+
if ($prefix -and (Test-Path -Path $prefix -PathType Container) -and -not $prefix.EndsWith('/') -and -not $prefix.EndsWith('\')) {
|
|
94
|
+
$prefix = $prefix + '/'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Build the glob path—when the prefix contains wildcard
|
|
98
|
+
# characters, use it as-is; otherwise append *
|
|
99
|
+
$globPath = if ($prefix -match '[*?]') { $prefix } else { "${prefix}*" }
|
|
100
|
+
|
|
101
|
+
# Get file system items based on type
|
|
102
|
+
$items = @()
|
|
103
|
+
switch ($type) {
|
|
104
|
+
'file' {
|
|
105
|
+
if ($extensions) {
|
|
106
|
+
# Filter by extensions, always include directories
|
|
107
|
+
$extList = ($extensions -split ',') -replace '^\.',''
|
|
108
|
+
$items = Get-ChildItem @forceParam -Path $globPath -ErrorAction SilentlyContinue |
|
|
109
|
+
Where-Object {
|
|
110
|
+
$_.PSIsContainer -or (($_.Extension -replace '^\.','' ) -in $extList)
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
$items = Get-ChildItem @forceParam -Path $globPath -ErrorAction SilentlyContinue
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
'directory' {
|
|
117
|
+
$items = Get-ChildItem @forceParam -Directory -Path $globPath -ErrorAction SilentlyContinue
|
|
118
|
+
}
|
|
119
|
+
'any' {
|
|
120
|
+
if ($extensions) {
|
|
121
|
+
# Filter by extensions, always include directories
|
|
122
|
+
$extList = ($extensions -split ',') -replace '^\.',''
|
|
123
|
+
$items = Get-ChildItem @forceParam -Path $globPath -ErrorAction SilentlyContinue |
|
|
124
|
+
Where-Object {
|
|
125
|
+
$_.PSIsContainer -or (($_.Extension -replace '^\.','' ) -in $extList)
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
$items = Get-ChildItem @forceParam -Path $globPath -ErrorAction SilentlyContinue
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
# For file/any modes with glob patterns, also add directories
|
|
134
|
+
# from the base directory for navigation
|
|
135
|
+
if ($prefix -match '[*?]' -and $type -ne 'directory') {
|
|
136
|
+
$globDir = Split-Path -Parent $prefix
|
|
137
|
+
if (-not $globDir) { $globDir = '.' }
|
|
138
|
+
$extraDirs = Get-ChildItem @forceParam -Directory -Path "$globDir/*" -ErrorAction SilentlyContinue
|
|
139
|
+
if ($extraDirs) { $items = @($items) + @($extraDirs) | Select-Object -Unique }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
# Filter hidden files unless requested or the prefix targets dotfiles
|
|
143
|
+
if (-not $hidden -and -not ($prefixBasename -and $prefixBasename.StartsWith('.'))) {
|
|
144
|
+
$items = $items | Where-Object { -not $_.Attributes.HasFlag([System.IO.FileAttributes]::Hidden) }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Extract directory prefix to preserve in completion text
|
|
148
|
+
$dirPrefix = if ($prefix -and ($prefix.Contains('/') -or $prefix.Contains('\'))) {
|
|
149
|
+
$slashIdx = [Math]::Max($prefix.LastIndexOf('/'), $prefix.LastIndexOf('\'))
|
|
150
|
+
$prefix.Substring(0, $slashIdx + 1)
|
|
151
|
+
} else { '' }
|
|
152
|
+
|
|
153
|
+
# Create completion results for files
|
|
154
|
+
$items | ForEach-Object {
|
|
155
|
+
$completionText = if ($_.PSIsContainer) { "$dirPrefix$($_.Name)/" } else { "$dirPrefix$($_.Name)" }
|
|
156
|
+
$itemType = if ($_.PSIsContainer) { 'Directory' } else { 'File' }
|
|
157
|
+
[System.Management.Automation.CompletionResult]::new(
|
|
158
|
+
$completionText,
|
|
159
|
+
$completionText,
|
|
160
|
+
'ParameterValue',
|
|
161
|
+
$itemType
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
# Parse literal completion: text\tlistItemText\tdescription
|
|
166
|
+
$parts = $line -split "`t", 3
|
|
167
|
+
$completionText = $parts[0]
|
|
168
|
+
$listItemText = if ($parts.Length -gt 1 -and $parts[1]) { $parts[1] } else { $completionText }
|
|
169
|
+
$toolTip = if ($parts.Length -gt 2 -and $parts[2]) { $parts[2] } else { $completionText }
|
|
170
|
+
|
|
171
|
+
[System.Management.Automation.CompletionResult]::new(
|
|
172
|
+
$completionText,
|
|
173
|
+
$listItemText,
|
|
174
|
+
'ParameterValue',
|
|
175
|
+
$toolTip
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} catch {
|
|
180
|
+
# Silently ignore errors
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|