@@ -17,281 +17,6 @@ function quoteIfNeeded(path: string): string {
1717 return path . includes ( ' ' ) ? `'${ path } '` : path ;
1818}
1919
20- // export default function tab(instance: CAC): void {
21- // instance.command("complete [shell]").action(async (shell, extra) => {
22- // switch (shell) {
23- // case "zsh": {
24- // const script = zsh.generate(instance.name, x);
25- // console.log(script);
26- // break;
27- // }
28- // case "bash": {
29- // const script = bash.generate(instance.name, x);
30- // console.log(script);
31- // break;
32- // }
33- // case "fish": {
34- // const script = fish.generate(instance.name, x);
35- // console.log(script);
36- // break;
37- // }
38- // case "powershell": {
39- // const script = powershell.generate(instance.name, x);
40- // console.log(script);
41- // break;
42- // }
43- // default: {
44- // const args: string[] = extra["--"];
45-
46- // instance.showHelpOnExit = false;
47- // let directive = ShellCompDirective.ShellCompDirectiveDefault;
48-
49- // const endsWithSpace = args[args.length - 1] === "";
50- // if (endsWithSpace) {
51- // args.pop();
52- // }
53-
54- // let toComplete = args[args.length - 1] || "";
55- // const previousArgs = args.slice(0, -1);
56-
57- // const completions: string[] = [];
58-
59- // instance.unsetMatchedCommand();
60- // instance.parse([execPath, processArgs[0], ...previousArgs], {
61- // run: false,
62- // });
63-
64- // const command = instance.matchedCommand ?? instance.globalCommand;
65-
66- // const options = [
67- // ...new Set([
68- // ...(command?.options ?? []),
69- // ...instance.globalCommand.options,
70- // ]),
71- // ];
72-
73- // let isCompletingFlagValue = false;
74- // let flagName = "";
75- // let option: (typeof options)[number] | null = null;
76- // const lastArg = previousArgs[previousArgs.length - 1];
77-
78- // function processOption() {
79- // const matchedOption = options.find((o) =>
80- // o.names.some((name) => name === flagName)
81- // );
82-
83- // if (matchedOption && !matchedOption.isBoolean) {
84- // isCompletingFlagValue = true;
85- // option = matchedOption;
86- // if (endsWithSpace) {
87- // toComplete = "";
88- // }
89- // } else {
90- // isCompletingFlagValue = false;
91- // option = null;
92- // }
93- // }
94-
95- // if (toComplete.startsWith("--")) {
96- // // Long option
97- // flagName = toComplete.slice(2);
98- // const equalsIndex = flagName.indexOf("=");
99- // if (equalsIndex !== -1 && !endsWithSpace) {
100- // // Option with '=', get the name before '='
101- // flagName = flagName.slice(0, equalsIndex);
102- // toComplete = toComplete.slice(toComplete.indexOf("=") + 1);
103- // processOption();
104- // } else if (!endsWithSpace) {
105- // // If not ending with space, still typing option name
106- // flagName = "";
107- // } else {
108- // // User pressed space after typing the option name
109- // processOption();
110- // toComplete = "";
111- // }
112- // } else if (toComplete.startsWith("-") && toComplete.length > 1) {
113- // // Short option
114- // flagName = toComplete.slice(1);
115- // if (!endsWithSpace) {
116- // // Still typing option name
117- // flagName = "";
118- // } else {
119- // processOption();
120- // toComplete = "";
121- // }
122- // } else if (lastArg?.startsWith("--") && !endsWithSpace) {
123- // flagName = lastArg.slice(2);
124- // processOption();
125- // } else if (
126- // lastArg?.startsWith("-") &&
127- // lastArg.length > 1 &&
128- // !endsWithSpace
129- // ) {
130- // flagName = lastArg.slice(2);
131- // processOption();
132- // }
133-
134- // if (isCompletingFlagValue) {
135- // const flagCompletionFn = flagMap.get(
136- // `${command.name} ${option?.name}`
137- // );
138-
139- // if (flagCompletionFn) {
140- // // Call custom completion function for the flag
141- // const comps = await flagCompletionFn(previousArgs, toComplete);
142- // completions.push(
143- // ...comps.map(
144- // (comp) => `${comp.action}\t${comp.description ?? ""}`
145- // )
146- // );
147- // directive = ShellCompDirective.ShellCompDirectiveNoFileComp;
148- // } else {
149- // // Default completion (e.g., file completion)
150- // directive = ShellCompDirective.ShellCompDirectiveDefault;
151- // }
152- // } else if (toComplete.startsWith("-") && !endsWithSpace) {
153- // const flag = toComplete.replace(/^-+/, ""); // Remove leading '-'
154-
155- // // Determine options to suggest
156- // let optionsToSuggest = options.filter((o) => {
157- // const equalToDefault =
158- // "default" in o.config &&
159- // instance.options[o.name] === o.config.default;
160- // return (
161- // o.names.some((name) => name.startsWith(flag)) &&
162- // !(instance.options[o.name] && !equalToDefault)
163- // );
164- // });
165-
166- // const requiredOptions = optionsToSuggest.filter((o) => o.required);
167-
168- // if (requiredOptions.length) {
169- // // Required options not yet specified
170- // optionsToSuggest = requiredOptions;
171- // }
172-
173- // if (optionsToSuggest.length > 0) {
174- // completions.push(
175- // ...optionsToSuggest.map(
176- // (o) => `--${o.name}\t${o.description ?? ""}`
177- // )
178- // );
179- // }
180-
181- // directive = ShellCompDirective.ShellCompDirectiveNoFileComp;
182- // } else {
183- // instance.parse(
184- // [execPath, processArgs[0], ...previousArgs, toComplete],
185- // {
186- // run: false,
187- // }
188- // );
189- // const fullCommandName = args
190- // .filter((arg) => !arg.startsWith("-"))
191- // .join(" ");
192-
193- // for (const c of instance.commands) {
194- // if (c.name === "complete") {
195- // // avoid showing completions for the completion server
196- // continue;
197- // }
198- // const fullCommandParts = fullCommandName.split(" ");
199- // const commandParts: { type: "command"; value: string }[] = c.name
200- // .split(" ")
201- // .map((part) => ({ type: "command", value: part }));
202- // const args: {
203- // type: "positional";
204- // position: number;
205- // value: Positional;
206- // }[] =
207- // positionalMap.get(c.name)?.map((arg, i) => ({
208- // type: "positional",
209- // position: i,
210- // value: arg,
211- // })) ?? [];
212- // const parts = [...commandParts, ...args];
213-
214- // for (let i = 0; i < parts.length; i++) {
215- // const fullCommandPart = fullCommandParts[i];
216- // const part = parts[i];
217-
218- // if (part.type === "command") {
219- // // Command part matching
220- // if (part.value === fullCommandPart) {
221- // // Command part matches user input, continue to next part
222- // continue;
223- // } else if (
224- // !fullCommandPart ||
225- // part.value.startsWith(fullCommandPart)
226- // ) {
227- // // User is typing this command part, provide completion
228- // completions.push(`${part.value}\t${c.description ?? ""}`);
229- // }
230- // // Command part does not match, break
231- // break;
232- // } else if (part.type === "positional") {
233- // const positional = part.value;
234- // // Positional argument handling
235- // if (part.value.variadic) {
236- // const comps = await positional.completion(
237- // previousArgs,
238- // toComplete
239- // );
240- // completions.push(
241- // ...comps.map(
242- // (comp) => `${comp.action}\t${comp.description ?? ""}`
243- // )
244- // );
245- // break;
246- // }
247- // if (typeof fullCommandPart !== "undefined") {
248- // // User has provided input for this positional argument
249- // if (i === fullCommandParts.length - 1 && !endsWithSpace) {
250- // // User is still typing this positional argument, provide completions
251- // const comps = await positional.completion(
252- // previousArgs,
253- // toComplete
254- // );
255- // completions.push(
256- // ...comps.map(
257- // (comp) => `${comp.action}\t${comp.description ?? ""}`
258- // )
259- // );
260- // break;
261- // } else {
262- // // Positional argument is already provided, move to next
263- // previousArgs.push(fullCommandPart);
264- // continue;
265- // }
266- // } else {
267- // // User has not provided input for this positional argument
268- // const comps = await positional.completion(
269- // previousArgs,
270- // toComplete
271- // );
272- // completions.push(
273- // ...comps.map(
274- // (comp) => `${comp.action}\t${comp.description ?? ""}`
275- // )
276- // );
277- // break;
278- // }
279- // }
280- // }
281- // }
282- // }
283-
284- // // Output completions
285- // for (const comp of completions) {
286- // console.log(comp.split("\n")[0].trim());
287- // }
288- // console.log(`:${directive}`);
289- // console.error(`Completion ended with directive: ${directive}`);
290- // }
291- // }
292- // });
293- // }
294-
29520export default function tab ( instance : CAC ) : Completion {
29621 const completion = new Completion ( ) ;
29722
0 commit comments