/* * Copyright (C) Sapphirecode - All Rights Reserved * This file is part of console-app which is released under MIT. * See file 'LICENSE' for full license details. * Created by Timo Hocker , May 2020 */ import { OptionProcess } from '../Option'; import { ErrorCallback } from '../Types/ErrorCallback'; export abstract class OptionSource { public abstract async parse(opt: OptionProcess[]): Promise; protected error_callback?: ErrorCallback; public constructor (error_callback?: ErrorCallback) { this.error_callback = error_callback; } protected async assign_arg ( opt: OptionProcess, value: unknown ): Promise { try { opt.value = await opt.type_validation.to_type (value); opt.filled = true; } catch (e) { if (typeof this.error_callback !== 'undefined') this.error_callback (opt.name, value, e); } } }