Add FingerprintCommand
This commit is contained in:
62
Akari.Prototype.Server/Cli/Commands/FingerprintCommands.cs
Normal file
62
Akari.Prototype.Server/Cli/Commands/FingerprintCommands.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Akari.Prototype.Server.Services;
|
||||
using Akari.Prototype.Server.Utils;
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Exceptions;
|
||||
using CliFx.Extensibility;
|
||||
using CliFx.Infrastructure;
|
||||
using Spectre.Console;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Akari.Prototype.Server.Cli.Commands
|
||||
{
|
||||
[Command("fp", Description = "Manage registered fingerprints")]
|
||||
public class FingerprintCommands : ICommand
|
||||
{
|
||||
private readonly IFingerprintManager _fingerprintManager;
|
||||
|
||||
[Command("fp add", Description = "Add a fingerprint")]
|
||||
public class AddFingerprint : ICommand
|
||||
{
|
||||
[CommandParameter(0, Description = "The fingerprint name")]
|
||||
public string Name { get; init; }
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
if (Name.Length > 50)
|
||||
{
|
||||
throw new CommandException("Name can't be more than 50 characters");
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public FingerprintCommands(IFingerprintManager fingerprintManager)
|
||||
{
|
||||
_fingerprintManager = fingerprintManager;
|
||||
}
|
||||
|
||||
public ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
var ansiConsole = console.AsAnsiConsole();
|
||||
|
||||
var table = new Table();
|
||||
|
||||
table.AddColumn(new TableColumn("[bold yellow]Name[/]").LeftAligned());
|
||||
table.AddColumn(new TableColumn("[bold blue]Token[/]").LeftAligned());
|
||||
|
||||
foreach (var (name, hash) in _fingerprintManager.FingerprintsHash)
|
||||
{
|
||||
table.AddRow($"[silver]{name}[/]", $"[grey]{hash}[/]");
|
||||
}
|
||||
|
||||
ansiConsole.Write(table);
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using CliFx;
|
||||
using CliFx.Attributes;
|
||||
using CliFx.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Akari.Prototype.Server.Cli.Commands
|
||||
{
|
||||
[Command]
|
||||
public class MainCommand : ICommand
|
||||
{
|
||||
public async ValueTask ExecuteAsync(IConsole console)
|
||||
{
|
||||
await Program.AspMain(Array.Empty<string>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,8 @@ namespace Akari.Prototype.Server
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
Startup.ConfigureStandardServices(hostContext.Configuration, services);
|
||||
|
||||
services.AddTransient<FingerprintCommands>();
|
||||
});
|
||||
|
||||
public static IHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
|
||||
Reference in New Issue
Block a user