@@ -299,6 +299,7 @@ export abstract class ApifyCommand<T extends typeof BuiltApifyCommand = typeof B
299299 }
300300
301301 if ( missingRequiredArgs . size ) {
302+ process . exitCode = 1 ;
302303 this . _printMissingRequiredArgs ( missingRequiredArgs ) ;
303304 return ;
304305 }
@@ -309,6 +310,7 @@ export abstract class ApifyCommand<T extends typeof BuiltApifyCommand = typeof B
309310 await this . run ( ) ;
310311 } catch ( err : any ) {
311312 error ( { message : err . message } ) ;
313+ process . exitCode ||= 1 ;
312314 } finally {
313315 // analytics
314316 if ( ! this . telemetryData . actorLanguage && COMMANDS_WITHIN_ACTOR . includes ( this . commandString ) ) {
@@ -588,9 +590,15 @@ export abstract class ApifyCommand<T extends typeof BuiltApifyCommand = typeof B
588590 }
589591
590592 private _printMissingRequiredArgs ( missingRequiredArgs : Map < string , TaggedArgBuilder < ArgTag , unknown > > ) {
591- const help = selectiveRenderHelpForCommand ( this . ctor , {
592- showUsageString : true ,
593- } ) ;
593+ let help : string | undefined ;
594+
595+ try {
596+ help = selectiveRenderHelpForCommand ( this . ctor , {
597+ showUsageString : true ,
598+ } ) ;
599+ } catch {
600+ // Help renderer may not be registered (e.g. in tests)
601+ }
594602
595603 const widestArgNameLength = widestLine ( [ ...missingRequiredArgs . keys ( ) ] . join ( '\n' ) ) ;
596604
@@ -606,14 +614,18 @@ export abstract class ApifyCommand<T extends typeof BuiltApifyCommand = typeof B
606614 missingArgsStrings . push ( ` ${ chalk . red ( '>' ) } ${ indented } ` ) ;
607615 }
608616
617+ const messageParts = [
618+ `Missing ${ missingRequiredArgs . size } required ${ this . pluralString ( missingRequiredArgs . size , 'argument' , 'arguments' ) } :` ,
619+ ...missingArgsStrings ,
620+ chalk . gray ( ' See more help with --help' ) ,
621+ ] ;
622+
623+ if ( help ) {
624+ messageParts . push ( '' , help ) ;
625+ }
626+
609627 error ( {
610- message : [
611- `Missing ${ missingRequiredArgs . size } required ${ this . pluralString ( missingRequiredArgs . size , 'argument' , 'arguments' ) } :` ,
612- ...missingArgsStrings ,
613- chalk . gray ( ' See more help with --help' ) ,
614- '' ,
615- help ,
616- ] . join ( '\n' ) ,
628+ message : messageParts . join ( '\n' ) ,
617629 } ) ;
618630 }
619631
0 commit comments