using System; using System.CommandLine; using System.CommandLine.Invocation; using System.IO; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Wabbajack.Downloaders; using Wabbajack.DTOs; using Wabbajack.Hashing.xxHash64; using Wabbajack.Paths; using Wabbajack.Paths.IO; namespace Wabbajack.CLI.Verbs { public class DownloadUrl : IVerb { private readonly ILogger _logger; private readonly DownloadDispatcher _dispatcher; public DownloadUrl(ILogger logger, DownloadDispatcher dispatcher) { _logger = logger; _dispatcher = dispatcher; } public Command MakeCommand() { var command = new Command("download-url"); command.Add(new Option(new[] { "-u", "-url" }, "Url to parse")); command.Add(new Option(new[] { "-o", "-output" }, "Output file")); command.Description = "Downloads a file to a given output"; command.Handler = CommandHandler.Create(Run); return command; } private async Task Run(Uri url, AbsolutePath output) { var parsed = _dispatcher.Parse(url); if (parsed == null) { _logger.LogCritical("No downloader found for {Url}", url); return 1; } var archive = new Archive() { State = parsed, Name = output.FileName.ToString() }; await _dispatcher.Download(archive, output, CancellationToken.None); return 0; } } }