diff --git a/src/PhotoArchiver.Console/Commands/Download.cs b/src/PhotoArchiver.Console/Commands/Download.cs new file mode 100644 index 0000000..5053bde --- /dev/null +++ b/src/PhotoArchiver.Console/Commands/Download.cs @@ -0,0 +1,52 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using System; +using System.CommandLine; +using System.CommandLine.Invocation; + +namespace PhotoArchiver.Console.Commands; + +using Download; + +public static partial class Extensions +{ + public static void AddDownloadCommand(this RootCommand root, IHostBuilder hostBuilder) + { + var command = new Command("download", "Downloads media from cloud storage to a folder."); + + var dateArgument = new Argument("date", "The date to download media for."); + command.AddArgument(dateArgument); + var pathArgument = new Argument("path", "The path of the destination folder."); + command.AddArgument(pathArgument); + + var verifyOption = new Option("--verify", "Verifies the upload after completion."); + verifyOption.SetDefaultValue(true); + command.AddOption(verifyOption); + var archiveOption = new Option("--archive", "Archives the file after download."); + archiveOption.SetDefaultValue(false); + command.AddOption(archiveOption); + + command.SetHandler(async (InvocationContext context) => + { + var cancellationToken = context.GetCancellationToken(); + + // configure + hostBuilder.ConfigureServices((services) => + { + services.Configure(options => + { + options.Date = context.ParseResult.GetValueForArgument(dateArgument); + options.Path = context.ParseResult.GetValueForArgument(pathArgument); + options.Verify = context.ParseResult.GetValueForOption(verifyOption); + options.Archive = context.ParseResult.GetValueForOption(archiveOption); + }); + }); + using var host = hostBuilder.Build(); + + // run + await host.StartAsync(cancellationToken); + }); + + root.AddCommand(command); + } +} diff --git a/src/PhotoArchiver.Console/Commands/Upload.cs b/src/PhotoArchiver.Console/Commands/Upload.cs index 27c50e8..395b4ae 100644 --- a/src/PhotoArchiver.Console/Commands/Upload.cs +++ b/src/PhotoArchiver.Console/Commands/Upload.cs @@ -1,12 +1,13 @@ using Azure.Storage.Blobs.Models; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using PhotoArchiver.Upload; using System.CommandLine; using System.CommandLine.Invocation; namespace PhotoArchiver.Console.Commands; +using Upload; + public static partial class Extensions { public static void AddUploadCommand(this RootCommand root, IHostBuilder hostBuilder) diff --git a/src/PhotoArchiver.Console/Program.cs b/src/PhotoArchiver.Console/Program.cs index 664fcac..8635287 100644 --- a/src/PhotoArchiver.Console/Program.cs +++ b/src/PhotoArchiver.Console/Program.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using System.CommandLine; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -19,7 +20,6 @@ using PhotoArchiver.Update; using PhotoArchiver.Upload; using PhotoArchiver.Console; -using System.CommandLine; using PhotoArchiver.Console.Commands; [assembly: InternalsVisibleTo("PhotoArchiver.Tests")] @@ -93,5 +93,6 @@ var rootCommand = new RootCommand(); rootCommand.AddUploadCommand(hostBuilder); +rootCommand.AddDownloadCommand(hostBuilder); await rootCommand.InvokeAsync(args); \ No newline at end of file