51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
|
|
// Copyright (c) The Geekeey Authors
|
|||
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|||
|
|
|
|||
|
|
using System.CommandLine;
|
|||
|
|
using System.CommandLine.Parsing;
|
|||
|
|
|
|||
|
|
using Geekeey.Actions.Core.Commands;
|
|||
|
|
|
|||
|
|
namespace Geekeey.Actions.Core;
|
|||
|
|
|
|||
|
|
internal sealed class Program : RootCommand
|
|||
|
|
{
|
|||
|
|
#pragma warning disable format // @formatter:off
|
|||
|
|
public static readonly Option<Uri> Server = new GitHubContextOption<Uri>("--server", env: "GITHUB_SERVER_URL"){CustomParser = Uri};
|
|||
|
|
public static readonly Option<string> Token = new GitHubContextOption<string>("--token", env: "GITHUB_TOKEN");
|
|||
|
|
#pragma warning restore format // @formatter:on
|
|||
|
|
|
|||
|
|
public static Uri? Uri(ArgumentResult result)
|
|||
|
|
{
|
|||
|
|
string value;
|
|||
|
|
if (!result.Tokens.Any())
|
|||
|
|
{
|
|||
|
|
value = Environment.GetEnvironmentVariable("GITHUB_SERVER_URL")!;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
value = result.Tokens.Single().Value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!System.Uri.TryCreate(value, UriKind.RelativeOrAbsolute, out var uri))
|
|||
|
|
{
|
|||
|
|
result.AddError("Not a valid URI.");
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return uri;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private Program()
|
|||
|
|
{
|
|||
|
|
Add(Server);
|
|||
|
|
Add(Token);
|
|||
|
|
|
|||
|
|
Add(new Checkout());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static Task<int> Main(string[] args)
|
|||
|
|
{
|
|||
|
|
return new Program().Parse(args).InvokeAsync();
|
|||
|
|
}
|
|||
|
|
}
|