core-test/src/core/Commands/Release.cs
2026-02-12 21:31:34 +01:00

57 lines
2 KiB
C#

using System.CommandLine;
using Geekeey.Core.Properties;
using Microsoft.Extensions.FileSystemGlobbing;
namespace Geekeey.Core.Commands;
internal sealed class Release : Command
{
private static readonly Option<Uri> Repository = new("--repository") { Required = true, CustomParser = Parsers.Uri };
private static readonly Option<string> Version = new("--version") { Required = true };
private static readonly Option<Pattern> Draft = new("--draft") { CustomParser = Parsers.Pattern };
private static readonly Option<Pattern> PreRelease = new("--prerelease") { CustomParser = Parsers.Pattern };
private static readonly Option<string> Title = new("--title");
private static readonly Option<string> Notes = new("--notes");
private static readonly Option<Matcher> Attachments = new("--attachments") { CustomParser = Parsers.Matcher };
public Release() : base("release", Resources.ReleaseCommandDescription)
{
Add(Repository);
Add(Version);
Add(Draft);
Add(PreRelease);
Add(Title);
Add(Notes);
Add(Attachments);
SetAction(HandleAsync);
}
private Task<int> HandleAsync(ParseResult result, CancellationToken cancellationToken)
{
var server = result.GetRequiredValue(Program.Server);
var access = result.GetRequiredValue(Program.Token);
// relative repository urls are resolved against the server url
var repository = result.GetRequiredValue(Repository);
if (!repository.IsAbsoluteUri)
{
repository = new Uri(new Uri(server), repository);
}
var version = result.GetRequiredValue(Version);
var draft = result.GetValue(Draft);
var prerelease = result.GetValue(PreRelease);
var title = result.GetValue(Title);
var notes = result.GetValue(Notes);
var attachments = result.GetValue(Attachments);
// Implementation for checkout command goes here.
return Task.FromResult(0);
}
}