@@ -42,10 +42,6 @@ export class CLI {
4242 }
4343
4444 async start ( ) {
45- // In built version, we are in dist/index.js (from cli/index.ts) -> core bundled? or just imported.
46- // The core logic is now in src/cli/core/src/CLI.ts or dist/core/src/CLI.js
47-
48- // Check for debug flag early
4945 if ( process . argv . includes ( '--debug' ) ) {
5046 setDebugMode ( true ) ;
5147 logger . debug ( 'Debug mode enabled via --debug flag' ) ;
@@ -56,18 +52,6 @@ export class CLI {
5652 if ( this . config . searchDirectories && this . config . searchDirectories . length > 0 ) {
5753 commandsDirs = [ ...this . config . searchDirectories ] ;
5854 } else {
59- // We assume the standard structure:
60- // cli/
61- // index.js
62- // commands/
63- // core/
64- // src/
65- // CLI.ts
66-
67- // When running from source (ts-node src/cli/index.ts), specific commands are in src/cli/commands.
68- // core is in src/cli/core/src.
69- // Relative path from CLI.ts to commands: ../../../commands
70-
7155 const possibleDirs = [
7256 path . resolve ( __dirname , './src/commands' ) ,
7357 path . resolve ( process . cwd ( ) , 'commands' ) // Fallback relative to cwd
@@ -183,12 +167,6 @@ export class CLI {
183167 const options = args . pop ( ) ; // last is options
184168
185169 if ( ! subcommand || options . help ) {
186- // If --help is passed to 'module --help', subcommand might be caught as 'module' if args parsing is weird?
187- // ACTUALLY: cac parses 'module add --help' as subcommand="add".
188- // 'module --help' might trigger the command itself? No, 'module <subcommand>' expects a subcommand.
189- // If I run 'module --help', it might fail validation or parse 'help' as subcommand if unlucky,
190- // but likely it just prints help if we didn't override.
191-
192170 await this . runHelp ( [ root , subcommand ] . filter ( Boolean ) ) ;
193171 return ;
194172 }
@@ -205,17 +183,7 @@ export class CLI {
205183 }
206184
207185 const CommandClass = cmd . class ;
208- // Map remaining args?
209- // The args array contains positional args AFTER subcommand.
210- // But we didn't define them in CAC, so they are just strings.
211- // We need to map them manually to the Target Command's args definition.
212- // argsDef.args usually starts after the command.
213- // For 'module add <url>', <url> is the first arg after 'add'.
214- // So 'args' here corresponds to <url>.
215-
216186 const argsDef = CommandClass . args || { } ;
217- // If using [...args], the variadic args are collected into the first argument array
218- // args here is what remains after popping options.
219187 const positionalArgs = ( args . length > 0 && Array . isArray ( args [ 0 ] ) ) ? args [ 0 ] : args ;
220188
221189 const childOptions = { ...options } ; // Copy options
@@ -242,25 +210,29 @@ export class CLI {
242210 } ) ;
243211 }
244212
213+ if ( argsDef . options ) {
214+ argsDef . options . forEach ( ( opt : any ) => {
215+ const name = opt . name . replace ( / ^ - + / , '' ) ; // remove leading dashes
216+ const camelName = name . split ( ' ' ) [ 0 ] . replace ( / - ( [ a - z ] ) / g, ( g : string ) => g [ 1 ] . toUpperCase ( ) ) ;
217+
218+ // Check both raw name and camelCase name
219+ // CAC usually provides camelCase options
220+ if ( childOptions [ camelName ] === undefined && opt . default !== undefined ) {
221+ childOptions [ camelName ] = opt . default ;
222+ }
223+ } ) ;
224+ }
225+
245226 await this . runCommand ( CommandClass , childOptions , cmdParts ) ;
246227 } ) ;
247228 }
248229 }
249- // Disable default help
250- // this.cli.help();
251230
252231 // Manually register global help to ensure it's allowed
253232 this . cli . option ( '--help, -h' , 'Display help' ) ;
254233
255234 this . cli . version ( this . version ) ;
256235
257- // Global help interception for root command
258- // If we run `app --help`, we need to catch it.
259- // CAC doesn't expose a clean global action without a command content.
260- // However, if we parse and no command matches, it usually errors or shows help.
261- // If we have default logic, we can put it here?
262- // Let's rely on standard parsing but maybe inspect raw args first?
263-
264236 if ( process . argv . includes ( '--help' ) || process . argv . includes ( '-h' ) ) {
265237 // Inspect non-option args to see if there's a command?
266238 const args = process . argv . slice ( 2 ) . filter ( a => ! a . startsWith ( '-' ) ) ;
@@ -280,14 +252,6 @@ export class CLI {
280252 // Simple heuristic: find first non-flag arg as command
281253 const args = process . argv . slice ( 2 ) ;
282254 const potentialCommand = args . find ( a => ! a . startsWith ( '-' ) ) ;
283- // If it matches a loaded command root, show help for it
284- // Otherwise show global help
285-
286- // We need to match 'module add' etc?
287- // Just pass the potential command parts to runHelp.
288- // runHelp handles filtering itself? No, runHelp takes commandParts to pass to HelpCommand.
289- // HelpCommand expects `command` array.
290-
291255 const helpArgs = potentialCommand ? [ potentialCommand ] : [ ] ;
292256 await this . runHelp ( helpArgs ) ;
293257
0 commit comments