combines settings with commands into same file

This commit is contained in:
Philipp Häfelfinger 2023-09-10 21:29:44 +02:00
parent bdbff917ca
commit 2dd4b85e06
14 changed files with 91 additions and 106 deletions

View File

@ -6,7 +6,7 @@ using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands; namespace PiwigoDirectorySync.Commands;
internal class DownloadImagesCommand : CancellableAsyncCommand<DownloadImagesSettings> internal class DownloadImagesCommand : CancellableAsyncCommand<DownloadImagesCommand.DownloadImagesSettings>
{ {
private readonly IImageSynchronizer _imageSynchronizer; private readonly IImageSynchronizer _imageSynchronizer;
private readonly ILogger<DownloadImagesCommand> _logger; private readonly ILogger<DownloadImagesCommand> _logger;
@ -30,4 +30,8 @@ internal class DownloadImagesCommand : CancellableAsyncCommand<DownloadImagesSet
return 0; return 0;
} }
internal class DownloadImagesSettings : CommonCommandSettings
{
}
} }

View File

@ -1,5 +0,0 @@
namespace PiwigoDirectorySync.Commands;
internal class DownloadImagesSettings : CommonCommandSettings
{
}

View File

@ -7,7 +7,7 @@ using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands; namespace PiwigoDirectorySync.Commands;
internal class PiwigoAddCommand : CancellableAsyncCommand<PiwigoAddSettings> internal class PiwigoAddCommand : CancellableAsyncCommand<PiwigoAddCommand.PiwigoAddSettings>
{ {
private readonly ILogger<PiwigoAddCommand> _logger; private readonly ILogger<PiwigoAddCommand> _logger;
private readonly PersistenceContext _persistenceContext; private readonly PersistenceContext _persistenceContext;
@ -49,4 +49,56 @@ internal class PiwigoAddCommand : CancellableAsyncCommand<PiwigoAddSettings>
return 0; return 0;
} }
internal class PiwigoAddSettings : CommandSettings
{
[CommandArgument(0, "<ServerName>")] public string ServerName { get; init; } = string.Empty;
[CommandArgument(1, "<UserName>")] public string UserName { get; init; } = string.Empty;
[CommandArgument(1, "<Password>")] public string Password { get; init; } = string.Empty;
[CommandArgument(1, "<Password>")] public string Url { get; init; } = string.Empty;
[CommandArgument(1, "<RootDirectory>")]
public string RootDirectory { get; init; } = string.Empty;
public override ValidationResult Validate()
{
var baseResult = base.Validate();
if (!baseResult.Successful)
{
return baseResult;
}
if (string.IsNullOrWhiteSpace(ServerName))
{
return ValidationResult.Error("Please specify a server name");
}
if (string.IsNullOrWhiteSpace(Url))
{
return ValidationResult.Error("Please specify a server url");
}
if (string.IsNullOrWhiteSpace(UserName))
{
return ValidationResult.Error("Please specify a valid username for the server");
}
if (string.IsNullOrWhiteSpace(Password))
{
return ValidationResult.Error("Please specify a password");
}
if (string.IsNullOrWhiteSpace(RootDirectory))
{
return ValidationResult.Error("Please specify a root directory");
}
if (!Directory.Exists(RootDirectory))
{
return ValidationResult.Error($"The root directory {RootDirectory} does not exist or is not accessible");
}
return ValidationResult.Success();
}
}
} }

View File

@ -1,56 +0,0 @@
using Spectre.Console;
using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands;
internal class PiwigoAddSettings : CommandSettings
{
[CommandArgument(0, "<ServerName>")] public string ServerName { get; init; } = string.Empty;
[CommandArgument(1, "<UserName>")] public string UserName { get; init; } = string.Empty;
[CommandArgument(1, "<Password>")] public string Password { get; init; } = string.Empty;
[CommandArgument(1, "<Password>")] public string Url { get; init; } = string.Empty;
[CommandArgument(1, "<RootDirectory>")]
public string RootDirectory { get; init; } = string.Empty;
public override ValidationResult Validate()
{
var baseResult = base.Validate();
if (!baseResult.Successful)
{
return baseResult;
}
if (string.IsNullOrWhiteSpace(ServerName))
{
return ValidationResult.Error("Please specify a server name");
}
if (string.IsNullOrWhiteSpace(Url))
{
return ValidationResult.Error("Please specify a server url");
}
if (string.IsNullOrWhiteSpace(UserName))
{
return ValidationResult.Error("Please specify a valid username for the server");
}
if (string.IsNullOrWhiteSpace(Password))
{
return ValidationResult.Error("Please specify a password");
}
if (string.IsNullOrWhiteSpace(RootDirectory))
{
return ValidationResult.Error("Please specify a root directory");
}
if (!Directory.Exists(RootDirectory))
{
return ValidationResult.Error($"The root directory {RootDirectory} does not exist or is not accessible");
}
return ValidationResult.Success();
}
}

View File

@ -7,7 +7,7 @@ using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands; namespace PiwigoDirectorySync.Commands;
internal class PiwigoListCommand : CancellableAsyncCommand<PiwigoListSettings> internal class PiwigoListCommand : CancellableAsyncCommand<PiwigoListCommand.PiwigoListSettings>
{ {
private readonly ILogger<PiwigoListCommand> _logger; private readonly ILogger<PiwigoListCommand> _logger;
private readonly PersistenceContext _persistenceContext; private readonly PersistenceContext _persistenceContext;
@ -42,4 +42,8 @@ internal class PiwigoListCommand : CancellableAsyncCommand<PiwigoListSettings>
AnsiConsole.Write(table); AnsiConsole.Write(table);
} }
internal class PiwigoListSettings : CommandSettings
{
}
} }

View File

@ -1,7 +0,0 @@
using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands;
internal class PiwigoListSettings : CommandSettings
{
}

View File

@ -1,4 +1,6 @@
using System.Diagnostics; using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Channels; using System.Threading.Channels;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PiwigoDirectorySync.Infrastructure; using PiwigoDirectorySync.Infrastructure;
@ -7,7 +9,7 @@ using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands; namespace PiwigoDirectorySync.Commands;
internal class ScanCommand : CancellableAsyncCommand<ScanSettings> internal class ScanCommand : CancellableAsyncCommand<ScanCommand.ScanSettings>
{ {
private readonly IFileIndexer _fileIndexer; private readonly IFileIndexer _fileIndexer;
private readonly IFileSystemScanner _fileSystemScanner; private readonly IFileSystemScanner _fileSystemScanner;
@ -49,4 +51,12 @@ internal class ScanCommand : CancellableAsyncCommand<ScanSettings>
//TODO: write failed files to log //TODO: write failed files to log
} }
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
internal class ScanSettings : CommonCommandSettings
{
[CommandOption("-d|--mark-for-delete")]
[DefaultValue(false)]
public bool MarkForDelete { get; set; }
}
} }

View File

@ -1,13 +0,0 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands;
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
internal class ScanSettings : CommonCommandSettings
{
[CommandOption("-d|--mark-for-delete")]
[DefaultValue(false)]
public bool MarkForDelete { get; set; }
}

View File

@ -6,7 +6,7 @@ using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands; namespace PiwigoDirectorySync.Commands;
internal class SyncAlbumsCommand : CancellableAsyncCommand<SyncAlbumsSettings> internal class SyncAlbumsCommand : CancellableAsyncCommand<SyncAlbumsCommand.SyncAlbumsSettings>
{ {
private readonly IAlbumSynchronizer _albumSynchronizer; private readonly IAlbumSynchronizer _albumSynchronizer;
private readonly ILogger<SyncAlbumsCommand> _logger; private readonly ILogger<SyncAlbumsCommand> _logger;
@ -31,4 +31,8 @@ internal class SyncAlbumsCommand : CancellableAsyncCommand<SyncAlbumsSettings>
return 0; return 0;
} }
internal class SyncAlbumsSettings : CommonCommandSettings
{
}
} }

View File

@ -1,8 +0,0 @@
using System.Diagnostics.CodeAnalysis;
namespace PiwigoDirectorySync.Commands;
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
internal class SyncAlbumsSettings : CommonCommandSettings
{
}

View File

@ -6,7 +6,7 @@ using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands; namespace PiwigoDirectorySync.Commands;
internal class SyncFullCommand : CancellableAsyncCommand<SyncFullSettings> internal class SyncFullCommand : CancellableAsyncCommand<SyncFullCommand.SyncFullSettings>
{ {
private readonly IAlbumSynchronizer _albumSynchronizer; private readonly IAlbumSynchronizer _albumSynchronizer;
private readonly IFileIndexer _fileIndexer; private readonly IFileIndexer _fileIndexer;
@ -44,4 +44,8 @@ internal class SyncFullCommand : CancellableAsyncCommand<SyncFullSettings>
return 0; return 0;
} }
internal class SyncFullSettings : CommonCommandSettings
{
}
} }

View File

@ -1,3 +0,0 @@
namespace PiwigoDirectorySync.Commands;
internal class SyncFullSettings : CommonCommandSettings {}

View File

@ -6,7 +6,7 @@ using Spectre.Console.Cli;
namespace PiwigoDirectorySync.Commands; namespace PiwigoDirectorySync.Commands;
internal class SyncImagesCommand : CancellableAsyncCommand<SyncImagesSettings> internal class SyncImagesCommand : CancellableAsyncCommand<SyncImagesCommand.SyncImagesSettings>
{ {
private readonly IImageSynchronizer _imageSynchronizer; private readonly IImageSynchronizer _imageSynchronizer;
private readonly ILogger<SyncImagesCommand> _logger; private readonly ILogger<SyncImagesCommand> _logger;
@ -30,4 +30,8 @@ internal class SyncImagesCommand : CancellableAsyncCommand<SyncImagesSettings>
return 0; return 0;
} }
internal class SyncImagesSettings : CommonCommandSettings
{
}
} }

View File

@ -1,5 +0,0 @@
namespace PiwigoDirectorySync.Commands;
internal class SyncImagesSettings : CommonCommandSettings
{
}