|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|