Skip to content

Commit ca48675

Browse files
committed
treat options well
1 parent e7b53f4 commit ca48675

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/cac.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export default async function tab(
7878
const targetCommand = isRootCommand ? t : command;
7979
if (targetCommand) {
8080
const handler = commandCompletionConfig?.options?.[argName];
81+
82+
// Check if option takes a value (has <> or [] in rawName, or is marked as required)
83+
const takesValue =
84+
option.required || /<[^>]+>|\[[^\]]+\]/.test(option.rawName);
85+
8186
if (handler) {
8287
// Has custom handler → value option
8388
if (shortFlag) {
@@ -90,8 +95,24 @@ export default async function tab(
9095
} else {
9196
targetCommand.option(argName, option.description || '', handler);
9297
}
98+
} else if (takesValue) {
99+
// Takes value but no custom handler → value option with no completions
100+
if (shortFlag) {
101+
targetCommand.option(
102+
argName,
103+
option.description || '',
104+
async () => [], // Empty completions
105+
shortFlag
106+
);
107+
} else {
108+
targetCommand.option(
109+
argName,
110+
option.description || '',
111+
async () => []
112+
);
113+
}
93114
} else {
94-
// No custom handler → boolean flag
115+
// No custom handler and doesn't take value → boolean flag
95116
if (shortFlag) {
96117
targetCommand.option(argName, option.description || '', shortFlag);
97118
} else {

0 commit comments

Comments
 (0)