@@ -721,10 +721,21 @@ export class CodeError extends Error {
721721export class HelpError extends Error {
722722 readonly help : string = ''
723723 readonly messages : string [ ] = [ ]
724- readonly code = 22
725- constructor ( ...messages : string [ ] ) {
724+ readonly code : number = 22
725+ constructor ( config : { help ?: string ; code ?: number } , ...messages : string [ ] )
726+ constructor ( ...messages : string [ ] )
727+ constructor (
728+ first ?: string | { help ?: string ; code ?: number } ,
729+ ...rest : string [ ]
730+ ) {
726731 super ( )
727- this . messages = messages
732+ if ( typeof first === 'object' && first !== null ) {
733+ if ( first . help != null ) this . help = first . help
734+ if ( first . code != null ) this . code = first . code
735+ this . messages = rest
736+ } else if ( typeof first === 'string' ) {
737+ this . messages = [ first , ...rest ]
738+ }
728739 }
729740 public override toString ( ) : string {
730741 if ( this . messages . length ) {
@@ -758,7 +769,7 @@ export async function exec(cmd: string[]): Promise<void> {
758769 }
759770}
760771
761- export type AssertValues < T extends readonly unknown [ ] > = T [ number ]
772+ export type AssertFactoryValues < T extends readonly unknown [ ] > = T [ number ]
762773export function assertFactory < T extends readonly unknown [ ] > (
763774 values : T ,
764775 typeName : string ,
@@ -807,7 +818,7 @@ export function asError(value: unknown): Error {
807818
808819export async function exitWithError ( error ?: unknown , status ?: number ) {
809820 if ( status == null || status < 0 ) {
810- if ( error instanceof CodeError ) {
821+ if ( error instanceof CodeError || error instanceof HelpError ) {
811822 status = error . code ?? 1
812823 } else {
813824 status = 1
0 commit comments