Skip to content

Commit

Permalink
fix: failed flag parsing error
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jan 25, 2023
1 parent 2c6d0cd commit d3e975f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
9 changes: 1 addition & 8 deletions src/parser/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {renderList} from '../cli-ux/list'
import * as chalk from 'chalk'
import {OptionFlag, Flag} from '../interfaces'
import {uniq} from '../config/util'
import {Arg, ArgInput, BooleanFlag, CLIParseErrorOptions} from '../interfaces/parser'
import {Arg, ArgInput, CLIParseErrorOptions} from '../interfaces/parser'

export {CLIError} from '../errors'

Expand Down Expand Up @@ -96,13 +96,6 @@ export class FlagInvalidOptionError extends CLIParseError {
}
}

export class FailedFlagParseError extends CLIParseError {
constructor(flag: BooleanFlag<any> | OptionFlag<any>, errMsg: string) {
const message = `Parsing --${flag.name} \n\t${errMsg}`
super({parse: {}, message})
}
}

export class ArgInvalidOptionError extends CLIParseError {
constructor(arg: Arg<any>, input: string) {
const message = `Expected ${input} to be one of: ${arg.options!.join(', ')}`
Expand Down
5 changes: 3 additions & 2 deletions src/parser/parse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-await-in-loop */
import {ArgInvalidOptionError, CLIError, FailedFlagParseError, FlagInvalidOptionError} from './errors'
import {ArgInvalidOptionError, CLIError, FlagInvalidOptionError} from './errors'
import {ArgToken, BooleanFlag, FlagToken, OptionFlag, OutputArgs, OutputFlags, ParserInput, ParserOutput, ParsingToken} from '../interfaces/parser'
import * as readline from 'readline'
import {isTruthy, pickBy} from '../util'
Expand Down Expand Up @@ -282,7 +282,8 @@ export class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']

return flag.parse ? await flag.parse(input, this.context, flag) : input
} catch (error: any) {
throw new FailedFlagParseError(flag, error.message)
error.message = `Parsing --${flag.name} \n\t${error.message}\nSee more help with --help`
throw error
}
}

Expand Down

0 comments on commit d3e975f

Please sign in to comment.