// Copyright (C) 2023 WYATT GROUP // Please see the AUTHORS file for details. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . import 'package:brick_generator/logger.dart'; import 'package:brick_generator/models/variable_type.dart'; import 'package:brick_generator/string_extension.dart'; import 'package:yaml/yaml.dart'; const _typeKey = 'type'; const _nameKey = 'name'; const _descriptionKey = 'description'; const _defaultKey = 'default'; const _promptKey = 'prompt'; class BrickVariable { VariableType? type; String? name; String? description; String? defaultValue; String? prompt; Map? syntax; BrickVariable({ required this.type, required this.name, required this.description, required this.defaultValue, required this.prompt, required this.syntax, }); BrickVariable._(); factory BrickVariable.parser() => BrickVariable._(); static BrickVariable? from(YamlMap? data) => data != null ? BrickVariable( type: VariableType.fromString(data[_typeKey] as String?), name: data[_nameKey] as String?, description: data[_descriptionKey] as String?, defaultValue: data[_defaultKey] as String?, prompt: data[_promptKey] as String?, syntax: (data[_nameKey] as String? ?? '').syntaxes, ) : null; void checkFormat() { if (name == null || description == null || type == null) { final err = 'Yaml file is not conform'; Logger.throwError(ArgumentError(err), err); } } }