import {CommandTemplate} from '../../models/commandTemplate' import {CommandLoader} from '../commandLoader' export class ConfigFileCommandTemplateLoader implements CommandLoader{ private commandsConfiguration; constructor(commands:object){ if(commands === undefined) throw new Error("commands arguments cannot be undefined"); this.commandsConfiguration = commands; } loadCommandTemplateBy(filename: string): Promise { const result = this.commandsConfiguration .commands .find(comm => comm.filename === filename); if(!result){ throw new Error(`command with filename ${filename} was not found.`); } const response = new Promise(resolve => { resolve(new CommandTemplate(result.filename, result.template)); }); return response; } }