mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Added the command to download latest release with a path.
This commit is contained in:
17
src/Velopack.Deployment/PathRepository.cs
Normal file
17
src/Velopack.Deployment/PathRepository.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Velopack.Sources;
|
||||
|
||||
namespace Velopack.Deployment;
|
||||
|
||||
public class PathDownloadOptions : RepositoryOptions
|
||||
{
|
||||
public DirectoryInfo Path { get; set; }
|
||||
}
|
||||
|
||||
public class PathRepository(ILogger logger) : SourceRepository<PathDownloadOptions, SimpleFileSource>(logger)
|
||||
{
|
||||
public override SimpleFileSource CreateSource(PathDownloadOptions options)
|
||||
{
|
||||
return new SimpleFileSource(options.Path);
|
||||
}
|
||||
}
|
||||
15
src/Velopack.Vpk/Commands/PathDownloadCommand.cs
Normal file
15
src/Velopack.Vpk/Commands/PathDownloadCommand.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace Velopack.Vpk.Commands;
|
||||
|
||||
public class PathDownloadCommand : OutputCommand
|
||||
{
|
||||
public DirectoryInfo Path { get; private set; }
|
||||
|
||||
public PathDownloadCommand()
|
||||
: base("path", "Download latest release from a specific path source.")
|
||||
{
|
||||
AddOption<DirectoryInfo>((p) => Path = p, "--path")
|
||||
.SetDescription("Path to download releases from.")
|
||||
.MustExist()
|
||||
.SetRequired();
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ public static partial class OptionMapper
|
||||
public static partial GitHubDownloadOptions ToOptions(this GitHubDownloadCommand cmd);
|
||||
public static partial GitHubUploadOptions ToOptions(this GitHubUploadCommand cmd);
|
||||
public static partial HttpDownloadOptions ToOptions(this HttpDownloadCommand cmd);
|
||||
public static partial PathDownloadOptions ToOption(this PathDownloadCommand cmd);
|
||||
public static partial S3DownloadOptions ToOptions(this S3DownloadCommand cmd);
|
||||
public static partial S3UploadOptions ToOptions(this S3UploadCommand cmd);
|
||||
public static partial DeltaGenOptions ToOptions(this DeltaGenCommand cmd);
|
||||
|
||||
@@ -83,6 +83,7 @@ public class Program
|
||||
downloadCommand.AddRepositoryDownload<GitHubDownloadCommand, GitHubRepository, GitHubDownloadOptions>(provider);
|
||||
downloadCommand.AddRepositoryDownload<S3DownloadCommand, S3Repository, S3DownloadOptions>(provider);
|
||||
downloadCommand.AddRepositoryDownload<HttpDownloadCommand, HttpRepository, HttpDownloadOptions>(provider);
|
||||
downloadCommand.AddRepositoryDownload<PathDownloadCommand, PathRepository, PathDownloadOptions>(provider);
|
||||
rootCommand.Add(downloadCommand);
|
||||
|
||||
var uploadCommand = new CliCommand("upload", "Upload local package(s) to a remote update source.");
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.CommandLine;
|
||||
using Velopack.Vpk.Commands;
|
||||
|
||||
namespace Velopack.CommandLine.Tests.Commands;
|
||||
public class PathDownloadCommandTests : BaseCommandTests<PathDownloadCommand>
|
||||
{
|
||||
[Fact]
|
||||
public void Path_WithPath_ParsesValue()
|
||||
{
|
||||
var command = new PathDownloadCommand();
|
||||
|
||||
DirectoryInfo directory = Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "releases"));
|
||||
ParseResult parseResult = command.ParseAndApply($"--path {directory.FullName}");
|
||||
|
||||
Assert.Empty(parseResult.Errors);
|
||||
Assert.Equal(directory.FullName, command.Path.FullName);
|
||||
|
||||
Directory.Delete(directory.FullName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Path_WithNonExistingDirectory_ShowsError()
|
||||
{
|
||||
var command = new PathDownloadCommand();
|
||||
|
||||
// Parse with a fake path
|
||||
ParseResult parseResult = command.ParseAndApply($"--path \"E:\releases\"");
|
||||
|
||||
Assert.Equal(1, parseResult.Errors.Count);
|
||||
Assert.StartsWith("--path directory is not found, but must exist", parseResult.Errors[0].Message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user