console-app/lib/Sources/OptionSource.ts

26 lines
627 B
TypeScript
Raw Normal View History

2020-05-15 16:53:45 +02:00
/*
* 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 <timo@scode.ovh>, May 2020
*/
2020-05-09 21:30:37 +02:00
import { OptionProcess } from '../Option';
2020-05-09 19:51:43 +02:00
export abstract class OptionSource {
public abstract async parse(opt: OptionProcess[]): Promise<void>;
protected async assign_arg (
opt: OptionProcess,
value: unknown
): Promise<void> {
try {
opt.value = await opt.type_validation.to_type (value);
opt.filled = true;
}
catch (e) {
2020-05-27 18:35:01 +02:00
// could not assign
2020-05-09 19:51:43 +02:00
}
}
}