mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Simplify deployment commands into a 'upload' and 'download' top level command.
This commit is contained in:
@@ -10,10 +10,11 @@ namespace Squirrel.CommandLine
|
||||
protected static IFullLogger Log = SquirrelLocator.CurrentMutable.GetService<ILogManager>().GetLogger(typeof(BaseOptions));
|
||||
|
||||
public Option<DirectoryInfo> ReleaseDirectory { get; }
|
||||
|
||||
protected BaseCommand(string name, string description)
|
||||
: base(name, description)
|
||||
{
|
||||
ReleaseDirectory = new Option<DirectoryInfo>(new[] { "-r", "--releaseDir" }, "Output {DIRECTORY} for releasified packages") {
|
||||
ReleaseDirectory = new Option<DirectoryInfo>(new[] { "-r", "--releaseDir" }, "Output directory for Squirrel packages") {
|
||||
ArgumentHelpName = "DIRECTORY"
|
||||
};
|
||||
Add(ReleaseDirectory);
|
||||
|
||||
@@ -6,15 +6,6 @@ using System;
|
||||
|
||||
namespace Squirrel.CommandLine.Deployment
|
||||
{
|
||||
public class GitHubCommand : Command
|
||||
{
|
||||
public GitHubCommand() : base("github", "Upload or download from GitHub")
|
||||
{
|
||||
Add(new GitHubDownloadCommand());
|
||||
Add(new GitHubUploadCommand());
|
||||
}
|
||||
}
|
||||
|
||||
public class GitHubBaseCommand : BaseCommand
|
||||
{
|
||||
public Option<Uri> RepoUrl { get; }
|
||||
@@ -23,13 +14,13 @@ namespace Squirrel.CommandLine.Deployment
|
||||
protected GitHubBaseCommand(string name, string description)
|
||||
: base(name, description)
|
||||
{
|
||||
RepoUrl = new Option<Uri>("--repoUrl", "Full url to the github repository\nexample: 'https://github.com/myname/myrepo'") {
|
||||
RepoUrl = new Option<Uri>("--repoUrl", "Full url to the github repository\nexample: 'https://github.com/myname/myrepo'.") {
|
||||
IsRequired = true
|
||||
};
|
||||
RepoUrl.MustBeValidHttpUri();
|
||||
Add(RepoUrl);
|
||||
|
||||
Token = new Option<string>("--token", "OAuth token to use as login credentials");
|
||||
Token = new Option<string>("--token", "OAuth token to use as login credentials.");
|
||||
Add(Token);
|
||||
}
|
||||
|
||||
@@ -44,13 +35,13 @@ namespace Squirrel.CommandLine.Deployment
|
||||
public class GitHubDownloadCommand : GitHubBaseCommand
|
||||
{
|
||||
public Option<bool> Pre { get; }
|
||||
|
||||
|
||||
public GitHubDownloadCommand()
|
||||
: base("down", "Download latest release from GitHub")
|
||||
: base("github", "Download latest release from GitHub repository.")
|
||||
{
|
||||
Pre = new Option<bool>("--pre", "Get latest pre-release instead of stable");
|
||||
Pre = new Option<bool>("--pre", "Get latest pre-release instead of stable.");
|
||||
Add(Pre);
|
||||
|
||||
|
||||
this.SetHandler(Execute);
|
||||
}
|
||||
|
||||
@@ -74,12 +65,12 @@ namespace Squirrel.CommandLine.Deployment
|
||||
public Option<string> ReleaseName { get; }
|
||||
|
||||
public GitHubUploadCommand()
|
||||
: base("up", "Upload latest release to GitHub")
|
||||
: base("github", "Upload latest release to a GitHub repository.")
|
||||
{
|
||||
Publish = new Option<bool>("--publish", "Publish release instead of creating draft");
|
||||
Publish = new Option<bool>("--publish", "Publish release instead of creating draft.");
|
||||
Add(Publish);
|
||||
|
||||
ReleaseName = new Option<string>("--releaseName", "A custom {NAME} for created release") {
|
||||
ReleaseName = new Option<string>("--releaseName", "A custom {NAME} for created release.") {
|
||||
ArgumentHelpName = "NAME"
|
||||
};
|
||||
Add(ReleaseName);
|
||||
|
||||
@@ -6,22 +6,14 @@ using Squirrel.CommandLine.Sync;
|
||||
|
||||
namespace Squirrel.CommandLine.Deployment
|
||||
{
|
||||
public class HttpCommand : Command
|
||||
{
|
||||
public HttpCommand() : base("http", "Download from HTTP")
|
||||
{
|
||||
Add(new HttpDownloadCommand());
|
||||
}
|
||||
}
|
||||
|
||||
public class HttpDownloadCommand : BaseCommand
|
||||
{
|
||||
public Option<Uri> Url { get; }
|
||||
|
||||
public HttpDownloadCommand()
|
||||
: base("down", "Download latest release from HTTP")
|
||||
: base("http", "Download latest release from a HTTP source.")
|
||||
{
|
||||
Url = new Option<Uri>("--url", "URL to download from") {
|
||||
Url = new Option<Uri>("--url", "Url to download remote releases from.") {
|
||||
ArgumentHelpName = "URL",
|
||||
IsRequired = true,
|
||||
};
|
||||
|
||||
@@ -5,15 +5,6 @@ using Squirrel.CommandLine.Sync;
|
||||
|
||||
namespace Squirrel.CommandLine.Deployment
|
||||
{
|
||||
public class S3Command : Command
|
||||
{
|
||||
public S3Command() : base("s3", "Upload or download from S3 API")
|
||||
{
|
||||
Add(new S3DownloadCommand());
|
||||
Add(new S3UploadCommand());
|
||||
}
|
||||
}
|
||||
|
||||
public class S3BaseCommand : BaseCommand
|
||||
{
|
||||
public Option<string> KeyId { get; }
|
||||
@@ -26,19 +17,19 @@ namespace Squirrel.CommandLine.Deployment
|
||||
protected S3BaseCommand(string name, string description)
|
||||
: base(name, description)
|
||||
{
|
||||
KeyId = new Option<string>("--keyId", "Authentication {IDENTIFIER} or access key") {
|
||||
KeyId = new Option<string>("--keyId", "Authentication identifier or access key.") {
|
||||
ArgumentHelpName = "IDENTIFIER",
|
||||
IsRequired = true
|
||||
};
|
||||
Add(KeyId);
|
||||
|
||||
Secret = new Option<string>("--secret", "Authentication secret {KEY}") {
|
||||
Secret = new Option<string>("--secret", "Authentication secret key.") {
|
||||
ArgumentHelpName = "KEY",
|
||||
IsRequired = true
|
||||
};
|
||||
Add(Secret);
|
||||
|
||||
Region = new Option<string>("--region", "AWS service {REGION} (eg. us-west-1)") {
|
||||
Region = new Option<string>("--region", "AWS service region (eg. us-west-1).") {
|
||||
ArgumentHelpName = "REGION"
|
||||
};
|
||||
Region.AddValidator(result => {
|
||||
@@ -56,19 +47,19 @@ namespace Squirrel.CommandLine.Deployment
|
||||
});
|
||||
Add(Region);
|
||||
|
||||
Endpoint = new Option<string>("--endpoint", "Custom service {URL} (backblaze, digital ocean, etc)") {
|
||||
Endpoint = new Option<string>("--endpoint", "Custom service url (backblaze, digital ocean, etc).") {
|
||||
ArgumentHelpName = "URL"
|
||||
};
|
||||
Add(Endpoint);
|
||||
|
||||
Bucket = new Option<string>("--bucket", "{NAME} of the S3 bucket") {
|
||||
Bucket = new Option<string>("--bucket", "Name of the S3 bucket.") {
|
||||
ArgumentHelpName = "NAME",
|
||||
IsRequired = true
|
||||
};
|
||||
Add(Bucket);
|
||||
|
||||
PathPrefix = new Option<string>("--pathPrefix", "A sub-folder {PATH} used for files in the bucket, for creating release channels (eg. 'stable' or 'dev')") {
|
||||
ArgumentHelpName = "PATH"
|
||||
PathPrefix = new Option<string>("--pathPrefix", "A sub-folder used for files in the bucket, for creating release channels (eg. 'stable' or 'dev').") {
|
||||
ArgumentHelpName = "PREFIX"
|
||||
};
|
||||
Add(PathPrefix);
|
||||
|
||||
@@ -91,7 +82,7 @@ namespace Squirrel.CommandLine.Deployment
|
||||
public class S3DownloadCommand : S3BaseCommand
|
||||
{
|
||||
public S3DownloadCommand()
|
||||
: base("down", "Download latest release from S3 API")
|
||||
: base("s3", "Download latest release from an S3 bucket.")
|
||||
{
|
||||
this.SetHandler(Execute);
|
||||
}
|
||||
@@ -110,12 +101,12 @@ namespace Squirrel.CommandLine.Deployment
|
||||
public Option<int> KeepMaxReleases { get; }
|
||||
|
||||
public S3UploadCommand()
|
||||
: base("up", "Upload releases to S3 API")
|
||||
: base("s3", "Upload releases to an S3 bucket.")
|
||||
{
|
||||
Overwrite = new Option<bool>("--overwrite", "Replace existing files if source has changed");
|
||||
Overwrite = new Option<bool>("--overwrite", "Replace remote files if local files have changed.");
|
||||
Add(Overwrite);
|
||||
|
||||
KeepMaxReleases = new Option<int>("--keepMaxReleases", "Applies a retention policy during upload which keeps only the specified {NUMBER} of old versions") {
|
||||
KeepMaxReleases = new Option<int>("--keepMaxReleases", "Apply a retention policy which keeps only the specified number of old versions in remote source.") {
|
||||
ArgumentHelpName = "NUMBER"
|
||||
};
|
||||
Add(KeepMaxReleases);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Builder;
|
||||
using System.CommandLine.Parsing;
|
||||
using Squirrel.CommandLine.Deployment;
|
||||
using Squirrel.SimpleSplat;
|
||||
@@ -13,7 +14,7 @@ namespace Squirrel.CommandLine
|
||||
= new Option<string>(new[] { "-x", "--xplat" }, "Select {PLATFORM} to cross-compile for (eg. win, osx)") {
|
||||
ArgumentHelpName = "PLATFORM"
|
||||
};
|
||||
public static Option<bool> VerboseOption { get; } = new Option<bool>("--verbose", "Print all diagnostic messages");
|
||||
public static Option<bool> VerboseOption { get; } = new Option<bool>("--verbose", "Print diagnostic messages.");
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
@@ -59,15 +60,24 @@ namespace Squirrel.CommandLine
|
||||
RootCommand rootCommand = new RootCommand($"Squirrel {SquirrelRuntimeInfo.SquirrelDisplayVersion} for creating and distributing Squirrel releases.");
|
||||
rootCommand.AddGlobalOption(PlatformOption);
|
||||
rootCommand.AddGlobalOption(VerboseOption);
|
||||
|
||||
foreach (var command in packageCommands) {
|
||||
rootCommand.Add(command);
|
||||
}
|
||||
Command deploymentCommand = new("deployment", "Command for deploying Squirrel releases") {
|
||||
new HttpCommand(),
|
||||
new S3Command(),
|
||||
new GitHubCommand()
|
||||
|
||||
Command uploadCommand = new("upload", "Upload local package(s) to a remote update source.") {
|
||||
new S3UploadCommand(),
|
||||
new GitHubUploadCommand(),
|
||||
};
|
||||
rootCommand.Add(deploymentCommand);
|
||||
|
||||
Command downloadCommand = new("download", "Download's the latest release from a remote update source.") {
|
||||
new HttpDownloadCommand(),
|
||||
new S3DownloadCommand(),
|
||||
new GitHubDownloadCommand(),
|
||||
};
|
||||
|
||||
rootCommand.Add(uploadCommand);
|
||||
rootCommand.Add(downloadCommand);
|
||||
|
||||
return rootCommand.Invoke(args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user