@@ -15,6 +15,9 @@ const quotedProcessExecArgs = process.execArgv.map(quoteIfNeeded);
1515
1616const x = `${ quotedExecPath } ${ quotedProcessExecArgs . join ( ' ' ) } ${ quotedProcessArgs [ 0 ] } ` ;
1717
18+ // Regex to detect if an option takes a value (has <required> or [optional] parameters)
19+ const VALUE_OPTION_RE = / < [ ^ > ] + > | \[ [ ^ \] ] + \] / ;
20+
1821function quoteIfNeeded ( path : string ) : string {
1922 return path . includes ( ' ' ) ? `'${ path } '` : path ;
2023}
@@ -78,8 +81,12 @@ export default async function tab(
7881 const targetCommand = isRootCommand ? t : command ;
7982 if ( targetCommand ) {
8083 const handler = commandCompletionConfig ?. options ?. [ argName ] ;
84+
85+ // Check if option takes a value (has <> or [] in rawName, or is marked as required)
86+ const takesValue =
87+ option . required || VALUE_OPTION_RE . test ( option . rawName ) ;
88+
8189 if ( handler ) {
82- // Has custom handler → value option
8390 if ( shortFlag ) {
8491 targetCommand . option (
8592 argName ,
@@ -90,8 +97,24 @@ export default async function tab(
9097 } else {
9198 targetCommand . option ( argName , option . description || '' , handler ) ;
9299 }
100+ } else if ( takesValue ) {
101+ // Takes value but no custom handler = value option with no completions
102+ if ( shortFlag ) {
103+ targetCommand . option (
104+ argName ,
105+ option . description || '' ,
106+ async ( ) => [ ] , // Empty completions
107+ shortFlag
108+ ) ;
109+ } else {
110+ targetCommand . option (
111+ argName ,
112+ option . description || '' ,
113+ async ( ) => [ ]
114+ ) ;
115+ }
93116 } else {
94- // No custom handler → boolean flag
117+ // No custom handler and doesn't take value = boolean flag
95118 if ( shortFlag ) {
96119 targetCommand . option ( argName , option . description || '' , shortFlag ) ;
97120 } else {
0 commit comments