fix: Fix IAppPaths access issue in create-config

pull/76/head
Robert Dailey 3 years ago
parent 85b1abc035
commit 38b6ab5131

@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Exception when running `create-config` command.
## [2.1.0] - 2022-05-29
### Added

@ -5,6 +5,7 @@ using CliFx.Exceptions;
using CliFx.Infrastructure;
using Common;
using JetBrains.Annotations;
using Recyclarr.Command.Initialization;
using Serilog;
using TrashLib;
@ -16,40 +17,40 @@ public class CreateConfigCommand : ICommand
{
private readonly IFileSystem _fs;
private readonly IAppPaths _paths;
private readonly IDefaultAppDataSetup _appDataSetup;
private readonly ILogger _log;
private string? _path;
public CreateConfigCommand(ILogger logger, IFileSystem fs, IAppPaths paths)
public CreateConfigCommand(ILogger logger, IFileSystem fs, IAppPaths paths, IDefaultAppDataSetup appDataSetup)
{
_log = logger;
_fs = fs;
_paths = paths;
_appDataSetup = appDataSetup;
}
[CommandOption("path", 'p', Description =
"Path where the new YAML file should be created. Must include the filename (e.g. path/to/config.yml). " +
"File must not already exist. If not specified, uses the default path of `recyclarr.yml` right next to the " +
"executable.")]
public string Path
{
get => _path ?? _paths.ConfigPath;
set => _path = value;
}
"File must not already exist. If not specified, uses the default path of `recyclarr.yml` in the app data " +
"directory")]
public string? Path { get; set; }
public ValueTask ExecuteAsync(IConsole console)
{
_appDataSetup.SetupDefaultPath();
var reader = new ResourceDataReader(typeof(Program));
var ymlData = reader.ReadData("config-template.yml");
var path = Path ?? _paths.ConfigPath;
if (_fs.File.Exists(Path))
if (_fs.File.Exists(path))
{
throw new CommandException($"The file {Path} already exists. Please choose another path or " +
throw new CommandException($"The file {path} already exists. Please choose another path or " +
"delete/move the existing file and run this command again.");
}
_fs.Directory.CreateDirectory(_fs.Path.GetDirectoryName(Path));
_fs.File.WriteAllText(Path, ymlData);
_log.Information("Created configuration at: {Path}", Path);
_fs.Directory.CreateDirectory(_fs.Path.GetDirectoryName(path));
_fs.File.WriteAllText(path, ymlData);
_log.Information("Created configuration at: {Path}", path);
return default;
}
}

Loading…
Cancel
Save