@drfed/drfed 0.0.0-stage → 0.1.0-dev.0
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-7FOUqcPO.mjs +6 -0
- package/dist/package-7FOUqcPO.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 +275 -3
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
|
|
2
|
+
# Helper to split args respecting quotes and whitespace
|
|
3
|
+
def args-split []: string -> list<string> {
|
|
4
|
+
let STATE_NORMAL = 0
|
|
5
|
+
let STATE_IN_SINGLE_QUOTE = 1
|
|
6
|
+
let STATE_IN_DOUBLE_QUOTE = 2
|
|
7
|
+
let STATE_ESCAPE = 3
|
|
8
|
+
let WHITESPACES = [" " "\t" "\n" "\r"]
|
|
9
|
+
|
|
10
|
+
mut state = $STATE_NORMAL
|
|
11
|
+
mut current_token = ""
|
|
12
|
+
mut result: list<string> = []
|
|
13
|
+
mut prev_state = $STATE_NORMAL
|
|
14
|
+
|
|
15
|
+
for char in ($in | split chars) {
|
|
16
|
+
if $state == $STATE_ESCAPE {
|
|
17
|
+
$current_token = $current_token + $char
|
|
18
|
+
$state = $prev_state
|
|
19
|
+
} else if $char == '\\' {
|
|
20
|
+
$prev_state = $state
|
|
21
|
+
$state = $STATE_ESCAPE
|
|
22
|
+
} else if $state == $STATE_NORMAL {
|
|
23
|
+
if $char == "'" {
|
|
24
|
+
$state = $STATE_IN_SINGLE_QUOTE
|
|
25
|
+
} else if $char == '"' {
|
|
26
|
+
$state = $STATE_IN_DOUBLE_QUOTE
|
|
27
|
+
} else if ($char in $WHITESPACES) {
|
|
28
|
+
if ($current_token | is-not-empty) {
|
|
29
|
+
$result = $result | append $current_token
|
|
30
|
+
$current_token = ""
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
$current_token = $current_token + $char
|
|
34
|
+
}
|
|
35
|
+
} else if $state == $STATE_IN_SINGLE_QUOTE {
|
|
36
|
+
if $char == "'" {
|
|
37
|
+
$state = $STATE_NORMAL
|
|
38
|
+
} else {
|
|
39
|
+
$current_token = $current_token + $char
|
|
40
|
+
}
|
|
41
|
+
} else if $state == $STATE_IN_DOUBLE_QUOTE {
|
|
42
|
+
if $char == '"' {
|
|
43
|
+
$state = $STATE_NORMAL
|
|
44
|
+
} else {
|
|
45
|
+
$current_token = $current_token + $char
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if ($current_token | is-not-empty) {
|
|
50
|
+
$result = $result | append $current_token
|
|
51
|
+
}
|
|
52
|
+
$result
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Completion command that calls back to the CLI
|
|
56
|
+
export def "nu-complete-drfed-account" [context: string] {
|
|
57
|
+
# Split context into tokens, handling quotes properly
|
|
58
|
+
let tokens = $context | args-split
|
|
59
|
+
|
|
60
|
+
# Remove the command name (first token) to get arguments
|
|
61
|
+
let args = if ($tokens | length) > 1 {
|
|
62
|
+
$tokens | skip 1
|
|
63
|
+
} else {
|
|
64
|
+
[]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# If context ends with whitespace, add empty string to represent the new argument
|
|
68
|
+
let args_with_empty = if ($context | str ends-with ' ') {
|
|
69
|
+
$args | append ''
|
|
70
|
+
} else {
|
|
71
|
+
$args
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Ensure at least one argument (empty string) to get completions not script
|
|
75
|
+
let final_args = if ($args_with_empty | is-empty) {
|
|
76
|
+
['']
|
|
77
|
+
} else {
|
|
78
|
+
$args_with_empty
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let output = try {
|
|
82
|
+
^drfed-account 'completion' 'nu' ...$final_args | complete | get stdout
|
|
83
|
+
} catch {
|
|
84
|
+
""
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
# Process each line of output
|
|
88
|
+
$output | lines | each {|line|
|
|
89
|
+
if ($line | str starts-with '__FILE__:') {
|
|
90
|
+
# Parse file completion directive: __FILE__:type:extensions:pattern:hidden
|
|
91
|
+
let directive = ($line | split row " " | first)
|
|
92
|
+
let parts = ($directive | split row ':')
|
|
93
|
+
let type = ($parts | get 1)
|
|
94
|
+
let extensions = ($parts | get 2)
|
|
95
|
+
let pattern = ($parts | get 3 | str replace -a '%3A' ':' | str replace -a '%25' '%')
|
|
96
|
+
let hidden = ($parts | get 4) == '1'
|
|
97
|
+
|
|
98
|
+
# Extract prefix from the last argument if it exists
|
|
99
|
+
let prefix = if ($final_args | length) > 0 {
|
|
100
|
+
$final_args | last
|
|
101
|
+
} else {
|
|
102
|
+
""
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
# When a pattern is specified, use it as the glob base instead of
|
|
106
|
+
# the user-typed prefix. If the user has already typed beyond the
|
|
107
|
+
# pattern (e.g., pattern="src/" and prefix="src/ma"), keep the
|
|
108
|
+
# prefix for incremental narrowing. Normalize path separators
|
|
109
|
+
# before comparing so that Windows backslashes match forward slashes
|
|
110
|
+
# in the transported pattern.
|
|
111
|
+
let glob_base = if ($pattern | is-not-empty) {
|
|
112
|
+
# Normalize separators and leading ./; downcase only on Windows
|
|
113
|
+
# where filesystems are typically case-insensitive
|
|
114
|
+
let norm_prefix_raw = ($prefix | str replace -a '\' '/' | str replace -r '^\./' '')
|
|
115
|
+
let norm_pattern_raw = ($pattern | str replace -a '\' '/' | str replace -r '^\./' '')
|
|
116
|
+
let is_win = (($nu.os-info.name | str downcase) == "windows")
|
|
117
|
+
let norm_prefix = (if $is_win { $norm_prefix_raw | str downcase } else { $norm_prefix_raw })
|
|
118
|
+
let norm_pattern = (if $is_win { $norm_pattern_raw | str downcase } else { $norm_pattern_raw })
|
|
119
|
+
# For wildcard patterns, compare only the directory prefix
|
|
120
|
+
let compare_pattern = if ($norm_pattern =~ '[*?]') {
|
|
121
|
+
let before_wild = ($norm_pattern | str replace -r '[*?].*' '')
|
|
122
|
+
if ($before_wild =~ '/') { $before_wild | str replace -r '/[^/]*$' '/' } else { "" }
|
|
123
|
+
} else {
|
|
124
|
+
$norm_pattern
|
|
125
|
+
}
|
|
126
|
+
if (($compare_pattern | is-not-empty) or ($norm_prefix | is-not-empty)) and ($norm_prefix | str starts-with $compare_pattern) and (($norm_prefix | str length) >= ($compare_pattern | str length)) and ($prefix != $pattern) {
|
|
127
|
+
$prefix
|
|
128
|
+
} else {
|
|
129
|
+
$pattern
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
$prefix
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
# If the glob base is a directory without a trailing slash (e.g., "src"),
|
|
136
|
+
# append one so that ls enumerates its contents instead of matching
|
|
137
|
+
# siblings like "src-old"
|
|
138
|
+
let glob_base = if ($glob_base | is-not-empty) and ($glob_base | path type) == "dir" and (not ($glob_base | str ends-with "/")) {
|
|
139
|
+
$glob_base + "/"
|
|
140
|
+
} else {
|
|
141
|
+
$glob_base
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
# Generate file completions based on type.
|
|
145
|
+
# When the glob base contains wildcard characters, use it as-is;
|
|
146
|
+
# otherwise append * to treat it as a prefix.
|
|
147
|
+
# Note: into glob is required so that ls expands wildcards from a variable
|
|
148
|
+
let has_glob = ($glob_base =~ '[*?]')
|
|
149
|
+
let ls_pattern = if ($glob_base | is-empty) {
|
|
150
|
+
"."
|
|
151
|
+
} else if $has_glob {
|
|
152
|
+
($glob_base | into glob)
|
|
153
|
+
} else {
|
|
154
|
+
($glob_base + "*" | into glob)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
# When using a glob pattern, also compute a directory listing pattern
|
|
158
|
+
# so that file/any modes can include directories for navigation
|
|
159
|
+
let glob_dir_pattern = if $has_glob {
|
|
160
|
+
let dir_part = ($glob_base | path dirname)
|
|
161
|
+
let dir = if ($dir_part | is-empty) or ($dir_part == $glob_base) { "." } else { $dir_part }
|
|
162
|
+
($dir + "/*" | into glob)
|
|
163
|
+
} else {
|
|
164
|
+
null
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
# Use ls -a to include hidden files when requested
|
|
168
|
+
let items = try {
|
|
169
|
+
match $type {
|
|
170
|
+
"file" => {
|
|
171
|
+
if ($extensions | is-empty) {
|
|
172
|
+
(if $hidden { ls -a $ls_pattern } else { ls $ls_pattern }) | where type == file or type == dir
|
|
173
|
+
} else {
|
|
174
|
+
let ext_list = ($extensions | split row ',' | each {|e| $e | str replace -r '^\.' '' })
|
|
175
|
+
let all_items = (if $hidden { ls -a $ls_pattern } else { ls $ls_pattern })
|
|
176
|
+
let dirs = $all_items | where type == dir
|
|
177
|
+
let files = $all_items | where type == file | where {|f|
|
|
178
|
+
let ext = ($f.name | path parse | get extension)
|
|
179
|
+
$ext in $ext_list
|
|
180
|
+
}
|
|
181
|
+
$dirs | append $files
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
"directory" => {
|
|
185
|
+
(if $hidden { ls -a $ls_pattern } else { ls $ls_pattern }) | where type == dir
|
|
186
|
+
},
|
|
187
|
+
"any" => {
|
|
188
|
+
if ($extensions | is-empty) {
|
|
189
|
+
if $hidden { ls -a $ls_pattern } else { ls $ls_pattern }
|
|
190
|
+
} else {
|
|
191
|
+
let ext_list = ($extensions | split row ',' | each {|e| $e | str replace -r '^\.' '' })
|
|
192
|
+
let all_items = (if $hidden { ls -a $ls_pattern } else { ls $ls_pattern })
|
|
193
|
+
let dirs = $all_items | where type == dir
|
|
194
|
+
let files = $all_items | where type == file | where {|f|
|
|
195
|
+
let ext = ($f.name | path parse | get extension)
|
|
196
|
+
$ext in $ext_list
|
|
197
|
+
}
|
|
198
|
+
$dirs | append $files
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} catch {
|
|
203
|
+
[]
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
# When using a glob pattern, also add directories from the base
|
|
207
|
+
# directory for navigation (file/any modes should list directories
|
|
208
|
+
# even when the glob itself does not match directory names)
|
|
209
|
+
let items = if ($glob_dir_pattern != null) and ($type != "directory") {
|
|
210
|
+
let extra_dirs = try {
|
|
211
|
+
(if $hidden { ls -a $glob_dir_pattern } else { ls $glob_dir_pattern }) | where type == dir
|
|
212
|
+
} catch {
|
|
213
|
+
[]
|
|
214
|
+
}
|
|
215
|
+
$items | append $extra_dirs | uniq-by name
|
|
216
|
+
} else {
|
|
217
|
+
$items
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
# Filter out hidden files unless requested.
|
|
221
|
+
# Check the basename of glob_base so that patterns like "src/.e"
|
|
222
|
+
# correctly target hidden entries.
|
|
223
|
+
let glob_basename = ($glob_base | path basename)
|
|
224
|
+
let filtered = if $hidden or ($glob_basename | str starts-with '.') {
|
|
225
|
+
$items
|
|
226
|
+
} else {
|
|
227
|
+
$items | where {|item|
|
|
228
|
+
let basename = ($item.name | path basename)
|
|
229
|
+
not ($basename | str starts-with '.')
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
# Extract directory prefix to preserve in completion text
|
|
234
|
+
let dir_prefix = if ($glob_base | is-empty) {
|
|
235
|
+
""
|
|
236
|
+
} else if ($glob_base | str ends-with "/") {
|
|
237
|
+
$glob_base
|
|
238
|
+
} else {
|
|
239
|
+
let parsed = ($glob_base | path parse)
|
|
240
|
+
if ($parsed.parent | is-empty) { "" } else if ($parsed.parent | str ends-with "/") { $parsed.parent } else { $parsed.parent + "/" }
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
# Format file completions
|
|
244
|
+
$filtered | each {|item|
|
|
245
|
+
let name = if $item.type == dir {
|
|
246
|
+
$dir_prefix + ($item.name | path basename) + "/"
|
|
247
|
+
} else {
|
|
248
|
+
$dir_prefix + ($item.name | path basename)
|
|
249
|
+
}
|
|
250
|
+
{ value: $name }
|
|
251
|
+
}
|
|
252
|
+
} else {
|
|
253
|
+
# Regular literal completion - split by tab
|
|
254
|
+
let parts = ($line | split row " ")
|
|
255
|
+
if ($parts | length) >= 2 {
|
|
256
|
+
# value\tdescription format
|
|
257
|
+
{ value: ($parts | get 0), description: ($parts | get 1) }
|
|
258
|
+
} else if ($parts | length) == 1 and ($parts | get 0 | is-not-empty) {
|
|
259
|
+
# Just value
|
|
260
|
+
{ value: ($parts | get 0) }
|
|
261
|
+
} else {
|
|
262
|
+
null
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
} | flatten | compact
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
# Custom completer for external commands
|
|
269
|
+
# This function will be called by Nushell's completion system
|
|
270
|
+
def --env "nu-complete-drfed-account-external" [] {
|
|
271
|
+
let existing_completer = $env.config.completions.external.completer
|
|
272
|
+
|
|
273
|
+
$env.config.completions.external.completer = {|spans|
|
|
274
|
+
# Check if this is for our program
|
|
275
|
+
if ($spans.0 == "drfed-account") {
|
|
276
|
+
# Build context string from spans
|
|
277
|
+
let context = $spans | str join ' '
|
|
278
|
+
nu-complete-drfed-account $context
|
|
279
|
+
} else if ($existing_completer != null) {
|
|
280
|
+
# Delegate to existing completer
|
|
281
|
+
do $existing_completer $spans
|
|
282
|
+
} else {
|
|
283
|
+
# No completions
|
|
284
|
+
null
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
$env.config.completions.external.enable = true
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
# Auto-setup: register the completer when this module is imported
|
|
292
|
+
nu-complete-drfed-account-external
|
|
293
|
+
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
|
|
2
|
+
# Helper to split args respecting quotes and whitespace
|
|
3
|
+
def args-split []: string -> list<string> {
|
|
4
|
+
let STATE_NORMAL = 0
|
|
5
|
+
let STATE_IN_SINGLE_QUOTE = 1
|
|
6
|
+
let STATE_IN_DOUBLE_QUOTE = 2
|
|
7
|
+
let STATE_ESCAPE = 3
|
|
8
|
+
let WHITESPACES = [" " "\t" "\n" "\r"]
|
|
9
|
+
|
|
10
|
+
mut state = $STATE_NORMAL
|
|
11
|
+
mut current_token = ""
|
|
12
|
+
mut result: list<string> = []
|
|
13
|
+
mut prev_state = $STATE_NORMAL
|
|
14
|
+
|
|
15
|
+
for char in ($in | split chars) {
|
|
16
|
+
if $state == $STATE_ESCAPE {
|
|
17
|
+
$current_token = $current_token + $char
|
|
18
|
+
$state = $prev_state
|
|
19
|
+
} else if $char == '\\' {
|
|
20
|
+
$prev_state = $state
|
|
21
|
+
$state = $STATE_ESCAPE
|
|
22
|
+
} else if $state == $STATE_NORMAL {
|
|
23
|
+
if $char == "'" {
|
|
24
|
+
$state = $STATE_IN_SINGLE_QUOTE
|
|
25
|
+
} else if $char == '"' {
|
|
26
|
+
$state = $STATE_IN_DOUBLE_QUOTE
|
|
27
|
+
} else if ($char in $WHITESPACES) {
|
|
28
|
+
if ($current_token | is-not-empty) {
|
|
29
|
+
$result = $result | append $current_token
|
|
30
|
+
$current_token = ""
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
$current_token = $current_token + $char
|
|
34
|
+
}
|
|
35
|
+
} else if $state == $STATE_IN_SINGLE_QUOTE {
|
|
36
|
+
if $char == "'" {
|
|
37
|
+
$state = $STATE_NORMAL
|
|
38
|
+
} else {
|
|
39
|
+
$current_token = $current_token + $char
|
|
40
|
+
}
|
|
41
|
+
} else if $state == $STATE_IN_DOUBLE_QUOTE {
|
|
42
|
+
if $char == '"' {
|
|
43
|
+
$state = $STATE_NORMAL
|
|
44
|
+
} else {
|
|
45
|
+
$current_token = $current_token + $char
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if ($current_token | is-not-empty) {
|
|
50
|
+
$result = $result | append $current_token
|
|
51
|
+
}
|
|
52
|
+
$result
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# Completion command that calls back to the CLI
|
|
56
|
+
export def "nu-complete-drfed-migrate" [context: string] {
|
|
57
|
+
# Split context into tokens, handling quotes properly
|
|
58
|
+
let tokens = $context | args-split
|
|
59
|
+
|
|
60
|
+
# Remove the command name (first token) to get arguments
|
|
61
|
+
let args = if ($tokens | length) > 1 {
|
|
62
|
+
$tokens | skip 1
|
|
63
|
+
} else {
|
|
64
|
+
[]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# If context ends with whitespace, add empty string to represent the new argument
|
|
68
|
+
let args_with_empty = if ($context | str ends-with ' ') {
|
|
69
|
+
$args | append ''
|
|
70
|
+
} else {
|
|
71
|
+
$args
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Ensure at least one argument (empty string) to get completions not script
|
|
75
|
+
let final_args = if ($args_with_empty | is-empty) {
|
|
76
|
+
['']
|
|
77
|
+
} else {
|
|
78
|
+
$args_with_empty
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let output = try {
|
|
82
|
+
^drfed-migrate 'completion' 'nu' ...$final_args | complete | get stdout
|
|
83
|
+
} catch {
|
|
84
|
+
""
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
# Process each line of output
|
|
88
|
+
$output | lines | each {|line|
|
|
89
|
+
if ($line | str starts-with '__FILE__:') {
|
|
90
|
+
# Parse file completion directive: __FILE__:type:extensions:pattern:hidden
|
|
91
|
+
let directive = ($line | split row " " | first)
|
|
92
|
+
let parts = ($directive | split row ':')
|
|
93
|
+
let type = ($parts | get 1)
|
|
94
|
+
let extensions = ($parts | get 2)
|
|
95
|
+
let pattern = ($parts | get 3 | str replace -a '%3A' ':' | str replace -a '%25' '%')
|
|
96
|
+
let hidden = ($parts | get 4) == '1'
|
|
97
|
+
|
|
98
|
+
# Extract prefix from the last argument if it exists
|
|
99
|
+
let prefix = if ($final_args | length) > 0 {
|
|
100
|
+
$final_args | last
|
|
101
|
+
} else {
|
|
102
|
+
""
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
# When a pattern is specified, use it as the glob base instead of
|
|
106
|
+
# the user-typed prefix. If the user has already typed beyond the
|
|
107
|
+
# pattern (e.g., pattern="src/" and prefix="src/ma"), keep the
|
|
108
|
+
# prefix for incremental narrowing. Normalize path separators
|
|
109
|
+
# before comparing so that Windows backslashes match forward slashes
|
|
110
|
+
# in the transported pattern.
|
|
111
|
+
let glob_base = if ($pattern | is-not-empty) {
|
|
112
|
+
# Normalize separators and leading ./; downcase only on Windows
|
|
113
|
+
# where filesystems are typically case-insensitive
|
|
114
|
+
let norm_prefix_raw = ($prefix | str replace -a '\' '/' | str replace -r '^\./' '')
|
|
115
|
+
let norm_pattern_raw = ($pattern | str replace -a '\' '/' | str replace -r '^\./' '')
|
|
116
|
+
let is_win = (($nu.os-info.name | str downcase) == "windows")
|
|
117
|
+
let norm_prefix = (if $is_win { $norm_prefix_raw | str downcase } else { $norm_prefix_raw })
|
|
118
|
+
let norm_pattern = (if $is_win { $norm_pattern_raw | str downcase } else { $norm_pattern_raw })
|
|
119
|
+
# For wildcard patterns, compare only the directory prefix
|
|
120
|
+
let compare_pattern = if ($norm_pattern =~ '[*?]') {
|
|
121
|
+
let before_wild = ($norm_pattern | str replace -r '[*?].*' '')
|
|
122
|
+
if ($before_wild =~ '/') { $before_wild | str replace -r '/[^/]*$' '/' } else { "" }
|
|
123
|
+
} else {
|
|
124
|
+
$norm_pattern
|
|
125
|
+
}
|
|
126
|
+
if (($compare_pattern | is-not-empty) or ($norm_prefix | is-not-empty)) and ($norm_prefix | str starts-with $compare_pattern) and (($norm_prefix | str length) >= ($compare_pattern | str length)) and ($prefix != $pattern) {
|
|
127
|
+
$prefix
|
|
128
|
+
} else {
|
|
129
|
+
$pattern
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
$prefix
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
# If the glob base is a directory without a trailing slash (e.g., "src"),
|
|
136
|
+
# append one so that ls enumerates its contents instead of matching
|
|
137
|
+
# siblings like "src-old"
|
|
138
|
+
let glob_base = if ($glob_base | is-not-empty) and ($glob_base | path type) == "dir" and (not ($glob_base | str ends-with "/")) {
|
|
139
|
+
$glob_base + "/"
|
|
140
|
+
} else {
|
|
141
|
+
$glob_base
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
# Generate file completions based on type.
|
|
145
|
+
# When the glob base contains wildcard characters, use it as-is;
|
|
146
|
+
# otherwise append * to treat it as a prefix.
|
|
147
|
+
# Note: into glob is required so that ls expands wildcards from a variable
|
|
148
|
+
let has_glob = ($glob_base =~ '[*?]')
|
|
149
|
+
let ls_pattern = if ($glob_base | is-empty) {
|
|
150
|
+
"."
|
|
151
|
+
} else if $has_glob {
|
|
152
|
+
($glob_base | into glob)
|
|
153
|
+
} else {
|
|
154
|
+
($glob_base + "*" | into glob)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
# When using a glob pattern, also compute a directory listing pattern
|
|
158
|
+
# so that file/any modes can include directories for navigation
|
|
159
|
+
let glob_dir_pattern = if $has_glob {
|
|
160
|
+
let dir_part = ($glob_base | path dirname)
|
|
161
|
+
let dir = if ($dir_part | is-empty) or ($dir_part == $glob_base) { "." } else { $dir_part }
|
|
162
|
+
($dir + "/*" | into glob)
|
|
163
|
+
} else {
|
|
164
|
+
null
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
# Use ls -a to include hidden files when requested
|
|
168
|
+
let items = try {
|
|
169
|
+
match $type {
|
|
170
|
+
"file" => {
|
|
171
|
+
if ($extensions | is-empty) {
|
|
172
|
+
(if $hidden { ls -a $ls_pattern } else { ls $ls_pattern }) | where type == file or type == dir
|
|
173
|
+
} else {
|
|
174
|
+
let ext_list = ($extensions | split row ',' | each {|e| $e | str replace -r '^\.' '' })
|
|
175
|
+
let all_items = (if $hidden { ls -a $ls_pattern } else { ls $ls_pattern })
|
|
176
|
+
let dirs = $all_items | where type == dir
|
|
177
|
+
let files = $all_items | where type == file | where {|f|
|
|
178
|
+
let ext = ($f.name | path parse | get extension)
|
|
179
|
+
$ext in $ext_list
|
|
180
|
+
}
|
|
181
|
+
$dirs | append $files
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
"directory" => {
|
|
185
|
+
(if $hidden { ls -a $ls_pattern } else { ls $ls_pattern }) | where type == dir
|
|
186
|
+
},
|
|
187
|
+
"any" => {
|
|
188
|
+
if ($extensions | is-empty) {
|
|
189
|
+
if $hidden { ls -a $ls_pattern } else { ls $ls_pattern }
|
|
190
|
+
} else {
|
|
191
|
+
let ext_list = ($extensions | split row ',' | each {|e| $e | str replace -r '^\.' '' })
|
|
192
|
+
let all_items = (if $hidden { ls -a $ls_pattern } else { ls $ls_pattern })
|
|
193
|
+
let dirs = $all_items | where type == dir
|
|
194
|
+
let files = $all_items | where type == file | where {|f|
|
|
195
|
+
let ext = ($f.name | path parse | get extension)
|
|
196
|
+
$ext in $ext_list
|
|
197
|
+
}
|
|
198
|
+
$dirs | append $files
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} catch {
|
|
203
|
+
[]
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
# When using a glob pattern, also add directories from the base
|
|
207
|
+
# directory for navigation (file/any modes should list directories
|
|
208
|
+
# even when the glob itself does not match directory names)
|
|
209
|
+
let items = if ($glob_dir_pattern != null) and ($type != "directory") {
|
|
210
|
+
let extra_dirs = try {
|
|
211
|
+
(if $hidden { ls -a $glob_dir_pattern } else { ls $glob_dir_pattern }) | where type == dir
|
|
212
|
+
} catch {
|
|
213
|
+
[]
|
|
214
|
+
}
|
|
215
|
+
$items | append $extra_dirs | uniq-by name
|
|
216
|
+
} else {
|
|
217
|
+
$items
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
# Filter out hidden files unless requested.
|
|
221
|
+
# Check the basename of glob_base so that patterns like "src/.e"
|
|
222
|
+
# correctly target hidden entries.
|
|
223
|
+
let glob_basename = ($glob_base | path basename)
|
|
224
|
+
let filtered = if $hidden or ($glob_basename | str starts-with '.') {
|
|
225
|
+
$items
|
|
226
|
+
} else {
|
|
227
|
+
$items | where {|item|
|
|
228
|
+
let basename = ($item.name | path basename)
|
|
229
|
+
not ($basename | str starts-with '.')
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
# Extract directory prefix to preserve in completion text
|
|
234
|
+
let dir_prefix = if ($glob_base | is-empty) {
|
|
235
|
+
""
|
|
236
|
+
} else if ($glob_base | str ends-with "/") {
|
|
237
|
+
$glob_base
|
|
238
|
+
} else {
|
|
239
|
+
let parsed = ($glob_base | path parse)
|
|
240
|
+
if ($parsed.parent | is-empty) { "" } else if ($parsed.parent | str ends-with "/") { $parsed.parent } else { $parsed.parent + "/" }
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
# Format file completions
|
|
244
|
+
$filtered | each {|item|
|
|
245
|
+
let name = if $item.type == dir {
|
|
246
|
+
$dir_prefix + ($item.name | path basename) + "/"
|
|
247
|
+
} else {
|
|
248
|
+
$dir_prefix + ($item.name | path basename)
|
|
249
|
+
}
|
|
250
|
+
{ value: $name }
|
|
251
|
+
}
|
|
252
|
+
} else {
|
|
253
|
+
# Regular literal completion - split by tab
|
|
254
|
+
let parts = ($line | split row " ")
|
|
255
|
+
if ($parts | length) >= 2 {
|
|
256
|
+
# value\tdescription format
|
|
257
|
+
{ value: ($parts | get 0), description: ($parts | get 1) }
|
|
258
|
+
} else if ($parts | length) == 1 and ($parts | get 0 | is-not-empty) {
|
|
259
|
+
# Just value
|
|
260
|
+
{ value: ($parts | get 0) }
|
|
261
|
+
} else {
|
|
262
|
+
null
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
} | flatten | compact
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
# Custom completer for external commands
|
|
269
|
+
# This function will be called by Nushell's completion system
|
|
270
|
+
def --env "nu-complete-drfed-migrate-external" [] {
|
|
271
|
+
let existing_completer = $env.config.completions.external.completer
|
|
272
|
+
|
|
273
|
+
$env.config.completions.external.completer = {|spans|
|
|
274
|
+
# Check if this is for our program
|
|
275
|
+
if ($spans.0 == "drfed-migrate") {
|
|
276
|
+
# Build context string from spans
|
|
277
|
+
let context = $spans | str join ' '
|
|
278
|
+
nu-complete-drfed-migrate $context
|
|
279
|
+
} else if ($existing_completer != null) {
|
|
280
|
+
# Delegate to existing completer
|
|
281
|
+
do $existing_completer $spans
|
|
282
|
+
} else {
|
|
283
|
+
# No completions
|
|
284
|
+
null
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
$env.config.completions.external.enable = true
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
# Auto-setup: register the completer when this module is imported
|
|
292
|
+
nu-complete-drfed-migrate-external
|
|
293
|
+
|