import { ParserErrors as IParserErrors, ParserErrorType } from './types'; export class ParserErrors implements IParserErrors { private _errors: Map = new Map(); public get commandErrors(): string[] { return this.getErrors('command'); } public get argumentErrors(): string[] { return this.getErrors('argument'); } public get optionErrors(): string[] { return this.getErrors('option'); } public get allErrors(): string[] { return [...this.commandErrors, ...this.argumentErrors, ...this.optionErrors]; } public getErrors = (type?: ParserErrorType) => { if (type) { if (!this._errors.has(type)) { this._errors.set(type, []); } return this._errors.get(type); } else { return this.allErrors; } }; public clearErrors = (type?: ParserErrorType) => { if (type) { this._errors.set(type, []); } else { this._errors.clear(); } }; public push = (type: ParserErrorType, message: string) => { const errs = this.getErrors(type); errs.push(message); this._errors.set(type, errs); }; public get hasErrors(): boolean { return this.allErrors.length > 0; } public get hasNonArgOrOptionErrors(): boolean { return this.commandErrors.length > 0; } }