File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed
Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ export default async function tab(
2424) {
2525 const completion = new Completion ( ) ;
2626
27+ // a hidden flag to track if -- is there in the raw arguments? we might need a better way to do this?
28+ const dashDashIndex = process . argv . indexOf ( '--' ) ;
29+ const wasDashDashProvided = dashDashIndex !== - 1 ;
30+
2731 // Add all commands and their options
2832 for ( const cmd of [ instance . globalCommand , ...instance . commands ] ) {
2933 if ( cmd . name === 'complete' ) continue ; // Skip completion command
@@ -85,7 +89,13 @@ export default async function tab(
8589 break ;
8690 }
8791 default : {
88- const args : string [ ] = extra [ '--' ] ;
92+ if ( ! wasDashDashProvided ) {
93+ console . error (
94+ 'Error: You need to use -- to separate completion arguments'
95+ ) ;
96+ return ;
97+ }
98+ const args : string [ ] = extra [ '--' ] || [ ] ;
8999 instance . showHelpOnExit = false ;
90100
91101 // Parse current command context
Original file line number Diff line number Diff line change @@ -98,6 +98,10 @@ export default async function tab<TArgs extends ArgsDef>(
9898) {
9999 const completion = new Completion ( ) ;
100100
101+ // a hidden flag to track if -- is there in the raw arguments? we might need a better way to do this?
102+ const dashDashIndex = process . argv . indexOf ( '--' ) ;
103+ const wasDashDashProvided = dashDashIndex !== - 1 ;
104+
101105 const meta = await resolve ( instance . meta ) ;
102106
103107 if ( ! meta ) {
@@ -155,7 +159,6 @@ export default async function tab<TArgs extends ArgsDef>(
155159 } ,
156160 async run ( ctx ) {
157161 let shell : string | undefined = ctx . rawArgs [ 0 ] ;
158- const extra = ctx . rawArgs . slice ( ctx . rawArgs . indexOf ( '--' ) + 1 ) ;
159162
160163 if ( shell === '--' ) {
161164 shell = undefined ;
@@ -188,6 +191,15 @@ export default async function tab<TArgs extends ArgsDef>(
188191 break ;
189192 }
190193 default : {
194+ // check if -- separator was provided
195+ if ( ! wasDashDashProvided ) {
196+ console . error (
197+ 'Error: You need to use -- to separate completion arguments'
198+ ) ;
199+ return ;
200+ }
201+
202+ const extra = ctx . rawArgs . slice ( ctx . rawArgs . indexOf ( '--' ) + 1 ) ;
191203 // const args = (await resolve(instance.args))!;
192204 // const parsed = parseArgs(extra, args);
193205 // TODO: this is not ideal at all
Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ export default function tab(instance: CommanderCommand): Completion {
2121 const completion = new Completion ( ) ;
2222 const programName = instance . name ( ) ;
2323
24+ // a hidden flag to track if -- is there in the raw arguments? we might need a better way to do this?
25+ const dashDashIndex = process . argv . indexOf ( '--' ) ;
26+ const wasDashDashProvided = dashDashIndex !== - 1 ;
27+
2428 // Process the root command
2529 processRootCommand ( completion , instance , programName ) ;
2630
@@ -79,6 +83,14 @@ export default function tab(instance: CommanderCommand): Completion {
7983 break ;
8084 }
8185 default : {
86+ // check if -- separator is provided
87+ if ( ! wasDashDashProvided ) {
88+ console . error (
89+ 'Error: You need to use -- to separate completion arguments'
90+ ) ;
91+ return ;
92+ }
93+
8294 // Parse current command context for autocompletion
8395 return completion . parse ( extra ) ;
8496 }
You can’t perform that action at this time.
0 commit comments