Add project files.
This commit is contained in:
9
src/GithubRepoRemover/Api/IGithubClient.cs
Normal file
9
src/GithubRepoRemover/Api/IGithubClient.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Refit;
|
||||
|
||||
namespace GithubRepoRemover.Api;
|
||||
internal interface IGithubClient
|
||||
{
|
||||
[Get("/user/repos")]
|
||||
[Headers("Accept: application/vnd.github+json", "X-GitHub-Api-Version: 2022-11-28", "User-Agent: Github-Repo-Remover")]
|
||||
Task ListRepositoriesAsync([Authorize("Bearer")] string accessToken);
|
||||
}
|
||||
26
src/GithubRepoRemover/Command/DeleteReposCommand.cs
Normal file
26
src/GithubRepoRemover/Command/DeleteReposCommand.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Cli;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace GithubRepoRemover.Command;
|
||||
internal class DeleteReposCommand : Command<DeleteReposCommand.Settings>
|
||||
{
|
||||
public class Settings : CommandSettings
|
||||
{
|
||||
[CommandOption("-t|--token")]
|
||||
[Description("The GitHub personal access token to authenticate with")]
|
||||
public string Token { get; set; } = string.Empty;
|
||||
|
||||
public override ValidationResult Validate()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Token)) return ValidationResult.Error("GitHub personal access token can't be empty");
|
||||
|
||||
return ValidationResult.Success();
|
||||
}
|
||||
}
|
||||
|
||||
public override int Execute(CommandContext context, Settings settings)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
18
src/GithubRepoRemover/GithubRepoRemover.csproj
Normal file
18
src/GithubRepoRemover/GithubRepoRemover.csproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.9" />
|
||||
<PackageReference Include="Refit" Version="8.0.0" />
|
||||
<PackageReference Include="Refit.HttpClientFactory" Version="8.0.0" />
|
||||
<PackageReference Include="Spectre.Console" Version="0.51.1" />
|
||||
<PackageReference Include="Spectre.Console.Cli" Version="0.51.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace GithubRepoRemover.Infrastructure;
|
||||
internal class DotnetDIServiceRegistrar(IServiceCollection services) : ITypeRegistrar
|
||||
{
|
||||
private readonly IServiceCollection _services = services;
|
||||
|
||||
public ITypeResolver Build() => new DotnetDIServiceResolver(_services.BuildServiceProvider());
|
||||
|
||||
public void Register(Type service, Type implementation) => _services.AddTransient(service, implementation);
|
||||
|
||||
public void RegisterInstance(Type service, object implementation) => _services.AddSingleton(service, implementation);
|
||||
|
||||
public void RegisterLazy(Type service, Func<object> factory)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(factory, nameof(factory));
|
||||
_services.AddTransient(service, (provider) => factory());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
namespace GithubRepoRemover.Infrastructure;
|
||||
internal class DotnetDIServiceResolver(IServiceProvider serviceProvider) : ITypeResolver
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider = serviceProvider;
|
||||
|
||||
public object? Resolve(Type? type)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(type, nameof(type));
|
||||
return _serviceProvider.GetRequiredService(type);
|
||||
}
|
||||
}
|
||||
20
src/GithubRepoRemover/Program.cs
Normal file
20
src/GithubRepoRemover/Program.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using GithubRepoRemover.Command;
|
||||
using GithubRepoRemover.Infrastructure;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Spectre.Console.Cli;
|
||||
using Refit;
|
||||
using GithubRepoRemover.Api;
|
||||
|
||||
ServiceCollection services = new();
|
||||
|
||||
services
|
||||
.AddRefitClient<IGithubClient>()
|
||||
.ConfigureHttpClient(c =>
|
||||
{
|
||||
c.BaseAddress = new("https://api.github.com/");
|
||||
});
|
||||
|
||||
DotnetDIServiceRegistrar serviceRegistrar = new(services);
|
||||
|
||||
CommandApp<DeleteReposCommand> app = new(serviceRegistrar);
|
||||
return app.Run(args);
|
||||
8
src/GithubRepoRemover/Properties/launchSettings.json
Normal file
8
src/GithubRepoRemover/Properties/launchSettings.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"profiles": {
|
||||
"GithubRepoRemover": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--token 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user