adds list and add command for server
All checks were successful
PiwigoDirectorySync/pipeline/head This commit looks good
All checks were successful
PiwigoDirectorySync/pipeline/head This commit looks good
This commit is contained in:
parent
d43235bca1
commit
6e714ef77a
42
PiwigoDirectorySync/Commands/PiwigoAddCommand.cs
Normal file
42
PiwigoDirectorySync/Commands/PiwigoAddCommand.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PiwigoDirectorySync.Infrastructure;
|
||||||
|
using PiwigoDirectorySync.Persistence;
|
||||||
|
using Spectre.Console.Cli;
|
||||||
|
|
||||||
|
namespace PiwigoDirectorySync.Commands;
|
||||||
|
|
||||||
|
internal class PiwigoAddCommand : CancellableAsyncCommand<PiwigoAddSettings>
|
||||||
|
{
|
||||||
|
private readonly ILogger<PiwigoAddCommand> _logger;
|
||||||
|
private readonly PersistenceContext _persistenceContext;
|
||||||
|
|
||||||
|
public PiwigoAddCommand(ILogger<PiwigoAddCommand> logger, PersistenceContext persistenceContext)
|
||||||
|
{
|
||||||
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||||
|
_persistenceContext = persistenceContext ?? throw new ArgumentNullException(nameof(persistenceContext));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task<int> ExecuteAsync(CommandContext context, PiwigoAddSettings settings, CancellationToken cancellation)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Adding piwigo server {SettingsServerName} with user {SettingsUserName} and url {SettingsUrl}", settings.ServerName, settings.UserName,
|
||||||
|
settings.Url);
|
||||||
|
|
||||||
|
var server = new ServerEntity
|
||||||
|
{
|
||||||
|
Url = settings.Url,
|
||||||
|
Name = settings.ServerName,
|
||||||
|
Username = settings.UserName,
|
||||||
|
Password = settings.Password,
|
||||||
|
RootDirectory = settings.RootDirectory
|
||||||
|
};
|
||||||
|
|
||||||
|
_persistenceContext.PiwigoServers.Add(server);
|
||||||
|
await _persistenceContext.SaveChangesAsync(cancellation);
|
||||||
|
|
||||||
|
var piwigoServers = await _persistenceContext.PiwigoServers.ToListAsync(cancellation);
|
||||||
|
PiwigoListCommand.PrintServers(piwigoServers);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
14
PiwigoDirectorySync/Commands/PiwigoAddSettings.cs
Normal file
14
PiwigoDirectorySync/Commands/PiwigoAddSettings.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
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;
|
||||||
|
}
|
45
PiwigoDirectorySync/Commands/PiwigoListCommand.cs
Normal file
45
PiwigoDirectorySync/Commands/PiwigoListCommand.cs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PiwigoDirectorySync.Infrastructure;
|
||||||
|
using PiwigoDirectorySync.Persistence;
|
||||||
|
using Spectre.Console;
|
||||||
|
using Spectre.Console.Cli;
|
||||||
|
|
||||||
|
namespace PiwigoDirectorySync.Commands;
|
||||||
|
|
||||||
|
internal class PiwigoListCommand : CancellableAsyncCommand<PiwigoListSettings>
|
||||||
|
{
|
||||||
|
private readonly ILogger<PiwigoListCommand> _logger;
|
||||||
|
private readonly PersistenceContext _persistenceContext;
|
||||||
|
|
||||||
|
public PiwigoListCommand(ILogger<PiwigoListCommand> logger, PersistenceContext persistenceContext)
|
||||||
|
{
|
||||||
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||||
|
_persistenceContext = persistenceContext ?? throw new ArgumentNullException(nameof(persistenceContext));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task<int> ExecuteAsync(CommandContext context, PiwigoListSettings settings, CancellationToken cancellation)
|
||||||
|
{
|
||||||
|
var piwigoServers = await _persistenceContext.PiwigoServers.ToListAsync(cancellation);
|
||||||
|
|
||||||
|
PrintServers(piwigoServers);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void PrintServers(List<ServerEntity> piwigoServers)
|
||||||
|
{
|
||||||
|
var table = new Table();
|
||||||
|
table.AddColumn(new TableColumn("Server Id").Centered());
|
||||||
|
table.AddColumn("Name");
|
||||||
|
table.AddColumn("User");
|
||||||
|
table.AddColumn("Url");
|
||||||
|
|
||||||
|
foreach (var piwigoServer in piwigoServers)
|
||||||
|
{
|
||||||
|
table.AddRow($"[green]{piwigoServer.Id}[/]", piwigoServer.Name, piwigoServer.Username, piwigoServer.Url);
|
||||||
|
}
|
||||||
|
|
||||||
|
AnsiConsole.Write(table);
|
||||||
|
}
|
||||||
|
}
|
7
PiwigoDirectorySync/Commands/PiwigoListSettings.cs
Normal file
7
PiwigoDirectorySync/Commands/PiwigoListSettings.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
using Spectre.Console.Cli;
|
||||||
|
|
||||||
|
namespace PiwigoDirectorySync.Commands;
|
||||||
|
|
||||||
|
internal class PiwigoListSettings : CommandSettings
|
||||||
|
{
|
||||||
|
}
|
@ -52,6 +52,13 @@ app.Configure(config =>
|
|||||||
c.AddCommand<SyncAlbumsCommand>("albums");
|
c.AddCommand<SyncAlbumsCommand>("albums");
|
||||||
c.AddCommand<SyncImagesCommand>("images");
|
c.AddCommand<SyncImagesCommand>("images");
|
||||||
});
|
});
|
||||||
|
config.AddBranch("piwigo", c =>
|
||||||
|
{
|
||||||
|
c.AddCommand<PiwigoListCommand>("list");
|
||||||
|
c.AddCommand<PiwigoAddCommand>("add");
|
||||||
|
// c.AddCommand<PiwigoUpdateCommand>("update");
|
||||||
|
// c.AddCommand<PiwigoRemoveCommand>("remove");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return await app.RunAsync(args);
|
return await app.RunAsync(args);
|
@ -36,6 +36,12 @@
|
|||||||
"commandLineArgs": "download",
|
"commandLineArgs": "download",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"ListServers": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "piwigo list",
|
||||||
|
"environmentVariables": {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user