diff --git a/Akari.Prototype.Server/Cli/Commands/FingerprintCommands.cs b/Akari.Prototype.Server/Cli/Commands/FingerprintCommands.cs new file mode 100644 index 0000000..69f0478 --- /dev/null +++ b/Akari.Prototype.Server/Cli/Commands/FingerprintCommands.cs @@ -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; + } + } +} diff --git a/Akari.Prototype.Server/Cli/Commands/MainCommand.cs b/Akari.Prototype.Server/Cli/Commands/MainCommand.cs deleted file mode 100644 index bbbb0d8..0000000 --- a/Akari.Prototype.Server/Cli/Commands/MainCommand.cs +++ /dev/null @@ -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()); - } - } -} diff --git a/Akari.Prototype.Server/Program.cs b/Akari.Prototype.Server/Program.cs index b3fd407..282aadb 100644 --- a/Akari.Prototype.Server/Program.cs +++ b/Akari.Prototype.Server/Program.cs @@ -73,6 +73,8 @@ namespace Akari.Prototype.Server .ConfigureServices((hostContext, services) => { Startup.ConfigureStandardServices(hostContext.Configuration, services); + + services.AddTransient(); }); public static IHostBuilder CreateWebHostBuilder(string[] args) =>