UNPKG

docutils-ts

Version:

Port of the Python Docutils library to TypeScript

25 lines (24 loc) 898 B
import { Action } from 'argparse'; export class ActionValidating extends Action { constructor(options) { super(options); this.options = options; this.delegatedAction = options.delegatedAction; this.validator = options.validator; } call(parser, namespace, values, optionString) { let Action; try { Action = parser._registryGet('action', this.delegatedAction); } catch (e) { throw new Error(`no action for ${this.delegatedAction}`); } if (Action === undefined) { throw new Error(`no action for ${this.delegatedAction}`); } const value = this.validator(parser, namespace, values, optionString); const action = new Action(Object.assign({}, this.options, { "constant": value })); action.call(parser, namespace, [value], optionString); } }