public SettingsService(IConsole console, IConfiguration config, ILogger <SettingsService> logger, IGeneratorConfiguration configuration, ILoader <ISettings> settingsLoader, IFileWriter fileWriter) { _console = console ?? throw new ArgumentNullException(nameof(console)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); _settingsLoader = settingsLoader ?? throw new ArgumentNullException(nameof(settingsLoader)); _fileWriter = fileWriter ?? throw new ArgumentNullException(nameof(fileWriter)); _configuration.Update(target: config.GetValue <string>("Target"), localFolder: config.GetValue <string>("LocalFolder")); }
private FileInfo Update() { var temp = Settings ?? Path.Combine(Output, "settings.json"); var settingFile = _settingsService.ValidateFilepath(temp); var settings = _settingsService.UpdateConfigurationAndReturn(settingFile); settings.OutputPath = Output; settings.ModelName = Model; settings.GeneratorName = Generator; settings.LocalFolder = LocalFolder; settings.Target = Target; settings.Version = Version; settings.SourceModel = SourceModel; var packageFile = Path.Combine(settings.LocalFolder, settings.Target, settings.Target + ".json"); if (_packageLoader.TryLoad(packageFile, out var list)) { settings.Packages = new List <IPackage>(list); } _generatorConfiguration.Update(settings); return(settingFile); }
public ISettings UpdateConfigurationAndReturn(FileInfo fileInfo) { _configuration.Update(settingsFile: fileInfo.FullName); if (_settingsLoader.TryLoad(_configuration.SettingsFile, out var instance)) { return(instance); } instance = new Settings(_configuration); var pleaseSave = Prompt.GetYesNo($"Unable to load the settings, would you like a new file '{fileInfo.FullName}'?", false); if (!pleaseSave) { return(instance); } SaveSettings(fileInfo, instance); return(instance); }