-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1a27f5
commit 6dd941d
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DateTime>("date", "The date to download media for."); | ||
command.AddArgument(dateArgument); | ||
var pathArgument = new Argument<string>("path", "The path of the destination folder."); | ||
command.AddArgument(pathArgument); | ||
|
||
var verifyOption = new Option<bool>("--verify", "Verifies the upload after completion."); | ||
verifyOption.SetDefaultValue(true); | ||
command.AddOption(verifyOption); | ||
var archiveOption = new Option<bool>("--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<DownloadOptions>(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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters