@react-grab/cli 0.0.97 → 0.0.98
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/dist/cli.cjs +1143 -94
- package/dist/cli.js +1142 -94
- package/package.json +2 -1
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
|
+
import e from 'assert';
|
|
3
4
|
import pc from 'picocolors';
|
|
4
5
|
import prompts3 from 'prompts';
|
|
5
6
|
import { spawn, execSync } from 'child_process';
|
|
@@ -10,6 +11,1036 @@ import ora from 'ora';
|
|
|
10
11
|
import { createServer } from 'http';
|
|
11
12
|
import { createProxyMiddleware, responseInterceptor } from 'http-proxy-middleware';
|
|
12
13
|
|
|
14
|
+
function t(e3, t2) {
|
|
15
|
+
return `#compdef ${e3}
|
|
16
|
+
compdef _${e3} ${e3}
|
|
17
|
+
|
|
18
|
+
# zsh completion for ${e3} -*- shell-script -*-
|
|
19
|
+
|
|
20
|
+
__${e3}_debug() {
|
|
21
|
+
local file="$BASH_COMP_DEBUG_FILE"
|
|
22
|
+
if [[ -n \${file} ]]; then
|
|
23
|
+
echo "$*" >> "\${file}"
|
|
24
|
+
fi
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_${e3}() {
|
|
28
|
+
local shellCompDirectiveError=${a.ShellCompDirectiveError}
|
|
29
|
+
local shellCompDirectiveNoSpace=${a.ShellCompDirectiveNoSpace}
|
|
30
|
+
local shellCompDirectiveNoFileComp=${a.ShellCompDirectiveNoFileComp}
|
|
31
|
+
local shellCompDirectiveFilterFileExt=${a.ShellCompDirectiveFilterFileExt}
|
|
32
|
+
local shellCompDirectiveFilterDirs=${a.ShellCompDirectiveFilterDirs}
|
|
33
|
+
local shellCompDirectiveKeepOrder=${a.ShellCompDirectiveKeepOrder}
|
|
34
|
+
|
|
35
|
+
local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder
|
|
36
|
+
local -a completions
|
|
37
|
+
|
|
38
|
+
__${e3}_debug "\\n========= starting completion logic =========="
|
|
39
|
+
__${e3}_debug "CURRENT: \${CURRENT}, words[*]: \${words[*]}"
|
|
40
|
+
|
|
41
|
+
# The user could have moved the cursor backwards on the command-line.
|
|
42
|
+
# We need to trigger completion from the $CURRENT location, so we need
|
|
43
|
+
# to truncate the command-line ($words) up to the $CURRENT location.
|
|
44
|
+
# (We cannot use $CURSOR as its value does not work when a command is an alias.)
|
|
45
|
+
words=( "\${=words[1,CURRENT]}" )
|
|
46
|
+
__${e3}_debug "Truncated words[*]: \${words[*]},"
|
|
47
|
+
|
|
48
|
+
lastParam=\${words[-1]}
|
|
49
|
+
lastChar=\${lastParam[-1]}
|
|
50
|
+
__${e3}_debug "lastParam: \${lastParam}, lastChar: \${lastChar}"
|
|
51
|
+
|
|
52
|
+
# For zsh, when completing a flag with an = (e.g., ${e3} -n=<TAB>)
|
|
53
|
+
# completions must be prefixed with the flag
|
|
54
|
+
setopt local_options BASH_REMATCH
|
|
55
|
+
if [[ "\${lastParam}" =~ '-.*=' ]]; then
|
|
56
|
+
# We are dealing with a flag with an =
|
|
57
|
+
flagPrefix="-P \${BASH_REMATCH}"
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
|
+
# Prepare the command to obtain completions, ensuring arguments are quoted for eval
|
|
61
|
+
local -a args_to_quote=("\${(@)words[2,-1]}")
|
|
62
|
+
if [ "\${lastChar}" = "" ]; then
|
|
63
|
+
# If the last parameter is complete (there is a space following it)
|
|
64
|
+
# We add an extra empty parameter so we can indicate this to the go completion code.
|
|
65
|
+
__${e3}_debug "Adding extra empty parameter"
|
|
66
|
+
args_to_quote+=("")
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
# Use Zsh's (q) flag to quote each argument safely for eval
|
|
70
|
+
local quoted_args=("\${(@q)args_to_quote}")
|
|
71
|
+
|
|
72
|
+
# Join the main command and the quoted arguments into a single string for eval
|
|
73
|
+
requestComp="${t2} complete -- \${quoted_args[*]}"
|
|
74
|
+
|
|
75
|
+
__${e3}_debug "About to call: eval \${requestComp}"
|
|
76
|
+
|
|
77
|
+
# Use eval to handle any environment variables and such
|
|
78
|
+
out=$(eval \${requestComp} 2>/dev/null)
|
|
79
|
+
__${e3}_debug "completion output: \${out}"
|
|
80
|
+
|
|
81
|
+
# Extract the directive integer following a : from the last line
|
|
82
|
+
local lastLine
|
|
83
|
+
while IFS='
|
|
84
|
+
' read -r line; do
|
|
85
|
+
lastLine=\${line}
|
|
86
|
+
done < <(printf "%s
|
|
87
|
+
" "\${out[@]}")
|
|
88
|
+
__${e3}_debug "last line: \${lastLine}"
|
|
89
|
+
|
|
90
|
+
if [ "\${lastLine[1]}" = : ]; then
|
|
91
|
+
directive=\${lastLine[2,-1]}
|
|
92
|
+
# Remove the directive including the : and the newline
|
|
93
|
+
local suffix
|
|
94
|
+
(( suffix=\${#lastLine}+2))
|
|
95
|
+
out=\${out[1,-$suffix]}
|
|
96
|
+
else
|
|
97
|
+
# There is no directive specified. Leave $out as is.
|
|
98
|
+
__${e3}_debug "No directive found. Setting to default"
|
|
99
|
+
directive=0
|
|
100
|
+
fi
|
|
101
|
+
|
|
102
|
+
__${e3}_debug "directive: \${directive}"
|
|
103
|
+
__${e3}_debug "completions: \${out}"
|
|
104
|
+
__${e3}_debug "flagPrefix: \${flagPrefix}"
|
|
105
|
+
|
|
106
|
+
if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
|
|
107
|
+
__${e3}_debug "Completion received error. Ignoring completions."
|
|
108
|
+
return
|
|
109
|
+
fi
|
|
110
|
+
|
|
111
|
+
local activeHelpMarker="%"
|
|
112
|
+
local endIndex=\${#activeHelpMarker}
|
|
113
|
+
local startIndex=$((\${#activeHelpMarker}+1))
|
|
114
|
+
local hasActiveHelp=0
|
|
115
|
+
while IFS='
|
|
116
|
+
' read -r comp; do
|
|
117
|
+
# Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)
|
|
118
|
+
if [ "\${comp[1,$endIndex]}" = "$activeHelpMarker" ];then
|
|
119
|
+
__${e3}_debug "ActiveHelp found: $comp"
|
|
120
|
+
comp="\${comp[$startIndex,-1]}"
|
|
121
|
+
if [ -n "$comp" ]; then
|
|
122
|
+
compadd -x "\${comp}"
|
|
123
|
+
__${e3}_debug "ActiveHelp will need delimiter"
|
|
124
|
+
hasActiveHelp=1
|
|
125
|
+
fi
|
|
126
|
+
continue
|
|
127
|
+
fi
|
|
128
|
+
|
|
129
|
+
if [ -n "$comp" ]; then
|
|
130
|
+
# If requested, completions are returned with a description.
|
|
131
|
+
# The description is preceded by a TAB character.
|
|
132
|
+
# For zsh's _describe, we need to use a : instead of a TAB.
|
|
133
|
+
# We first need to escape any : as part of the completion itself.
|
|
134
|
+
comp=\${comp//:/\\:}
|
|
135
|
+
|
|
136
|
+
local tab="$(printf '\\t')"
|
|
137
|
+
comp=\${comp//$tab/:}
|
|
138
|
+
|
|
139
|
+
__${e3}_debug "Adding completion: \${comp}"
|
|
140
|
+
completions+=\${comp}
|
|
141
|
+
lastComp=$comp
|
|
142
|
+
fi
|
|
143
|
+
done < <(printf "%s
|
|
144
|
+
" "\${out[@]}")
|
|
145
|
+
|
|
146
|
+
# Add a delimiter after the activeHelp statements, but only if:
|
|
147
|
+
# - there are completions following the activeHelp statements, or
|
|
148
|
+
# - file completion will be performed (so there will be choices after the activeHelp)
|
|
149
|
+
if [ $hasActiveHelp -eq 1 ]; then
|
|
150
|
+
if [ \${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then
|
|
151
|
+
__${e3}_debug "Adding activeHelp delimiter"
|
|
152
|
+
compadd -x "--"
|
|
153
|
+
hasActiveHelp=0
|
|
154
|
+
fi
|
|
155
|
+
fi
|
|
156
|
+
|
|
157
|
+
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
|
|
158
|
+
__${e3}_debug "Activating nospace."
|
|
159
|
+
noSpace="-S ''"
|
|
160
|
+
fi
|
|
161
|
+
|
|
162
|
+
if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then
|
|
163
|
+
__${e3}_debug "Activating keep order."
|
|
164
|
+
keepOrder="-V"
|
|
165
|
+
fi
|
|
166
|
+
|
|
167
|
+
if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
|
|
168
|
+
# File extension filtering
|
|
169
|
+
local filteringCmd
|
|
170
|
+
filteringCmd='_files'
|
|
171
|
+
for filter in \${completions[@]}; do
|
|
172
|
+
if [ \${filter[1]} != '*' ]; then
|
|
173
|
+
# zsh requires a glob pattern to do file filtering
|
|
174
|
+
filter="\\*.$filter"
|
|
175
|
+
fi
|
|
176
|
+
filteringCmd+=" -g $filter"
|
|
177
|
+
done
|
|
178
|
+
filteringCmd+=" \${flagPrefix}"
|
|
179
|
+
|
|
180
|
+
__${e3}_debug "File filtering command: $filteringCmd"
|
|
181
|
+
_arguments '*:filename:'"$filteringCmd"
|
|
182
|
+
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
|
183
|
+
# File completion for directories only
|
|
184
|
+
local subdir
|
|
185
|
+
subdir="\${completions[1]}"
|
|
186
|
+
if [ -n "$subdir" ]; then
|
|
187
|
+
__${e3}_debug "Listing directories in $subdir"
|
|
188
|
+
pushd "\${subdir}" >/dev/null 2>&1
|
|
189
|
+
else
|
|
190
|
+
__${e3}_debug "Listing directories in ."
|
|
191
|
+
fi
|
|
192
|
+
|
|
193
|
+
local result
|
|
194
|
+
_arguments '*:dirname:_files -/'" \${flagPrefix}"
|
|
195
|
+
result=$?
|
|
196
|
+
if [ -n "$subdir" ]; then
|
|
197
|
+
popd >/dev/null 2>&1
|
|
198
|
+
fi
|
|
199
|
+
return $result
|
|
200
|
+
else
|
|
201
|
+
__${e3}_debug "Calling _describe"
|
|
202
|
+
if eval _describe $keepOrder "completions" completions -Q \${flagPrefix} \${noSpace}; then
|
|
203
|
+
__${e3}_debug "_describe found some completions"
|
|
204
|
+
|
|
205
|
+
# Return the success of having called _describe
|
|
206
|
+
return 0
|
|
207
|
+
else
|
|
208
|
+
__${e3}_debug "_describe did not find completions."
|
|
209
|
+
__${e3}_debug "Checking if we should do file completion."
|
|
210
|
+
if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
|
|
211
|
+
__${e3}_debug "deactivating file completion"
|
|
212
|
+
|
|
213
|
+
# Return 0 to indicate completion is finished and prevent zsh from
|
|
214
|
+
# trying other completion algorithms (which could cause hanging).
|
|
215
|
+
# We use NoFileComp directive to explicitly disable file completion.
|
|
216
|
+
return 0
|
|
217
|
+
else
|
|
218
|
+
# Perform file completion
|
|
219
|
+
__${e3}_debug "Activating file completion"
|
|
220
|
+
|
|
221
|
+
# We must return the result of this command, so it must be the
|
|
222
|
+
# last command, or else we must store its result to return it.
|
|
223
|
+
_arguments '*:filename:_files'" \${flagPrefix}"
|
|
224
|
+
fi
|
|
225
|
+
fi
|
|
226
|
+
fi
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
# don't run the completion function when being sourced or eval-ed
|
|
230
|
+
if [ "\${funcstack[1]}" = "_${e3}" ]; then
|
|
231
|
+
_${e3}
|
|
232
|
+
fi
|
|
233
|
+
`;
|
|
234
|
+
}
|
|
235
|
+
function n(e3, t2) {
|
|
236
|
+
let n2 = e3.replace(/[-:]/g, `_`);
|
|
237
|
+
return `# bash completion for ${e3}
|
|
238
|
+
|
|
239
|
+
# Define shell completion directives
|
|
240
|
+
readonly ShellCompDirectiveError=${a.ShellCompDirectiveError}
|
|
241
|
+
readonly ShellCompDirectiveNoSpace=${a.ShellCompDirectiveNoSpace}
|
|
242
|
+
readonly ShellCompDirectiveNoFileComp=${a.ShellCompDirectiveNoFileComp}
|
|
243
|
+
readonly ShellCompDirectiveFilterFileExt=${a.ShellCompDirectiveFilterFileExt}
|
|
244
|
+
readonly ShellCompDirectiveFilterDirs=${a.ShellCompDirectiveFilterDirs}
|
|
245
|
+
readonly ShellCompDirectiveKeepOrder=${a.ShellCompDirectiveKeepOrder}
|
|
246
|
+
|
|
247
|
+
# Function to debug completion
|
|
248
|
+
__${n2}_debug() {
|
|
249
|
+
if [[ -n \${BASH_COMP_DEBUG_FILE:-} ]]; then
|
|
250
|
+
echo "$*" >> "\${BASH_COMP_DEBUG_FILE}"
|
|
251
|
+
fi
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
# Function to handle completions
|
|
255
|
+
__${n2}_complete() {
|
|
256
|
+
local cur prev words cword
|
|
257
|
+
_get_comp_words_by_ref -n "=:" cur prev words cword
|
|
258
|
+
|
|
259
|
+
local requestComp out directive
|
|
260
|
+
|
|
261
|
+
# Build the command to get completions
|
|
262
|
+
requestComp="${t2} complete -- \${words[@]:1}"
|
|
263
|
+
|
|
264
|
+
# Add an empty parameter if the last parameter is complete
|
|
265
|
+
if [[ -z "$cur" ]]; then
|
|
266
|
+
requestComp="$requestComp ''"
|
|
267
|
+
fi
|
|
268
|
+
|
|
269
|
+
# Get completions from the program
|
|
270
|
+
out=$(eval "$requestComp" 2>/dev/null)
|
|
271
|
+
|
|
272
|
+
# Extract directive if present
|
|
273
|
+
directive=0
|
|
274
|
+
if [[ "$out" == *:* ]]; then
|
|
275
|
+
directive=\${out##*:}
|
|
276
|
+
out=\${out%:*}
|
|
277
|
+
fi
|
|
278
|
+
|
|
279
|
+
# Process completions based on directive
|
|
280
|
+
if [[ $((directive & $ShellCompDirectiveError)) -ne 0 ]]; then
|
|
281
|
+
# Error, no completion
|
|
282
|
+
return
|
|
283
|
+
fi
|
|
284
|
+
|
|
285
|
+
# Apply directives
|
|
286
|
+
if [[ $((directive & $ShellCompDirectiveNoSpace)) -ne 0 ]]; then
|
|
287
|
+
compopt -o nospace
|
|
288
|
+
fi
|
|
289
|
+
if [[ $((directive & $ShellCompDirectiveKeepOrder)) -ne 0 ]]; then
|
|
290
|
+
compopt -o nosort
|
|
291
|
+
fi
|
|
292
|
+
if [[ $((directive & $ShellCompDirectiveNoFileComp)) -ne 0 ]]; then
|
|
293
|
+
compopt +o default
|
|
294
|
+
fi
|
|
295
|
+
|
|
296
|
+
# Handle file extension filtering
|
|
297
|
+
if [[ $((directive & $ShellCompDirectiveFilterFileExt)) -ne 0 ]]; then
|
|
298
|
+
local filter=""
|
|
299
|
+
for ext in $out; do
|
|
300
|
+
filter="$filter|$ext"
|
|
301
|
+
done
|
|
302
|
+
filter="\\.($filter)"
|
|
303
|
+
compopt -o filenames
|
|
304
|
+
COMPREPLY=( $(compgen -f -X "!$filter" -- "$cur") )
|
|
305
|
+
return
|
|
306
|
+
fi
|
|
307
|
+
|
|
308
|
+
# Handle directory filtering
|
|
309
|
+
if [[ $((directive & $ShellCompDirectiveFilterDirs)) -ne 0 ]]; then
|
|
310
|
+
compopt -o dirnames
|
|
311
|
+
COMPREPLY=( $(compgen -d -- "$cur") )
|
|
312
|
+
return
|
|
313
|
+
fi
|
|
314
|
+
|
|
315
|
+
# Process completions
|
|
316
|
+
local IFS=$'\\n'
|
|
317
|
+
local tab=$(printf '\\t')
|
|
318
|
+
|
|
319
|
+
# Parse completions with descriptions
|
|
320
|
+
local completions=()
|
|
321
|
+
while read -r comp; do
|
|
322
|
+
if [[ "$comp" == *$tab* ]]; then
|
|
323
|
+
# Split completion and description
|
|
324
|
+
local value=\${comp%%$tab*}
|
|
325
|
+
local desc=\${comp#*$tab}
|
|
326
|
+
completions+=("$value")
|
|
327
|
+
else
|
|
328
|
+
completions+=("$comp")
|
|
329
|
+
fi
|
|
330
|
+
done <<< "$out"
|
|
331
|
+
|
|
332
|
+
# Return completions
|
|
333
|
+
COMPREPLY=( $(compgen -W "\${completions[*]}" -- "$cur") )
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
# Register completion function
|
|
337
|
+
complete -F __${n2}_complete ${e3}
|
|
338
|
+
`;
|
|
339
|
+
}
|
|
340
|
+
function r(e3, t2) {
|
|
341
|
+
let n2 = e3.replace(/[-:]/g, `_`);
|
|
342
|
+
return `# fish completion for ${e3} -*- shell-script -*-
|
|
343
|
+
|
|
344
|
+
# Define shell completion directives
|
|
345
|
+
set -l ShellCompDirectiveError ${a.ShellCompDirectiveError}
|
|
346
|
+
set -l ShellCompDirectiveNoSpace ${a.ShellCompDirectiveNoSpace}
|
|
347
|
+
set -l ShellCompDirectiveNoFileComp ${a.ShellCompDirectiveNoFileComp}
|
|
348
|
+
set -l ShellCompDirectiveFilterFileExt ${a.ShellCompDirectiveFilterFileExt}
|
|
349
|
+
set -l ShellCompDirectiveFilterDirs ${a.ShellCompDirectiveFilterDirs}
|
|
350
|
+
set -l ShellCompDirectiveKeepOrder ${a.ShellCompDirectiveKeepOrder}
|
|
351
|
+
|
|
352
|
+
function __${n2}_debug
|
|
353
|
+
set -l file "$BASH_COMP_DEBUG_FILE"
|
|
354
|
+
if test -n "$file"
|
|
355
|
+
echo "$argv" >> $file
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
function __${n2}_perform_completion
|
|
360
|
+
__${n2}_debug "Starting __${n2}_perform_completion"
|
|
361
|
+
|
|
362
|
+
# Extract all args except the completion flag
|
|
363
|
+
set -l args (string match -v -- "--completion=" (commandline -opc))
|
|
364
|
+
|
|
365
|
+
# Extract the current token being completed
|
|
366
|
+
set -l current_token (commandline -ct)
|
|
367
|
+
|
|
368
|
+
# Check if current token starts with a dash
|
|
369
|
+
set -l flag_prefix ""
|
|
370
|
+
if string match -q -- "-*" $current_token
|
|
371
|
+
set flag_prefix "--flag="
|
|
372
|
+
end
|
|
373
|
+
|
|
374
|
+
__${n2}_debug "Current token: $current_token"
|
|
375
|
+
__${n2}_debug "All args: $args"
|
|
376
|
+
|
|
377
|
+
# Call the completion program and get the results
|
|
378
|
+
set -l requestComp "${t2} complete -- $args"
|
|
379
|
+
__${n2}_debug "Calling $requestComp"
|
|
380
|
+
set -l results (eval $requestComp 2> /dev/null)
|
|
381
|
+
|
|
382
|
+
# Some programs may output extra empty lines after the directive.
|
|
383
|
+
# Let's ignore them or else it will break completion.
|
|
384
|
+
# Ref: https://github.com/spf13/cobra/issues/1279
|
|
385
|
+
for line in $results[-1..1]
|
|
386
|
+
if test (string sub -s 1 -l 1 -- $line) = ":"
|
|
387
|
+
# The directive
|
|
388
|
+
set -l directive (string sub -s 2 -- $line)
|
|
389
|
+
set -l directive_num (math $directive)
|
|
390
|
+
break
|
|
391
|
+
end
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
# No directive specified, use default
|
|
395
|
+
if not set -q directive_num
|
|
396
|
+
set directive_num 0
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
__${n2}_debug "Directive: $directive_num"
|
|
400
|
+
|
|
401
|
+
# Process completions based on directive
|
|
402
|
+
if test $directive_num -eq $ShellCompDirectiveError
|
|
403
|
+
# Error code. No completion.
|
|
404
|
+
__${n2}_debug "Received error directive: aborting."
|
|
405
|
+
return 1
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
# Filter out the directive (last line)
|
|
409
|
+
if test (count $results) -gt 0 -a (string sub -s 1 -l 1 -- $results[-1]) = ":"
|
|
410
|
+
set results $results[1..-2]
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
# No completions, let fish handle file completions unless forbidden
|
|
414
|
+
if test (count $results) -eq 0
|
|
415
|
+
if test $directive_num -ne $ShellCompDirectiveNoFileComp
|
|
416
|
+
__${n2}_debug "No completions, performing file completion"
|
|
417
|
+
return 1
|
|
418
|
+
end
|
|
419
|
+
__${n2}_debug "No completions, but file completion forbidden"
|
|
420
|
+
return 0
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
# Filter file extensions
|
|
424
|
+
if test $directive_num -eq $ShellCompDirectiveFilterFileExt
|
|
425
|
+
__${n2}_debug "File extension filtering"
|
|
426
|
+
set -l file_extensions
|
|
427
|
+
for item in $results
|
|
428
|
+
if test -n "$item" -a (string sub -s 1 -l 1 -- $item) != "-"
|
|
429
|
+
set -a file_extensions "*$item"
|
|
430
|
+
end
|
|
431
|
+
end
|
|
432
|
+
__${n2}_debug "File extensions: $file_extensions"
|
|
433
|
+
|
|
434
|
+
# Use the file extensions as completions
|
|
435
|
+
set -l completions
|
|
436
|
+
for ext in $file_extensions
|
|
437
|
+
# Get all files matching the extension
|
|
438
|
+
set -a completions (string replace -r '^.*/' '' -- $ext)
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
for item in $completions
|
|
442
|
+
echo -e "$item "
|
|
443
|
+
end
|
|
444
|
+
return 0
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
# Filter directories
|
|
448
|
+
if test $directive_num -eq $ShellCompDirectiveFilterDirs
|
|
449
|
+
__${n2}_debug "Directory filtering"
|
|
450
|
+
set -l dirs
|
|
451
|
+
for item in $results
|
|
452
|
+
if test -d "$item"
|
|
453
|
+
set -a dirs "$item/"
|
|
454
|
+
end
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
for item in $dirs
|
|
458
|
+
echo -e "$item "
|
|
459
|
+
end
|
|
460
|
+
return 0
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
# Process remaining completions
|
|
464
|
+
for item in $results
|
|
465
|
+
if test -n "$item"
|
|
466
|
+
# Check if the item has a description
|
|
467
|
+
if string match -q "* *" -- "$item"
|
|
468
|
+
set -l completion_parts (string split -- "$item")
|
|
469
|
+
set -l comp $completion_parts[1]
|
|
470
|
+
set -l desc $completion_parts[2]
|
|
471
|
+
|
|
472
|
+
# Add the completion and description
|
|
473
|
+
echo -e "$comp $desc"
|
|
474
|
+
else
|
|
475
|
+
# Add just the completion
|
|
476
|
+
echo -e "$item "
|
|
477
|
+
end
|
|
478
|
+
end
|
|
479
|
+
end
|
|
480
|
+
|
|
481
|
+
# If directive contains NoSpace, tell fish not to add a space after completion
|
|
482
|
+
if test (math "$directive_num & $ShellCompDirectiveNoSpace") -ne 0
|
|
483
|
+
return 2
|
|
484
|
+
end
|
|
485
|
+
|
|
486
|
+
return 0
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
# Set up the completion for the ${e3} command
|
|
490
|
+
complete -c ${e3} -f -a "(eval __${n2}_perform_completion)"
|
|
491
|
+
`;
|
|
492
|
+
}
|
|
493
|
+
function i(e3, t2) {
|
|
494
|
+
let n2 = e3.replace(/[-:]/g, `_`);
|
|
495
|
+
return `# powershell completion for ${e3} -*- shell-script -*-
|
|
496
|
+
|
|
497
|
+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
498
|
+
function __${e3}_debug {
|
|
499
|
+
if ($env:BASH_COMP_DEBUG_FILE) {
|
|
500
|
+
"$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE"
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
filter __${e3}_escapeStringWithSpecialChars {
|
|
505
|
+
$_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|"|\\||<|>|&','\`$&'
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
[scriptblock]$__${n2}CompleterBlock = {
|
|
509
|
+
param(
|
|
510
|
+
$WordToComplete,
|
|
511
|
+
$CommandAst,
|
|
512
|
+
$CursorPosition
|
|
513
|
+
)
|
|
514
|
+
|
|
515
|
+
# Get the current command line and convert into a string
|
|
516
|
+
$Command = $CommandAst.CommandElements
|
|
517
|
+
$Command = "$Command"
|
|
518
|
+
|
|
519
|
+
__${e3}_debug ""
|
|
520
|
+
__${e3}_debug "========= starting completion logic =========="
|
|
521
|
+
__${e3}_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
|
|
522
|
+
|
|
523
|
+
# The user could have moved the cursor backwards on the command-line.
|
|
524
|
+
# We need to trigger completion from the $CursorPosition location, so we need
|
|
525
|
+
# to truncate the command-line ($Command) up to the $CursorPosition location.
|
|
526
|
+
# Make sure the $Command is longer then the $CursorPosition before we truncate.
|
|
527
|
+
# This happens because the $Command does not include the last space.
|
|
528
|
+
if ($Command.Length -gt $CursorPosition) {
|
|
529
|
+
$Command = $Command.Substring(0, $CursorPosition)
|
|
530
|
+
}
|
|
531
|
+
__${e3}_debug "Truncated command: $Command"
|
|
532
|
+
|
|
533
|
+
$ShellCompDirectiveError=${a.ShellCompDirectiveError}
|
|
534
|
+
$ShellCompDirectiveNoSpace=${a.ShellCompDirectiveNoSpace}
|
|
535
|
+
$ShellCompDirectiveNoFileComp=${a.ShellCompDirectiveNoFileComp}
|
|
536
|
+
$ShellCompDirectiveFilterFileExt=${a.ShellCompDirectiveFilterFileExt}
|
|
537
|
+
$ShellCompDirectiveFilterDirs=${a.ShellCompDirectiveFilterDirs}
|
|
538
|
+
$ShellCompDirectiveKeepOrder=${a.ShellCompDirectiveKeepOrder}
|
|
539
|
+
|
|
540
|
+
# Prepare the command to request completions for the program.
|
|
541
|
+
# Split the command at the first space to separate the program and arguments.
|
|
542
|
+
$Program, $Arguments = $Command.Split(" ", 2)
|
|
543
|
+
|
|
544
|
+
$QuotedArgs = ($Arguments -split ' ' | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ' '
|
|
545
|
+
__${e3}_debug "QuotedArgs: $QuotedArgs"
|
|
546
|
+
|
|
547
|
+
$RequestComp = "& ${t2} complete '--' $QuotedArgs"
|
|
548
|
+
__${e3}_debug "RequestComp: $RequestComp"
|
|
549
|
+
|
|
550
|
+
# we cannot use $WordToComplete because it
|
|
551
|
+
# has the wrong values if the cursor was moved
|
|
552
|
+
# so use the last argument
|
|
553
|
+
if ($WordToComplete -ne "" ) {
|
|
554
|
+
$WordToComplete = $Arguments.Split(" ")[-1]
|
|
555
|
+
}
|
|
556
|
+
__${e3}_debug "New WordToComplete: $WordToComplete"
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
# Check for flag with equal sign
|
|
560
|
+
$IsEqualFlag = ($WordToComplete -Like "--*=*" )
|
|
561
|
+
if ( $IsEqualFlag ) {
|
|
562
|
+
__${e3}_debug "Completing equal sign flag"
|
|
563
|
+
# Remove the flag part
|
|
564
|
+
$Flag, $WordToComplete = $WordToComplete.Split("=", 2)
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if ( $WordToComplete -eq "" -And ( -Not $IsEqualFlag )) {
|
|
568
|
+
# If the last parameter is complete (there is a space following it)
|
|
569
|
+
# We add an extra empty parameter so we can indicate this to the go method.
|
|
570
|
+
__${e3}_debug "Adding extra empty parameter"
|
|
571
|
+
# PowerShell 7.2+ changed the way how the arguments are passed to executables,
|
|
572
|
+
# so for pre-7.2 or when Legacy argument passing is enabled we need to use
|
|
573
|
+
if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
|
|
574
|
+
($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or
|
|
575
|
+
(($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and
|
|
576
|
+
$PSNativeCommandArgumentPassing -eq 'Legacy')) {
|
|
577
|
+
$RequestComp="$RequestComp" + ' \`"\`"'
|
|
578
|
+
} else {
|
|
579
|
+
$RequestComp = "$RequestComp" + ' ""'
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
__${e3}_debug "Calling $RequestComp"
|
|
584
|
+
# First disable ActiveHelp which is not supported for Powershell
|
|
585
|
+
$env:ActiveHelp = 0
|
|
586
|
+
|
|
587
|
+
# call the command store the output in $out and redirect stderr and stdout to null
|
|
588
|
+
# $Out is an array contains each line per element
|
|
589
|
+
Invoke-Expression -OutVariable out "$RequestComp" 2>&1 | Out-Null
|
|
590
|
+
|
|
591
|
+
# get directive from last line
|
|
592
|
+
[int]$Directive = $Out[-1].TrimStart(':')
|
|
593
|
+
if ($Directive -eq "") {
|
|
594
|
+
# There is no directive specified
|
|
595
|
+
$Directive = 0
|
|
596
|
+
}
|
|
597
|
+
__${e3}_debug "The completion directive is: $Directive"
|
|
598
|
+
|
|
599
|
+
# remove directive (last element) from out
|
|
600
|
+
$Out = $Out | Where-Object { $_ -ne $Out[-1] }
|
|
601
|
+
__${e3}_debug "The completions are: $Out"
|
|
602
|
+
|
|
603
|
+
if (($Directive -band $ShellCompDirectiveError) -ne 0 ) {
|
|
604
|
+
# Error code. No completion.
|
|
605
|
+
__${e3}_debug "Received error from custom completion go code"
|
|
606
|
+
return
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
$Longest = 0
|
|
610
|
+
[Array]$Values = $Out | ForEach-Object {
|
|
611
|
+
# Split the output in name and description
|
|
612
|
+
$Name, $Description = $_.Split("\`t", 2)
|
|
613
|
+
__${e3}_debug "Name: $Name Description: $Description"
|
|
614
|
+
|
|
615
|
+
# Look for the longest completion so that we can format things nicely
|
|
616
|
+
if ($Longest -lt $Name.Length) {
|
|
617
|
+
$Longest = $Name.Length
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
# Set the description to a one space string if there is none set.
|
|
621
|
+
# This is needed because the CompletionResult does not accept an empty string as argument
|
|
622
|
+
if (-Not $Description) {
|
|
623
|
+
$Description = " "
|
|
624
|
+
}
|
|
625
|
+
@{ Name = "$Name"; Description = "$Description" }
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
$Space = " "
|
|
630
|
+
if (($Directive -band $ShellCompDirectiveNoSpace) -ne 0 ) {
|
|
631
|
+
# remove the space here
|
|
632
|
+
__${e3}_debug "ShellCompDirectiveNoSpace is called"
|
|
633
|
+
$Space = ""
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
if ((($Directive -band $ShellCompDirectiveFilterFileExt) -ne 0 ) -or
|
|
637
|
+
(($Directive -band $ShellCompDirectiveFilterDirs) -ne 0 )) {
|
|
638
|
+
__${e3}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
|
|
639
|
+
|
|
640
|
+
# return here to prevent the completion of the extensions
|
|
641
|
+
return
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
$Values = $Values | Where-Object {
|
|
645
|
+
# filter the result
|
|
646
|
+
$_.Name -like "$WordToComplete*"
|
|
647
|
+
|
|
648
|
+
# Join the flag back if we have an equal sign flag
|
|
649
|
+
if ( $IsEqualFlag ) {
|
|
650
|
+
__${e3}_debug "Join the equal sign flag back to the completion value"
|
|
651
|
+
$_.Name = $Flag + "=" + $_.Name
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
# we sort the values in ascending order by name if keep order isn't passed
|
|
656
|
+
if (($Directive -band $ShellCompDirectiveKeepOrder) -eq 0 ) {
|
|
657
|
+
$Values = $Values | Sort-Object -Property Name
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {
|
|
661
|
+
__${e3}_debug "ShellCompDirectiveNoFileComp is called"
|
|
662
|
+
|
|
663
|
+
if ($Values.Length -eq 0) {
|
|
664
|
+
# Just print an empty string here so the
|
|
665
|
+
# shell does not start to complete paths.
|
|
666
|
+
# We cannot use CompletionResult here because
|
|
667
|
+
# it does not accept an empty string as argument.
|
|
668
|
+
""
|
|
669
|
+
return
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
# Get the current mode
|
|
674
|
+
$Mode = (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Tab" }).Function
|
|
675
|
+
__${e3}_debug "Mode: $Mode"
|
|
676
|
+
|
|
677
|
+
$Values | ForEach-Object {
|
|
678
|
+
|
|
679
|
+
# store temporary because switch will overwrite $_
|
|
680
|
+
$comp = $_
|
|
681
|
+
|
|
682
|
+
# PowerShell supports three different completion modes
|
|
683
|
+
# - TabCompleteNext (default windows style - on each key press the next option is displayed)
|
|
684
|
+
# - Complete (works like bash)
|
|
685
|
+
# - MenuComplete (works like zsh)
|
|
686
|
+
# You set the mode with Set-PSReadLineKeyHandler -Key Tab -Function <mode>
|
|
687
|
+
|
|
688
|
+
# CompletionResult Arguments:
|
|
689
|
+
# 1) CompletionText text to be used as the auto completion result
|
|
690
|
+
# 2) ListItemText text to be displayed in the suggestion list
|
|
691
|
+
# 3) ResultType type of completion result
|
|
692
|
+
# 4) ToolTip text for the tooltip with details about the object
|
|
693
|
+
|
|
694
|
+
switch ($Mode) {
|
|
695
|
+
|
|
696
|
+
# bash like
|
|
697
|
+
"Complete" {
|
|
698
|
+
|
|
699
|
+
if ($Values.Length -eq 1) {
|
|
700
|
+
__${e3}_debug "Only one completion left"
|
|
701
|
+
|
|
702
|
+
# insert space after value
|
|
703
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${e3}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
704
|
+
|
|
705
|
+
} else {
|
|
706
|
+
# Add the proper number of spaces to align the descriptions
|
|
707
|
+
while($comp.Name.Length -lt $Longest) {
|
|
708
|
+
$comp.Name = $comp.Name + " "
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
# Check for empty description and only add parentheses if needed
|
|
712
|
+
if ($($comp.Description) -eq " " ) {
|
|
713
|
+
$Description = ""
|
|
714
|
+
} else {
|
|
715
|
+
$Description = " ($($comp.Description))"
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
[System.Management.Automation.CompletionResult]::new("$($comp.Name)$Description", "$($comp.Name)$Description", 'ParameterValue', "$($comp.Description)")
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
# zsh like
|
|
723
|
+
"MenuComplete" {
|
|
724
|
+
# insert space after value
|
|
725
|
+
# MenuComplete will automatically show the ToolTip of
|
|
726
|
+
# the highlighted value at the bottom of the suggestions.
|
|
727
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${e3}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
# TabCompleteNext and in case we get something unknown
|
|
731
|
+
Default {
|
|
732
|
+
# Like MenuComplete but we don't want to add a space here because
|
|
733
|
+
# the user need to press space anyway to get the completion.
|
|
734
|
+
# Description will not be shown because that's not possible with TabCompleteNext
|
|
735
|
+
[System.Management.Automation.CompletionResult]::new($($comp.Name | __${e3}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
Register-ArgumentCompleter -CommandName '${e3}' -ScriptBlock $__${n2}CompleterBlock
|
|
743
|
+
`;
|
|
744
|
+
}
|
|
745
|
+
var a = { ShellCompDirectiveError: 1, ShellCompDirectiveNoSpace: 2, ShellCompDirectiveNoFileComp: 4, ShellCompDirectiveFilterFileExt: 8, ShellCompDirectiveFilterDirs: 16, ShellCompDirectiveKeepOrder: 32, ShellCompDirectiveDefault: 0 };
|
|
746
|
+
var o = class {
|
|
747
|
+
name;
|
|
748
|
+
variadic;
|
|
749
|
+
command;
|
|
750
|
+
handler;
|
|
751
|
+
constructor(e3, t2, n2, r2 = false) {
|
|
752
|
+
this.command = e3, this.name = t2, this.handler = n2, this.variadic = r2;
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
var s = class {
|
|
756
|
+
value;
|
|
757
|
+
description;
|
|
758
|
+
command;
|
|
759
|
+
handler;
|
|
760
|
+
alias;
|
|
761
|
+
isBoolean;
|
|
762
|
+
constructor(e3, t2, n2, r2, i2, a2) {
|
|
763
|
+
this.command = e3, this.value = t2, this.description = n2, this.handler = r2, this.alias = i2, this.isBoolean = a2;
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
var c = class {
|
|
767
|
+
value;
|
|
768
|
+
description;
|
|
769
|
+
options = /* @__PURE__ */ new Map();
|
|
770
|
+
arguments = /* @__PURE__ */ new Map();
|
|
771
|
+
parent;
|
|
772
|
+
constructor(e3, t2) {
|
|
773
|
+
this.value = e3, this.description = t2;
|
|
774
|
+
}
|
|
775
|
+
option(e3, t2, n2, r2) {
|
|
776
|
+
let i2, a2, o3;
|
|
777
|
+
typeof n2 == `function` ? (i2 = n2, a2 = r2, o3 = false) : typeof n2 == `string` ? (i2 = void 0, a2 = n2, o3 = true) : (i2 = void 0, a2 = void 0, o3 = true);
|
|
778
|
+
let c3 = new s(this, e3, t2, i2, a2, o3);
|
|
779
|
+
return this.options.set(e3, c3), this;
|
|
780
|
+
}
|
|
781
|
+
argument(e3, t2, n2 = false) {
|
|
782
|
+
let r2 = new o(this, e3, t2, n2);
|
|
783
|
+
return this.arguments.set(e3, r2), this;
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
var l = class extends c {
|
|
787
|
+
commands = /* @__PURE__ */ new Map();
|
|
788
|
+
completions = [];
|
|
789
|
+
directive = a.ShellCompDirectiveDefault;
|
|
790
|
+
constructor() {
|
|
791
|
+
super(``, ``);
|
|
792
|
+
}
|
|
793
|
+
command(e3, t2) {
|
|
794
|
+
let n2 = new c(e3, t2);
|
|
795
|
+
return this.commands.set(e3, n2), n2;
|
|
796
|
+
}
|
|
797
|
+
stripOptions(e3) {
|
|
798
|
+
let t2 = [], n2 = 0;
|
|
799
|
+
for (; n2 < e3.length; ) {
|
|
800
|
+
let r2 = e3[n2];
|
|
801
|
+
if (r2.startsWith(`-`)) {
|
|
802
|
+
n2++;
|
|
803
|
+
let t3 = false, i2 = this.findOption(this, r2);
|
|
804
|
+
if (i2) t3 = i2.isBoolean ?? false;
|
|
805
|
+
else for (let [, e4] of this.commands) {
|
|
806
|
+
let n3 = this.findOption(e4, r2);
|
|
807
|
+
if (n3) {
|
|
808
|
+
t3 = n3.isBoolean ?? false;
|
|
809
|
+
break;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
!t3 && n2 < e3.length && !e3[n2].startsWith(`-`) && n2++;
|
|
813
|
+
} else t2.push(r2), n2++;
|
|
814
|
+
}
|
|
815
|
+
return t2;
|
|
816
|
+
}
|
|
817
|
+
matchCommand(e3) {
|
|
818
|
+
e3 = this.stripOptions(e3);
|
|
819
|
+
let t2 = [], n2 = [], r2 = null;
|
|
820
|
+
for (let i2 = 0; i2 < e3.length; i2++) {
|
|
821
|
+
let a2 = e3[i2];
|
|
822
|
+
t2.push(a2);
|
|
823
|
+
let o3 = this.commands.get(t2.join(` `));
|
|
824
|
+
if (o3) r2 = o3;
|
|
825
|
+
else {
|
|
826
|
+
n2 = e3.slice(i2, e3.length);
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
return [r2 || this, n2];
|
|
831
|
+
}
|
|
832
|
+
shouldCompleteFlags(e3, t2) {
|
|
833
|
+
if (t2.startsWith(`-`)) return true;
|
|
834
|
+
if (e3?.startsWith(`-`)) {
|
|
835
|
+
let t3 = this.findOption(this, e3);
|
|
836
|
+
if (!t3) {
|
|
837
|
+
for (let [, n2] of this.commands) if (t3 = this.findOption(n2, e3), t3) break;
|
|
838
|
+
}
|
|
839
|
+
return !(t3 && t3.isBoolean);
|
|
840
|
+
}
|
|
841
|
+
return false;
|
|
842
|
+
}
|
|
843
|
+
shouldCompleteCommands(e3) {
|
|
844
|
+
return !e3.startsWith(`-`);
|
|
845
|
+
}
|
|
846
|
+
handleFlagCompletion(e3, t2, n2, r2) {
|
|
847
|
+
let i2;
|
|
848
|
+
if (n2.includes(`=`)) {
|
|
849
|
+
let [e4] = n2.split(`=`);
|
|
850
|
+
i2 = e4;
|
|
851
|
+
} else if (r2?.startsWith(`-`)) {
|
|
852
|
+
let t3 = this.findOption(e3, r2);
|
|
853
|
+
t3 && !t3.isBoolean && (i2 = r2);
|
|
854
|
+
}
|
|
855
|
+
if (i2) {
|
|
856
|
+
let t3 = this.findOption(e3, i2);
|
|
857
|
+
if (t3?.handler) {
|
|
858
|
+
let n3 = [];
|
|
859
|
+
t3.handler.call(t3, (e4, t4) => n3.push({ value: e4, description: t4 }), e3.options), this.completions = n3;
|
|
860
|
+
}
|
|
861
|
+
return;
|
|
862
|
+
}
|
|
863
|
+
if (n2.startsWith(`-`)) {
|
|
864
|
+
let t3 = n2.startsWith(`-`) && !n2.startsWith(`--`), r3 = n2.replace(/^-+/, ``);
|
|
865
|
+
for (let [i3, a2] of e3.options) t3 && a2.alias && `-${a2.alias}`.startsWith(n2) ? this.completions.push({ value: `-${a2.alias}`, description: a2.description }) : !t3 && i3.startsWith(r3) && this.completions.push({ value: `--${i3}`, description: a2.description });
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
findOption(e3, t2) {
|
|
869
|
+
let n2 = e3.options.get(t2);
|
|
870
|
+
if (n2 || (n2 = e3.options.get(t2.replace(/^-+/, ``)), n2)) return n2;
|
|
871
|
+
for (let [n3, r2] of e3.options) if (r2.alias && `-${r2.alias}` === t2) return r2;
|
|
872
|
+
}
|
|
873
|
+
handleCommandCompletion(e3, t2) {
|
|
874
|
+
let n2 = this.stripOptions(e3);
|
|
875
|
+
for (let [e4, r2] of this.commands) {
|
|
876
|
+
if (e4 === ``) continue;
|
|
877
|
+
let i2 = e4.split(` `);
|
|
878
|
+
i2.slice(0, n2.length).every((e5, t3) => e5 === n2[t3]) && i2[n2.length]?.startsWith(t2) && this.completions.push({ value: i2[n2.length], description: r2.description });
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
handlePositionalCompletion(e3, t2) {
|
|
882
|
+
let n2 = e3.value.split(` `).length, r2 = Math.max(0, t2.length - n2), i2 = Array.from(e3.arguments.entries());
|
|
883
|
+
if (i2.length > 0) {
|
|
884
|
+
let t3;
|
|
885
|
+
if (r2 < i2.length) {
|
|
886
|
+
let [e4, n3] = i2[r2];
|
|
887
|
+
t3 = n3;
|
|
888
|
+
} else {
|
|
889
|
+
let e4 = i2[i2.length - 1][1];
|
|
890
|
+
e4.variadic && (t3 = e4);
|
|
891
|
+
}
|
|
892
|
+
if (t3 && t3.handler && typeof t3.handler == `function`) {
|
|
893
|
+
let n3 = [];
|
|
894
|
+
t3.handler.call(t3, (e4, t4) => n3.push({ value: e4, description: t4 }), e3.options), this.completions.push(...n3);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
complete(e3) {
|
|
899
|
+
this.directive = a.ShellCompDirectiveNoFileComp;
|
|
900
|
+
let t2 = /* @__PURE__ */ new Set();
|
|
901
|
+
this.completions.filter((e4) => t2.has(e4.value) ? false : (t2.add(e4.value), true)).filter((t3) => {
|
|
902
|
+
if (e3.includes(`=`)) {
|
|
903
|
+
let [, n2] = e3.split(`=`);
|
|
904
|
+
return t3.value.startsWith(n2);
|
|
905
|
+
}
|
|
906
|
+
return t3.value.startsWith(e3);
|
|
907
|
+
}).forEach((e4) => console.log(`${e4.value} ${e4.description ?? ``}`)), console.log(`:${this.directive}`);
|
|
908
|
+
}
|
|
909
|
+
parse(e3) {
|
|
910
|
+
this.completions = [];
|
|
911
|
+
let t2 = e3[e3.length - 1] === ``;
|
|
912
|
+
t2 && e3.pop();
|
|
913
|
+
let n2 = e3[e3.length - 1] || ``, r2 = e3.slice(0, -1);
|
|
914
|
+
t2 && (n2 !== `` && r2.push(n2), n2 = ``);
|
|
915
|
+
let [i2] = this.matchCommand(r2), a2 = r2[r2.length - 1];
|
|
916
|
+
if (this.shouldCompleteFlags(a2, n2)) this.handleFlagCompletion(i2, r2, n2, a2);
|
|
917
|
+
else {
|
|
918
|
+
if (a2?.startsWith(`-`) && n2 === `` && t2) {
|
|
919
|
+
let e4 = this.findOption(this, a2);
|
|
920
|
+
if (!e4) {
|
|
921
|
+
for (let [, t3] of this.commands) if (e4 = this.findOption(t3, a2), e4) break;
|
|
922
|
+
}
|
|
923
|
+
if (e4 && e4.isBoolean) {
|
|
924
|
+
this.complete(n2);
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
this.shouldCompleteCommands(n2) && this.handleCommandCompletion(r2, n2), i2 && i2.arguments.size > 0 && this.handlePositionalCompletion(i2, r2);
|
|
929
|
+
}
|
|
930
|
+
this.complete(n2);
|
|
931
|
+
}
|
|
932
|
+
setup(a2, o3, s3) {
|
|
933
|
+
switch (e(s3 === `zsh` || s3 === `bash` || s3 === `fish` || s3 === `powershell`, `Unsupported shell`), s3) {
|
|
934
|
+
case `zsh`: {
|
|
935
|
+
let e3 = t(a2, o3);
|
|
936
|
+
console.log(e3);
|
|
937
|
+
break;
|
|
938
|
+
}
|
|
939
|
+
case `bash`: {
|
|
940
|
+
let e3 = n(a2, o3);
|
|
941
|
+
console.log(e3);
|
|
942
|
+
break;
|
|
943
|
+
}
|
|
944
|
+
case `fish`: {
|
|
945
|
+
let e3 = r(a2, o3);
|
|
946
|
+
console.log(e3);
|
|
947
|
+
break;
|
|
948
|
+
}
|
|
949
|
+
case `powershell`: {
|
|
950
|
+
let e3 = i(a2, o3);
|
|
951
|
+
console.log(e3);
|
|
952
|
+
break;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
var u = new l();
|
|
958
|
+
var f = u;
|
|
959
|
+
|
|
960
|
+
// ../../node_modules/.pnpm/@bomb.sh+tab@0.0.11_cac@6.7.14_citty@0.1.6_commander@14.0.2/node_modules/@bomb.sh/tab/dist/shared-BE1U9MBi.js
|
|
961
|
+
function e2(e3 = `cli`) {
|
|
962
|
+
if (process.argv.indexOf(`--`) === -1) {
|
|
963
|
+
let t2 = `Error: You need to use -- to separate completion arguments.
|
|
964
|
+
Example: ${e3} complete -- <args>`;
|
|
965
|
+
console.error(t2), process.exit(1);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
// ../../node_modules/.pnpm/@bomb.sh+tab@0.0.11_cac@6.7.14_citty@0.1.6_commander@14.0.2/node_modules/@bomb.sh/tab/dist/commander.js
|
|
970
|
+
var o2 = process.execPath;
|
|
971
|
+
var s2 = process.argv.slice(1);
|
|
972
|
+
var c2 = d(o2);
|
|
973
|
+
var l2 = s2.map(d);
|
|
974
|
+
var u2 = `${c2} ${process.execArgv.map(d).join(` `)} ${l2[0]}`;
|
|
975
|
+
function d(e3) {
|
|
976
|
+
return e3.includes(` `) ? `'${e3}'` : e3;
|
|
977
|
+
}
|
|
978
|
+
function f2(o3) {
|
|
979
|
+
let s3 = o3.name();
|
|
980
|
+
p(o3), m(o3), o3.command(`complete [shell]`).description(`Generate shell completion scripts`).action(async (r2) => {
|
|
981
|
+
switch (r2) {
|
|
982
|
+
case `zsh`: {
|
|
983
|
+
let e3 = t(s3, u2);
|
|
984
|
+
console.log(e3);
|
|
985
|
+
break;
|
|
986
|
+
}
|
|
987
|
+
case `bash`: {
|
|
988
|
+
let e3 = n(s3, u2);
|
|
989
|
+
console.log(e3);
|
|
990
|
+
break;
|
|
991
|
+
}
|
|
992
|
+
case `fish`: {
|
|
993
|
+
let e3 = r(s3, u2);
|
|
994
|
+
console.log(e3);
|
|
995
|
+
break;
|
|
996
|
+
}
|
|
997
|
+
case `powershell`: {
|
|
998
|
+
let t2 = i(s3, u2);
|
|
999
|
+
console.log(t2);
|
|
1000
|
+
break;
|
|
1001
|
+
}
|
|
1002
|
+
case `debug`: {
|
|
1003
|
+
let e3 = /* @__PURE__ */ new Map();
|
|
1004
|
+
h(o3, ``, e3), console.log(`Collected commands:`);
|
|
1005
|
+
for (let [t2, n2] of e3.entries()) console.log(`- ${t2 || `<root>`}: ${n2.description() || `No description`}`);
|
|
1006
|
+
break;
|
|
1007
|
+
}
|
|
1008
|
+
default:
|
|
1009
|
+
console.error(`Unknown shell: ${r2}`), console.error(`Supported shells: zsh, bash, fish, powershell`), process.exit(1);
|
|
1010
|
+
}
|
|
1011
|
+
});
|
|
1012
|
+
let c3 = o3.parse.bind(o3);
|
|
1013
|
+
return o3.parse = function(e3, t2) {
|
|
1014
|
+
let n2 = e3 || process.argv, i2 = n2.findIndex((e4) => e4 === `complete`), l3 = n2.findIndex((e4) => e4 === `--`);
|
|
1015
|
+
if (i2 !== -1 && l3 !== -1 && l3 > i2) {
|
|
1016
|
+
let e4 = n2.slice(l3 + 1);
|
|
1017
|
+
return e2(s3), f.parse(e4), o3;
|
|
1018
|
+
}
|
|
1019
|
+
return c3(e3, t2);
|
|
1020
|
+
}, f;
|
|
1021
|
+
}
|
|
1022
|
+
function p(e3) {
|
|
1023
|
+
for (let t2 of e3.options) {
|
|
1024
|
+
let e4 = t2.flags, n2 = e4.match(/^-([a-zA-Z]), --/)?.[1], i2 = e4.match(/--([a-zA-Z0-9-]+)/)?.[1];
|
|
1025
|
+
i2 && (n2 ? f.option(i2, t2.description || ``, n2) : f.option(i2, t2.description || ``));
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
function m(e3) {
|
|
1029
|
+
let t2 = /* @__PURE__ */ new Map();
|
|
1030
|
+
h(e3, ``, t2);
|
|
1031
|
+
for (let [e4, n2] of t2.entries()) {
|
|
1032
|
+
if (e4 === ``) continue;
|
|
1033
|
+
let t3 = f.command(e4, n2.description() || ``);
|
|
1034
|
+
for (let e5 of n2.options) {
|
|
1035
|
+
let n3 = e5.flags, r2 = n3.match(/^-([a-zA-Z]), --/)?.[1], i2 = n3.match(/--([a-zA-Z0-9-]+)/)?.[1];
|
|
1036
|
+
i2 && (r2 ? t3.option(i2, e5.description || ``, r2) : t3.option(i2, e5.description || ``));
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
function h(e3, t2, n2) {
|
|
1041
|
+
n2.set(t2, e3);
|
|
1042
|
+
for (let r2 of e3.commands) r2.name() !== `complete` && h(r2, t2 ? `${t2} ${r2.name()}` : r2.name(), n2);
|
|
1043
|
+
}
|
|
13
1044
|
var detectPackageManager = async (projectRoot) => {
|
|
14
1045
|
const detected = await detect({ cwd: projectRoot });
|
|
15
1046
|
if (detected && ["npm", "yarn", "pnpm", "bun"].includes(detected)) {
|
|
@@ -508,6 +1539,29 @@ var getPackagesToUninstall = (agent) => {
|
|
|
508
1539
|
var spinner = (text, options) => ora({ text, isSilent: options?.silent });
|
|
509
1540
|
|
|
510
1541
|
// src/utils/templates.ts
|
|
1542
|
+
var AGENTS = [
|
|
1543
|
+
"claude-code",
|
|
1544
|
+
"cursor",
|
|
1545
|
+
"opencode",
|
|
1546
|
+
"codex",
|
|
1547
|
+
"gemini",
|
|
1548
|
+
"amp",
|
|
1549
|
+
"ami",
|
|
1550
|
+
"visual-edit"
|
|
1551
|
+
];
|
|
1552
|
+
var AGENT_NAMES = {
|
|
1553
|
+
"claude-code": "Claude Code",
|
|
1554
|
+
cursor: "Cursor",
|
|
1555
|
+
opencode: "OpenCode",
|
|
1556
|
+
codex: "Codex",
|
|
1557
|
+
gemini: "Gemini",
|
|
1558
|
+
amp: "Amp",
|
|
1559
|
+
ami: "Ami",
|
|
1560
|
+
"visual-edit": "Visual Edit"
|
|
1561
|
+
};
|
|
1562
|
+
var PROVIDERS = AGENTS.filter((agent) => agent !== "ami").map(
|
|
1563
|
+
(agent) => `@react-grab/${agent}`
|
|
1564
|
+
);
|
|
511
1565
|
var NEXT_APP_ROUTER_SCRIPT = `{process.env.NODE_ENV === "development" && (
|
|
512
1566
|
<Script
|
|
513
1567
|
src="//unpkg.com/react-grab/dist/index.global.js"
|
|
@@ -579,8 +1633,6 @@ var WEBPACK_IMPORT_WITH_AGENT = (agent) => {
|
|
|
579
1633
|
}`;
|
|
580
1634
|
};
|
|
581
1635
|
var SCRIPT_IMPORT = 'import Script from "next/script";';
|
|
582
|
-
|
|
583
|
-
// src/utils/transform.ts
|
|
584
1636
|
var hasReactGrabCode = (content) => {
|
|
585
1637
|
const fuzzyPatterns = [
|
|
586
1638
|
/["'`][^"'`]*react-grab/,
|
|
@@ -1601,16 +2653,7 @@ var previewPackageJsonAgentRemoval = (projectRoot, agent) => {
|
|
|
1601
2653
|
};
|
|
1602
2654
|
|
|
1603
2655
|
// src/commands/add.ts
|
|
1604
|
-
var VERSION = "0.0.
|
|
1605
|
-
var AGENT_NAMES = {
|
|
1606
|
-
"claude-code": "Claude Code",
|
|
1607
|
-
cursor: "Cursor",
|
|
1608
|
-
opencode: "OpenCode",
|
|
1609
|
-
codex: "Codex",
|
|
1610
|
-
gemini: "Gemini",
|
|
1611
|
-
amp: "Amp",
|
|
1612
|
-
"visual-edit": "Visual Edit"
|
|
1613
|
-
};
|
|
2656
|
+
var VERSION = "0.0.98";
|
|
1614
2657
|
var add = new Command().name("add").description("add an agent integration").argument(
|
|
1615
2658
|
"[agent]",
|
|
1616
2659
|
"agent to add (claude-code, cursor, opencode, codex, gemini, amp, visual-edit)"
|
|
@@ -1638,16 +2681,7 @@ var add = new Command().name("add").description("add an agent integration").argu
|
|
|
1638
2681
|
process.exit(1);
|
|
1639
2682
|
}
|
|
1640
2683
|
preflightSpinner.succeed();
|
|
1641
|
-
const
|
|
1642
|
-
"claude-code",
|
|
1643
|
-
"cursor",
|
|
1644
|
-
"opencode",
|
|
1645
|
-
"codex",
|
|
1646
|
-
"gemini",
|
|
1647
|
-
"amp",
|
|
1648
|
-
"visual-edit"
|
|
1649
|
-
];
|
|
1650
|
-
const availableAgents = allAgents.filter(
|
|
2684
|
+
const availableAgents = AGENTS.filter(
|
|
1651
2685
|
(agent) => !projectInfo.installedAgents.includes(agent)
|
|
1652
2686
|
);
|
|
1653
2687
|
if (availableAgents.length === 0) {
|
|
@@ -1659,7 +2693,7 @@ var add = new Command().name("add").description("add an agent integration").argu
|
|
|
1659
2693
|
let agentIntegration;
|
|
1660
2694
|
let agentsToRemove = [];
|
|
1661
2695
|
if (agentArg) {
|
|
1662
|
-
if (!
|
|
2696
|
+
if (!AGENTS.includes(agentArg)) {
|
|
1663
2697
|
logger.break();
|
|
1664
2698
|
logger.error(`Invalid agent: ${agentArg}`);
|
|
1665
2699
|
logger.error(
|
|
@@ -1946,7 +2980,7 @@ var add = new Command().name("add").description("add an agent integration").argu
|
|
|
1946
2980
|
handleError(error);
|
|
1947
2981
|
}
|
|
1948
2982
|
});
|
|
1949
|
-
var VERSION2 = "0.0.
|
|
2983
|
+
var VERSION2 = "0.0.98";
|
|
1950
2984
|
var MODIFIER_KEY_NAMES = {
|
|
1951
2985
|
metaKey: process.platform === "darwin" ? "\u2318 Command" : "\u229E Windows",
|
|
1952
2986
|
ctrlKey: "Ctrl",
|
|
@@ -2160,7 +3194,7 @@ var configure = new Command().name("configure").alias("config").description("con
|
|
|
2160
3194
|
handleError(error);
|
|
2161
3195
|
}
|
|
2162
3196
|
});
|
|
2163
|
-
var VERSION3 = "0.0.
|
|
3197
|
+
var VERSION3 = "0.0.98";
|
|
2164
3198
|
var REPORT_URL = "https://react-grab.com/api/report-cli";
|
|
2165
3199
|
var DOCS_URL = "https://github.com/aidenybai/react-grab";
|
|
2166
3200
|
var reportToCli = async (type, config, error) => {
|
|
@@ -2198,16 +3232,6 @@ var UNSUPPORTED_FRAMEWORK_NAMES = {
|
|
|
2198
3232
|
sveltekit: "SvelteKit",
|
|
2199
3233
|
gatsby: "Gatsby"
|
|
2200
3234
|
};
|
|
2201
|
-
var AGENT_NAMES2 = {
|
|
2202
|
-
"claude-code": "Claude Code",
|
|
2203
|
-
cursor: "Cursor",
|
|
2204
|
-
opencode: "OpenCode",
|
|
2205
|
-
codex: "Codex",
|
|
2206
|
-
gemini: "Gemini",
|
|
2207
|
-
amp: "Amp",
|
|
2208
|
-
ami: "Ami",
|
|
2209
|
-
"visual-edit": "Visual Edit"
|
|
2210
|
-
};
|
|
2211
3235
|
var MODIFIER_KEY_NAMES2 = {
|
|
2212
3236
|
metaKey: process.platform === "darwin" ? "\u2318 Command" : "\u229E Windows",
|
|
2213
3237
|
ctrlKey: "Ctrl",
|
|
@@ -2257,20 +3281,12 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2257
3281
|
logger.break();
|
|
2258
3282
|
logger.success("React Grab is already installed.");
|
|
2259
3283
|
logger.break();
|
|
2260
|
-
const allAgents =
|
|
2261
|
-
"claude-code",
|
|
2262
|
-
"cursor",
|
|
2263
|
-
"opencode",
|
|
2264
|
-
"codex",
|
|
2265
|
-
"gemini",
|
|
2266
|
-
"amp",
|
|
2267
|
-
"visual-edit"
|
|
2268
|
-
];
|
|
3284
|
+
const allAgents = AGENTS;
|
|
2269
3285
|
const availableAgents = allAgents.filter(
|
|
2270
3286
|
(agent) => !projectInfo.installedAgents.includes(agent)
|
|
2271
3287
|
);
|
|
2272
3288
|
if (projectInfo.installedAgents.length > 0) {
|
|
2273
|
-
const installedNames = projectInfo.installedAgents.map((innerAgent) =>
|
|
3289
|
+
const installedNames = projectInfo.installedAgents.map((innerAgent) => AGENT_NAMES[innerAgent] || innerAgent).join(", ");
|
|
2274
3290
|
logger.log(
|
|
2275
3291
|
`Currently installed agents: ${highlighter.info(installedNames)}`
|
|
2276
3292
|
);
|
|
@@ -2282,7 +3298,7 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2282
3298
|
type: "confirm",
|
|
2283
3299
|
name: "wantAddAgent",
|
|
2284
3300
|
message: `Would you like to add an ${highlighter.info("agent integration")}?`,
|
|
2285
|
-
initial:
|
|
3301
|
+
initial: false
|
|
2286
3302
|
});
|
|
2287
3303
|
if (wantAddAgent === void 0) {
|
|
2288
3304
|
logger.break();
|
|
@@ -2294,7 +3310,7 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2294
3310
|
name: "agent",
|
|
2295
3311
|
message: `Which ${highlighter.info("agent integration")} would you like to add?`,
|
|
2296
3312
|
choices: availableAgents.map((innerAgent) => ({
|
|
2297
|
-
title:
|
|
3313
|
+
title: AGENT_NAMES[innerAgent],
|
|
2298
3314
|
value: innerAgent
|
|
2299
3315
|
}))
|
|
2300
3316
|
});
|
|
@@ -2305,18 +3321,18 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2305
3321
|
const agentIntegration2 = agent;
|
|
2306
3322
|
let agentsToRemove2 = [];
|
|
2307
3323
|
if (projectInfo.installedAgents.length > 0) {
|
|
2308
|
-
const installedNames = projectInfo.installedAgents.map((innerAgent) =>
|
|
3324
|
+
const installedNames = projectInfo.installedAgents.map((innerAgent) => AGENT_NAMES[innerAgent] || innerAgent).join(", ");
|
|
2309
3325
|
const { action } = await prompts3({
|
|
2310
3326
|
type: "select",
|
|
2311
3327
|
name: "action",
|
|
2312
3328
|
message: "How would you like to proceed?",
|
|
2313
3329
|
choices: [
|
|
2314
3330
|
{
|
|
2315
|
-
title: `Replace ${installedNames} with ${
|
|
3331
|
+
title: `Replace ${installedNames} with ${AGENT_NAMES[agentIntegration2]}`,
|
|
2316
3332
|
value: "replace"
|
|
2317
3333
|
},
|
|
2318
3334
|
{
|
|
2319
|
-
title: `Add ${
|
|
3335
|
+
title: `Add ${AGENT_NAMES[agentIntegration2]} alongside existing`,
|
|
2320
3336
|
value: "add"
|
|
2321
3337
|
},
|
|
2322
3338
|
{ title: "Cancel", value: "cancel" }
|
|
@@ -2360,7 +3376,7 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2360
3376
|
}
|
|
2361
3377
|
if (removalResult.success && !removalResult.noChanges && removalResult.newContent) {
|
|
2362
3378
|
const removeWriteSpinner = spinner(
|
|
2363
|
-
`Removing ${
|
|
3379
|
+
`Removing ${AGENT_NAMES[agentToRemove] || agentToRemove} from ${removalResult.filePath}.`
|
|
2364
3380
|
).start();
|
|
2365
3381
|
const writeResult = applyTransform(removalResult);
|
|
2366
3382
|
if (!writeResult.success) {
|
|
@@ -2376,7 +3392,7 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2376
3392
|
}
|
|
2377
3393
|
if (removalPackageJsonResult.success && !removalPackageJsonResult.noChanges && removalPackageJsonResult.newContent) {
|
|
2378
3394
|
const removePackageJsonSpinner = spinner(
|
|
2379
|
-
`Removing ${
|
|
3395
|
+
`Removing ${AGENT_NAMES[agentToRemove] || agentToRemove} from ${removalPackageJsonResult.filePath}.`
|
|
2380
3396
|
).start();
|
|
2381
3397
|
const packageJsonWriteResult = applyPackageJsonTransform(
|
|
2382
3398
|
removalPackageJsonResult
|
|
@@ -2504,7 +3520,7 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2504
3520
|
didAddAgent = true;
|
|
2505
3521
|
logger.break();
|
|
2506
3522
|
logger.success(
|
|
2507
|
-
`${
|
|
3523
|
+
`${AGENT_NAMES[agentIntegration2]} has been added.`
|
|
2508
3524
|
);
|
|
2509
3525
|
}
|
|
2510
3526
|
} else {
|
|
@@ -2563,7 +3579,7 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2563
3579
|
didAddAgent = true;
|
|
2564
3580
|
logger.break();
|
|
2565
3581
|
logger.success(
|
|
2566
|
-
`${
|
|
3582
|
+
`${AGENT_NAMES[agentIntegration2]} has been added.`
|
|
2567
3583
|
);
|
|
2568
3584
|
}
|
|
2569
3585
|
}
|
|
@@ -2852,7 +3868,7 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2852
3868
|
if (!isNonInteractive && !opts.agent) {
|
|
2853
3869
|
logger.break();
|
|
2854
3870
|
if (opts.force && projectInfo.installedAgents.length > 0) {
|
|
2855
|
-
const installedNames = projectInfo.installedAgents.map((innerAgent) =>
|
|
3871
|
+
const installedNames = projectInfo.installedAgents.map((innerAgent) => AGENT_NAMES[innerAgent] || innerAgent).join(", ");
|
|
2856
3872
|
logger.warn(`Currently installed: ${installedNames}`);
|
|
2857
3873
|
logger.break();
|
|
2858
3874
|
}
|
|
@@ -2862,13 +3878,10 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2862
3878
|
message: `Would you like to add an ${highlighter.info("agent integration")}?`,
|
|
2863
3879
|
choices: [
|
|
2864
3880
|
{ title: "None", value: "none" },
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
{ title: "Gemini", value: "gemini" },
|
|
2870
|
-
{ title: "Amp", value: "amp" },
|
|
2871
|
-
{ title: "Visual Edit", value: "visual-edit" }
|
|
3881
|
+
...AGENTS.map((innerAgent) => ({
|
|
3882
|
+
title: AGENT_NAMES[innerAgent],
|
|
3883
|
+
value: innerAgent
|
|
3884
|
+
}))
|
|
2872
3885
|
]
|
|
2873
3886
|
});
|
|
2874
3887
|
if (agent === void 0) {
|
|
@@ -2877,18 +3890,18 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2877
3890
|
}
|
|
2878
3891
|
agentIntegration = agent;
|
|
2879
3892
|
if (opts.force && projectInfo.installedAgents.length > 0 && agentIntegration !== "none" && !projectInfo.installedAgents.includes(agentIntegration)) {
|
|
2880
|
-
const installedNames = projectInfo.installedAgents.map((innerAgent) =>
|
|
3893
|
+
const installedNames = projectInfo.installedAgents.map((innerAgent) => AGENT_NAMES[innerAgent] || innerAgent).join(", ");
|
|
2881
3894
|
const { action } = await prompts3({
|
|
2882
3895
|
type: "select",
|
|
2883
3896
|
name: "action",
|
|
2884
3897
|
message: "How would you like to proceed?",
|
|
2885
3898
|
choices: [
|
|
2886
3899
|
{
|
|
2887
|
-
title: `Replace ${installedNames} with ${
|
|
3900
|
+
title: `Replace ${installedNames} with ${AGENT_NAMES[agentIntegration]}`,
|
|
2888
3901
|
value: "replace"
|
|
2889
3902
|
},
|
|
2890
3903
|
{
|
|
2891
|
-
title: `Add ${
|
|
3904
|
+
title: `Add ${AGENT_NAMES[agentIntegration]} alongside existing`,
|
|
2892
3905
|
value: "add"
|
|
2893
3906
|
},
|
|
2894
3907
|
{ title: "Cancel", value: "cancel" }
|
|
@@ -2905,7 +3918,7 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2905
3918
|
}
|
|
2906
3919
|
}
|
|
2907
3920
|
} else if (opts.agent && opts.force && projectInfo.installedAgents.length > 0 && !projectInfo.installedAgents.includes(opts.agent) && !isNonInteractive) {
|
|
2908
|
-
const installedNames = projectInfo.installedAgents.map((innerAgent) =>
|
|
3921
|
+
const installedNames = projectInfo.installedAgents.map((innerAgent) => AGENT_NAMES[innerAgent] || innerAgent).join(", ");
|
|
2909
3922
|
logger.break();
|
|
2910
3923
|
logger.warn(`Currently installed: ${installedNames}`);
|
|
2911
3924
|
const { action } = await prompts3({
|
|
@@ -2914,11 +3927,11 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
2914
3927
|
message: "How would you like to proceed?",
|
|
2915
3928
|
choices: [
|
|
2916
3929
|
{
|
|
2917
|
-
title: `Replace ${installedNames} with ${
|
|
3930
|
+
title: `Replace ${installedNames} with ${AGENT_NAMES[agentIntegration]}`,
|
|
2918
3931
|
value: "replace"
|
|
2919
3932
|
},
|
|
2920
3933
|
{
|
|
2921
|
-
title: `Add ${
|
|
3934
|
+
title: `Add ${AGENT_NAMES[agentIntegration]} alongside existing`,
|
|
2922
3935
|
value: "add"
|
|
2923
3936
|
},
|
|
2924
3937
|
{ title: "Cancel", value: "cancel" }
|
|
@@ -3025,7 +4038,7 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
3025
4038
|
}
|
|
3026
4039
|
if (removalResult.success && !removalResult.noChanges && removalResult.newContent) {
|
|
3027
4040
|
const removeWriteSpinner = spinner(
|
|
3028
|
-
`Removing ${
|
|
4041
|
+
`Removing ${AGENT_NAMES[agentToRemove] || agentToRemove} from ${removalResult.filePath}.`
|
|
3029
4042
|
).start();
|
|
3030
4043
|
const writeResult = applyTransform(removalResult);
|
|
3031
4044
|
if (!writeResult.success) {
|
|
@@ -3039,7 +4052,7 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
3039
4052
|
}
|
|
3040
4053
|
if (removalPackageJsonResult.success && !removalPackageJsonResult.noChanges && removalPackageJsonResult.newContent) {
|
|
3041
4054
|
const removePackageJsonSpinner = spinner(
|
|
3042
|
-
`Removing ${
|
|
4055
|
+
`Removing ${AGENT_NAMES[agentToRemove] || agentToRemove} from ${removalPackageJsonResult.filePath}.`
|
|
3043
4056
|
).start();
|
|
3044
4057
|
const packageJsonWriteResult = applyPackageJsonTransform(
|
|
3045
4058
|
removalPackageJsonResult
|
|
@@ -3136,17 +4149,7 @@ var init = new Command().name("init").description("initialize React Grab in your
|
|
|
3136
4149
|
await reportToCli("error", void 0, error);
|
|
3137
4150
|
}
|
|
3138
4151
|
});
|
|
3139
|
-
var VERSION4 = "0.0.
|
|
3140
|
-
var AGENT_NAMES3 = {
|
|
3141
|
-
"claude-code": "Claude Code",
|
|
3142
|
-
cursor: "Cursor",
|
|
3143
|
-
opencode: "OpenCode",
|
|
3144
|
-
codex: "Codex",
|
|
3145
|
-
gemini: "Gemini",
|
|
3146
|
-
amp: "Amp",
|
|
3147
|
-
ami: "Ami",
|
|
3148
|
-
"visual-edit": "Visual Edit"
|
|
3149
|
-
};
|
|
4152
|
+
var VERSION4 = "0.0.98";
|
|
3150
4153
|
var remove = new Command().name("remove").description("remove an agent integration").argument(
|
|
3151
4154
|
"[agent]",
|
|
3152
4155
|
"agent to remove (claude-code, cursor, opencode, codex, gemini, amp, ami, visual-edit)"
|
|
@@ -3187,7 +4190,7 @@ var remove = new Command().name("remove").description("remove an agent integrati
|
|
|
3187
4190
|
logger.break();
|
|
3188
4191
|
logger.error(`Agent ${highlighter.info(agentArg)} is not installed.`);
|
|
3189
4192
|
logger.log(
|
|
3190
|
-
`Installed agents: ${projectInfo.installedAgents.map((innerAgent) =>
|
|
4193
|
+
`Installed agents: ${projectInfo.installedAgents.map((innerAgent) => AGENT_NAMES[innerAgent] || innerAgent).join(", ")}`
|
|
3191
4194
|
);
|
|
3192
4195
|
logger.break();
|
|
3193
4196
|
process.exit(1);
|
|
@@ -3200,7 +4203,7 @@ var remove = new Command().name("remove").description("remove an agent integrati
|
|
|
3200
4203
|
name: "agent",
|
|
3201
4204
|
message: `Which ${highlighter.info("agent integration")} would you like to remove?`,
|
|
3202
4205
|
choices: projectInfo.installedAgents.map((innerAgent) => ({
|
|
3203
|
-
title:
|
|
4206
|
+
title: AGENT_NAMES[innerAgent] || innerAgent,
|
|
3204
4207
|
value: innerAgent
|
|
3205
4208
|
}))
|
|
3206
4209
|
});
|
|
@@ -3219,7 +4222,7 @@ var remove = new Command().name("remove").description("remove an agent integrati
|
|
|
3219
4222
|
process.exit(1);
|
|
3220
4223
|
}
|
|
3221
4224
|
const removingSpinner = spinner(
|
|
3222
|
-
`Preparing to remove ${
|
|
4225
|
+
`Preparing to remove ${AGENT_NAMES[agentToRemove] || agentToRemove}.`
|
|
3223
4226
|
).start();
|
|
3224
4227
|
removingSpinner.succeed();
|
|
3225
4228
|
const result = previewAgentRemoval(
|
|
@@ -3316,14 +4319,14 @@ var remove = new Command().name("remove").description("remove an agent integrati
|
|
|
3316
4319
|
}
|
|
3317
4320
|
logger.break();
|
|
3318
4321
|
logger.log(
|
|
3319
|
-
`${highlighter.success("Success!")} ${
|
|
4322
|
+
`${highlighter.success("Success!")} ${AGENT_NAMES[agentToRemove] || agentToRemove} has been removed.`
|
|
3320
4323
|
);
|
|
3321
4324
|
logger.break();
|
|
3322
4325
|
} catch (error) {
|
|
3323
4326
|
handleError(error);
|
|
3324
4327
|
}
|
|
3325
4328
|
});
|
|
3326
|
-
var VERSION5 = "0.0.
|
|
4329
|
+
var VERSION5 = "0.0.98";
|
|
3327
4330
|
var DEFAULT_PROXY_PORT = 2e3;
|
|
3328
4331
|
var REACT_GRAB_SCRIPT = '<script src="https://unpkg.com/react-grab/dist/index.global.js"></script>';
|
|
3329
4332
|
var buildProviderScript = (provider) => `<script src="https://unpkg.com/${provider}/dist/client.global.js"></script>`;
|
|
@@ -3392,13 +4395,13 @@ var start = new Command().name("start").alias("proxy").description("start a prox
|
|
|
3392
4395
|
message: `Select a ${highlighter.info("provider")} to use:`,
|
|
3393
4396
|
choices: [
|
|
3394
4397
|
{ title: "None", value: "" },
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
4398
|
+
...PROVIDERS.map((provider2) => {
|
|
4399
|
+
const agentName = provider2.replace("@react-grab/", "");
|
|
4400
|
+
return {
|
|
4401
|
+
title: AGENT_NAMES[agentName],
|
|
4402
|
+
value: provider2
|
|
4403
|
+
};
|
|
4404
|
+
})
|
|
3402
4405
|
]
|
|
3403
4406
|
});
|
|
3404
4407
|
if (selectedProvider === void 0) {
|
|
@@ -3553,7 +4556,7 @@ var start = new Command().name("start").alias("proxy").description("start a prox
|
|
|
3553
4556
|
|
|
3554
4557
|
// src/cli.ts
|
|
3555
4558
|
process.noDeprecation = true;
|
|
3556
|
-
var VERSION6 = "0.0.
|
|
4559
|
+
var VERSION6 = "0.0.98";
|
|
3557
4560
|
var VERSION_API_URL = "https://www.react-grab.com/api/version";
|
|
3558
4561
|
process.on("SIGINT", () => process.exit(0));
|
|
3559
4562
|
process.on("SIGTERM", () => process.exit(0));
|
|
@@ -3568,4 +4571,49 @@ program.addCommand(add);
|
|
|
3568
4571
|
program.addCommand(remove);
|
|
3569
4572
|
program.addCommand(configure);
|
|
3570
4573
|
program.addCommand(start);
|
|
4574
|
+
var completion = f2(program);
|
|
4575
|
+
var initCommand = completion.commands.get("init");
|
|
4576
|
+
var initAgentOption = initCommand?.options.get("agent");
|
|
4577
|
+
if (initAgentOption) {
|
|
4578
|
+
initAgentOption.handler = (complete) => {
|
|
4579
|
+
for (const agent of AGENTS) {
|
|
4580
|
+
complete(agent, "");
|
|
4581
|
+
}
|
|
4582
|
+
};
|
|
4583
|
+
}
|
|
4584
|
+
var addCommand = completion.commands.get("add");
|
|
4585
|
+
var addAgentArg = addCommand?.arguments.get("agent");
|
|
4586
|
+
if (addAgentArg) {
|
|
4587
|
+
addAgentArg.handler = (complete) => {
|
|
4588
|
+
for (const agent of AGENTS) {
|
|
4589
|
+
complete(agent, "");
|
|
4590
|
+
}
|
|
4591
|
+
};
|
|
4592
|
+
}
|
|
4593
|
+
var removeCommand = completion.commands.get("remove");
|
|
4594
|
+
var removeAgentArg = removeCommand?.arguments.get("agent");
|
|
4595
|
+
if (removeAgentArg) {
|
|
4596
|
+
removeAgentArg.handler = (complete) => {
|
|
4597
|
+
for (const agent of AGENTS) {
|
|
4598
|
+
complete(agent, "");
|
|
4599
|
+
}
|
|
4600
|
+
};
|
|
4601
|
+
}
|
|
4602
|
+
var startCommand = completion.commands.get("start");
|
|
4603
|
+
var startProviderOption = startCommand?.options.get("provider");
|
|
4604
|
+
if (startProviderOption) {
|
|
4605
|
+
startProviderOption.handler = (complete) => {
|
|
4606
|
+
for (const provider of PROVIDERS) {
|
|
4607
|
+
complete(provider, "");
|
|
4608
|
+
}
|
|
4609
|
+
};
|
|
4610
|
+
}
|
|
4611
|
+
var startPortOption = startCommand?.options.get("port");
|
|
4612
|
+
if (startPortOption) {
|
|
4613
|
+
startPortOption.handler = (complete) => {
|
|
4614
|
+
complete("2000", "Default port");
|
|
4615
|
+
complete("3000", "Common dev port");
|
|
4616
|
+
complete("8080", "Alternative port");
|
|
4617
|
+
};
|
|
4618
|
+
}
|
|
3571
4619
|
program.parse();
|