Skip to content

Commit a930f32

Browse files
committed
fix: types
1 parent 8bbcca2 commit a930f32

File tree

4 files changed

+6
-66
lines changed

4 files changed

+6
-66
lines changed

bin/completion-handlers.ts

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,5 @@
11
// TODO: i do not see any completion functionality in this file. nothing is being provided for the defined commands of these package managers. this is a blocker for release. every each of them should be handled.
22
import { Completion } from '../src/index.js';
3-
import { execSync } from 'child_process';
4-
5-
const DEBUG = false; // for debugging purposes
6-
7-
function debugLog(...args: any[]) {
8-
if (DEBUG) {
9-
console.error('[DEBUG]', ...args);
10-
}
11-
}
12-
13-
async function checkCliHasCompletions(
14-
cliName: string,
15-
packageManager: string
16-
): Promise<boolean> {
17-
try {
18-
debugLog(`Checking if ${cliName} has completions via ${packageManager}`);
19-
const command = `${packageManager} ${cliName} complete --`;
20-
const result = execSync(command, {
21-
encoding: 'utf8',
22-
stdio: ['pipe', 'pipe', 'ignore'],
23-
timeout: 1000, // AMIR: we still havin issues with this, it still hangs if a cli doesn't have completions. longer timeout needed for shell completion system (shell → node → package manager → cli)
24-
});
25-
const hasCompletions = !!result.trim();
26-
debugLog(`${cliName} supports completions: ${hasCompletions}`);
27-
return hasCompletions;
28-
} catch (error) {
29-
debugLog(`Error checking completions for ${cliName}:`, error);
30-
return false;
31-
}
32-
}
33-
34-
async function getCliCompletions(
35-
cliName: string,
36-
packageManager: string,
37-
args: string[]
38-
): Promise<string[]> {
39-
try {
40-
const completeArgs = args.map((arg) =>
41-
arg.includes(' ') ? `"${arg}"` : arg
42-
);
43-
const completeCommand = `${packageManager} ${cliName} complete -- ${completeArgs.join(' ')}`;
44-
debugLog(`Getting completions with command: ${completeCommand}`);
45-
46-
const result = execSync(completeCommand, {
47-
encoding: 'utf8',
48-
stdio: ['pipe', 'pipe', 'ignore'],
49-
timeout: 1000, // same: longer timeout needed for shell completion system (shell → node → package manager → cli)
50-
});
51-
52-
const completions = result.trim().split('\n').filter(Boolean);
53-
debugLog(`Got ${completions.length} completions from ${cliName}`);
54-
return completions;
55-
} catch (error) {
56-
debugLog(`Error getting completions from ${cliName}:`, error);
57-
return [];
58-
}
59-
}
603

614
export function setupCompletionForPackageManager(
625
packageManager: string,

examples/demo.cac.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cac from 'cac';
22
import tab from '../src/cac';
3-
import type { Command, Option, OptionsMap } from '../src/t';
3+
import type { Option, OptionsMap } from '../src/t';
44

55
const cli = cac('vite');
66

examples/demo.t.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ t.command('dev build', 'Build project');
9696
t.command('dev start', 'Start development server');
9797

9898
// Copy command with multiple arguments
99-
const copyCmd = t
100-
.command('copy', 'Copy files')
99+
t.command('copy', 'Copy files')
101100
.argument('source', function (complete) {
102101
complete('src/', 'Source directory');
103102
complete('dist/', 'Distribution directory');
@@ -110,7 +109,7 @@ const copyCmd = t
110109
});
111110

112111
// Lint command with variadic arguments
113-
const lintCmd = t.command('lint', 'Lint project').argument(
112+
t.command('lint', 'Lint project').argument(
114113
'files',
115114
function (complete) {
116115
complete('main.ts', 'Main file');

src/t.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,10 @@ export class RootCommand extends Command {
274274
) {
275275
// Handle flag value completion
276276
let optionName: string | undefined;
277-
let valueToComplete = toComplete;
278277

279278
if (toComplete.includes('=')) {
280-
const [flag, value] = toComplete.split('=');
279+
const [flag] = toComplete.split('=');
281280
optionName = flag;
282-
valueToComplete = value || '';
283281
} else if (lastPrevArg?.startsWith('-')) {
284282
optionName = lastPrevArg;
285283
}
@@ -342,7 +340,7 @@ export class RootCommand extends Command {
342340
if (option) return option;
343341

344342
// Try by short alias
345-
for (const [name, opt] of command.options) {
343+
for (const [_name, opt] of command.options) {
346344
if (opt.alias && `-${opt.alias}` === optionName) {
347345
return opt;
348346
}
@@ -391,7 +389,7 @@ export class RootCommand extends Command {
391389

392390
if (currentArgIndex < argumentEntries.length) {
393391
// We're within the defined arguments
394-
const [argName, argument] = argumentEntries[currentArgIndex];
392+
const [_argName, argument] = argumentEntries[currentArgIndex];
395393
targetArgument = argument;
396394
} else {
397395
// We're beyond the defined arguments, check if the last argument is variadic

0 commit comments

Comments
 (0)