This repository was archived by the owner on Jul 5, 2024. It is now read-only.
forked from Squirrel/Squirrel.Windows
-
Notifications
You must be signed in to change notification settings - Fork 39
System command line full upgrade #120
Merged
Merged
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
2e603a1
Port Squirrel.Tool to System.CommandLine
Keboo 99833a9
WIP updating to System.Commandline
Keboo 634df3c
Pack command options.
Keboo f03b7fe
Mow WIP
Keboo b7867cf
Building out shared base commands
Keboo 68967ab
Added in the OSX Pack command
Keboo 702c38a
Starting on the HTTP and S3 commands
Keboo a13868c
OSX Update.exe updated
Keboo b6cbcff
Reverting change to Update.Windows
Keboo 74a9ecc
Fixing errors with commands
Keboo 2922147
Forcing csq to invoke Squirrel tool
Keboo 8442397
Starting tests for OSX PackCommand
Keboo 78fc8ed
OSX Pack command tests done
Keboo d5a1376
More tests
Keboo b1a7588
Windows PackCommand tests
Keboo ee2f0f3
Adding Windows releasify command tests
Keboo edf276c
Deployment command tests
Keboo 5da79bb
Removing questions
Keboo 8f0c75f
Removing TODO
Keboo b91b5b4
Removing commented code
Keboo e93d039
Removing TODO
Keboo d0a8c92
Simplify deployment commands into a 'upload' and 'download' top level…
caesay ee9293e
Fixing issue with help width being set to 80
Keboo 0a632ee
Updating AddSearchPaths and SquirrelAwareExecutable to be 0 to many
Keboo 8f3bd7d
Fixing override on SetOptionsValues methods
Keboo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,28 @@ | ||
| using System.CommandLine; | ||
| using System.CommandLine.Invocation; | ||
| using System.IO; | ||
| using Squirrel.SimpleSplat; | ||
|
|
||
| namespace Squirrel.CommandLine | ||
| { | ||
| public class BaseCommand : Command | ||
| { | ||
| 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 Squirrel packages") { | ||
| ArgumentHelpName = "DIRECTORY" | ||
| }; | ||
| Add(ReleaseDirectory); | ||
| } | ||
|
|
||
| private protected void SetOptionsValues(InvocationContext context, BaseOptions options) | ||
| { | ||
| options.releaseDir = context.ParseResult.GetValueForOption(ReleaseDirectory)?.FullName; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,9 @@ | ||
| namespace Squirrel.CommandLine | ||
| { | ||
| public enum Bitness | ||
| { | ||
| Unknown, | ||
| x86, | ||
| x64 | ||
| } | ||
| } |
This file contains hidden or 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,96 @@ | ||
| using System.CommandLine; | ||
| using Squirrel.CommandLine.Sync; | ||
| using System.CommandLine.Invocation; | ||
| using System.Threading.Tasks; | ||
| using System; | ||
|
|
||
| namespace Squirrel.CommandLine.Deployment | ||
| { | ||
| public class GitHubBaseCommand : BaseCommand | ||
| { | ||
| public Option<Uri> RepoUrl { get; } | ||
| public Option<string> Token { get; } | ||
|
|
||
| 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'.") { | ||
| IsRequired = true | ||
| }; | ||
| RepoUrl.MustBeValidHttpUri(); | ||
| Add(RepoUrl); | ||
|
|
||
| Token = new Option<string>("--token", "OAuth token to use as login credentials."); | ||
| Add(Token); | ||
| } | ||
|
|
||
| private protected void SetOptionsValues(InvocationContext context, SyncGithubOptions options) | ||
| { | ||
| base.SetOptionsValues(context, options); | ||
| options.repoUrl = context.ParseResult.GetValueForOption(RepoUrl)?.AbsoluteUri; | ||
| options.token = context.ParseResult.GetValueForOption(Token); | ||
| } | ||
| } | ||
|
|
||
| public class GitHubDownloadCommand : GitHubBaseCommand | ||
| { | ||
| public Option<bool> Pre { get; } | ||
|
|
||
| public GitHubDownloadCommand() | ||
| : base("github", "Download latest release from GitHub repository.") | ||
| { | ||
| Pre = new Option<bool>("--pre", "Get latest pre-release instead of stable."); | ||
| Add(Pre); | ||
|
|
||
| this.SetHandler(Execute); | ||
| } | ||
|
|
||
| private protected new void SetOptionsValues(InvocationContext context, SyncGithubOptions options) | ||
| { | ||
| base.SetOptionsValues(context, options); | ||
| options.pre = context.ParseResult.GetValueForOption(Pre); | ||
| } | ||
|
|
||
| private async Task Execute(InvocationContext context) | ||
| { | ||
| SyncGithubOptions options = new(); | ||
| SetOptionsValues(context, options); | ||
| await new GitHubRepository(options).DownloadRecentPackages(); | ||
| } | ||
| } | ||
|
|
||
| public class GitHubUploadCommand : GitHubBaseCommand | ||
| { | ||
| public Option<bool> Publish { get; } | ||
| public Option<string> ReleaseName { get; } | ||
|
|
||
| public GitHubUploadCommand() | ||
| : base("github", "Upload latest release to a GitHub repository.") | ||
| { | ||
| Publish = new Option<bool>("--publish", "Publish release instead of creating draft."); | ||
| Add(Publish); | ||
|
|
||
| ReleaseName = new Option<string>("--releaseName", "A custom {NAME} for created release.") { | ||
| ArgumentHelpName = "NAME" | ||
| }; | ||
| Add(ReleaseName); | ||
|
|
||
| this.SetHandler(Execute); | ||
| } | ||
|
|
||
| //Intentionally hiding base member | ||
| private protected new void SetOptionsValues(InvocationContext context, SyncGithubOptions options) | ||
| { | ||
| base.SetOptionsValues(context, options); | ||
| options.publish = context.ParseResult.GetValueForOption(Publish); | ||
| options.releaseName = context.ParseResult.GetValueForOption(ReleaseName); | ||
| } | ||
|
|
||
| private async Task Execute(InvocationContext context) | ||
| { | ||
| SyncGithubOptions options = new(); | ||
| SetOptionsValues(context, options); | ||
| await new GitHubRepository(options).UploadMissingPackages(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,39 @@ | ||
| using System; | ||
| using System.CommandLine; | ||
| using System.CommandLine.Invocation; | ||
| using System.Threading.Tasks; | ||
| using Squirrel.CommandLine.Sync; | ||
|
|
||
| namespace Squirrel.CommandLine.Deployment | ||
| { | ||
| public class HttpDownloadCommand : BaseCommand | ||
| { | ||
| public Option<Uri> Url { get; } | ||
|
|
||
| public HttpDownloadCommand() | ||
| : base("http", "Download latest release from a HTTP source.") | ||
| { | ||
| Url = new Option<Uri>("--url", "Url to download remote releases from.") { | ||
| ArgumentHelpName = "URL", | ||
| IsRequired = true, | ||
| }; | ||
| Url.MustBeValidHttpUri(); | ||
| Add(Url); | ||
|
|
||
| this.SetHandler(Execute); | ||
| } | ||
|
|
||
| private protected void SetOptionsValues(InvocationContext context, SyncHttpOptions options) | ||
| { | ||
| base.SetOptionsValues(context, options); | ||
| options.url = context.ParseResult.GetValueForOption(Url)?.AbsoluteUri; | ||
| } | ||
|
|
||
| public async Task Execute(InvocationContext context) | ||
| { | ||
| SyncHttpOptions options = new(); | ||
| SetOptionsValues(context, options); | ||
| await new SimpleWebRepository(options).DownloadRecentPackages(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,132 @@ | ||
| using System.CommandLine; | ||
| using System.CommandLine.Invocation; | ||
| using System.Threading.Tasks; | ||
| using Squirrel.CommandLine.Sync; | ||
|
|
||
| namespace Squirrel.CommandLine.Deployment | ||
| { | ||
| public class S3BaseCommand : BaseCommand | ||
| { | ||
| public Option<string> KeyId { get; } | ||
| public Option<string> Secret { get; } | ||
| public Option<string> Region { get; } | ||
| public Option<string> Endpoint { get; } | ||
| public Option<string> Bucket { get; } | ||
| public Option<string> PathPrefix { get; } | ||
|
|
||
| protected S3BaseCommand(string name, string description) | ||
| : base(name, description) | ||
| { | ||
| KeyId = new Option<string>("--keyId", "Authentication identifier or access key.") { | ||
| ArgumentHelpName = "IDENTIFIER", | ||
| IsRequired = true | ||
| }; | ||
| Add(KeyId); | ||
|
|
||
| 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).") { | ||
| ArgumentHelpName = "REGION" | ||
| }; | ||
| Region.AddValidator(result => { | ||
| for (var i = 0; i < result.Tokens.Count; i++) { | ||
| var region = result.Tokens[i].Value; | ||
| if (!string.IsNullOrWhiteSpace(region)) { | ||
| var r = Amazon.RegionEndpoint.GetBySystemName(result.Tokens[0].Value); | ||
| if (r is null || r.DisplayName == "Unknown") { | ||
| result.ErrorMessage = $"Region '{region}' lookup failed, is this a valid AWS region?"; | ||
| } | ||
| } else { | ||
| result.ErrorMessage = "A region value is required"; | ||
| } | ||
| } | ||
| }); | ||
| Add(Region); | ||
|
|
||
| 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.") { | ||
| ArgumentHelpName = "NAME", | ||
| IsRequired = true | ||
| }; | ||
| Add(Bucket); | ||
|
|
||
| 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); | ||
|
|
||
| this.AreMutuallyExclusive(Region, Endpoint) | ||
| .AtLeastOneRequired(Region, Endpoint); | ||
| } | ||
|
|
||
| private protected void SetOptionsValues(InvocationContext context, SyncS3Options options) | ||
| { | ||
| base.SetOptionsValues(context, options); | ||
| options.keyId = context.ParseResult.GetValueForOption(KeyId); | ||
| options.secret = context.ParseResult.GetValueForOption(Secret); | ||
| options.region = context.ParseResult.GetValueForOption(Region); | ||
| options.endpoint = context.ParseResult.GetValueForOption(Endpoint); | ||
| options.bucket = context.ParseResult.GetValueForOption(Bucket); | ||
| options.pathPrefix = context.ParseResult.GetValueForOption(PathPrefix); | ||
| } | ||
| } | ||
|
|
||
| public class S3DownloadCommand : S3BaseCommand | ||
| { | ||
| public S3DownloadCommand() | ||
| : base("s3", "Download latest release from an S3 bucket.") | ||
| { | ||
| this.SetHandler(Execute); | ||
| } | ||
|
|
||
| private async Task Execute(InvocationContext context) | ||
| { | ||
| SyncS3Options options = new(); | ||
| SetOptionsValues(context, options); | ||
| await new S3Repository(options).DownloadRecentPackages(); | ||
| } | ||
| } | ||
|
|
||
| public class S3UploadCommand : S3BaseCommand | ||
| { | ||
| public Option<bool> Overwrite { get; } | ||
| public Option<int> KeepMaxReleases { get; } | ||
|
|
||
| public S3UploadCommand() | ||
| : base("s3", "Upload releases to an S3 bucket.") | ||
| { | ||
| Overwrite = new Option<bool>("--overwrite", "Replace remote files if local files have changed."); | ||
| Add(Overwrite); | ||
|
|
||
| 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); | ||
|
|
||
| this.SetHandler(Execute); | ||
| } | ||
|
|
||
| //Intentionally hiding base member | ||
| private protected new void SetOptionsValues(InvocationContext context, SyncS3Options options) | ||
| { | ||
| base.SetOptionsValues(context, options); | ||
| options.overwrite = context.ParseResult.GetValueForOption(Overwrite); | ||
| options.keepMaxReleases = context.ParseResult.GetValueForOption(KeepMaxReleases); | ||
| } | ||
|
|
||
| private async Task Execute(InvocationContext context) | ||
| { | ||
| SyncS3Options options = new(); | ||
| SetOptionsValues(context, options); | ||
| await new S3Repository(options).UploadMissingPackages(); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.