@@ -10,7 +10,13 @@ import { renderHeader, renderUsage, renderValidationErrors } from './renderer.ts
1010import { create , resolveLazyCommand } from './utils.ts'
1111
1212import type { Args , ArgToken } from 'args-tokens'
13- import type { Command , CommandContext , CommandOptions , CommandRunner } from './types.ts'
13+ import type {
14+ Command ,
15+ CommandCallMode ,
16+ CommandContext ,
17+ CommandOptions ,
18+ CommandRunner
19+ } from './types.ts'
1420
1521/**
1622 * Run the command.
@@ -28,7 +34,12 @@ export async function cli<A extends Args = Args>(
2834
2935 const subCommand = getSubCommand ( tokens )
3036 const resolvedCommandOptions = resolveCommandOptions ( opts , entry )
31- const [ name , command ] = await resolveCommand ( subCommand , entry , resolvedCommandOptions , true )
37+ const [ name , command , callMode ] = await resolveCommand (
38+ subCommand ,
39+ entry ,
40+ resolvedCommandOptions ,
41+ true
42+ )
3243 if ( ! command ) {
3344 throw new Error ( `Command not found: ${ name || '' } ` )
3445 }
@@ -48,6 +59,7 @@ export async function cli<A extends Args = Args>(
4859 argv,
4960 tokens,
5061 omitted,
62+ callMode,
5163 command,
5264 commandOptions : resolvedCommandOptions
5365 } )
@@ -161,27 +173,31 @@ async function resolveCommand<A extends Args>(
161173 entry : Command < A > | CommandRunner < A > ,
162174 options : CommandOptions < A > ,
163175 needRunResolving : boolean = false
164- ) : Promise < [ string | undefined , Command < A > | undefined ] > {
176+ ) : Promise < [ string | undefined , Command < A > | undefined , CommandCallMode ] > {
165177 const omitted = ! sub
166178 if ( typeof entry === 'function' ) {
167- return [ undefined , { run : entry } ]
179+ return [ undefined , { run : entry } , 'entry' ]
168180 } else {
169181 if ( omitted ) {
170182 return typeof entry === 'object'
171- ? [ resolveEntryName ( entry ) , await resolveLazyCommand ( entry , '' , needRunResolving ) ]
172- : [ undefined , undefined ]
183+ ? [ resolveEntryName ( entry ) , await resolveLazyCommand ( entry , '' , needRunResolving ) , 'entry' ]
184+ : [ undefined , undefined , 'unexpected' ]
173185 } else {
174186 if ( options . subCommands == null || options . subCommands . size === 0 ) {
175- return [ resolveEntryName ( entry ) , await resolveLazyCommand ( entry , '' , needRunResolving ) ]
187+ return [
188+ resolveEntryName ( entry ) ,
189+ await resolveLazyCommand ( entry , '' , needRunResolving ) ,
190+ 'entry'
191+ ]
176192 }
177193
178194 const cmd = options . subCommands ?. get ( sub )
179195
180196 if ( cmd == null ) {
181- return [ sub , undefined ]
197+ return [ sub , undefined , 'unexpected' ]
182198 }
183199
184- return [ sub , await resolveLazyCommand ( cmd , sub , needRunResolving ) ]
200+ return [ sub , await resolveLazyCommand ( cmd , sub , needRunResolving ) , 'subCommand' ]
185201 }
186202 }
187203}
0 commit comments