30 lines
1.2 KiB
C#
30 lines
1.2 KiB
C#
using NozCli.Core.Config;
|
|
using NozCli.Repl;
|
|
using Spectre.Console;
|
|
|
|
// ── noz init <url> <token> ────────────────────────────────────────────────────
|
|
if (args is ["init", var url, var token])
|
|
{
|
|
if (!url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
AnsiConsole.MarkupLine("[red]Error:[/] Only HTTPS servers are allowed.");
|
|
return 1;
|
|
}
|
|
|
|
var cfg = new LocalConfig { ServerUrl = url, Token = token };
|
|
cfg.Save();
|
|
AnsiConsole.MarkupLine($"[green]✓[/] Config saved → ~/.config/noz/config.json");
|
|
return 0;
|
|
}
|
|
|
|
// ── All other commands need a saved config ────────────────────────────────────
|
|
var config = LocalConfig.Load();
|
|
if (config is null)
|
|
{
|
|
AnsiConsole.MarkupLine("[red]Not initialised.[/] Run: [cyan]noz init <server-url> <token>[/]");
|
|
return 1;
|
|
}
|
|
|
|
// ── Interactive REPL ──────────────────────────────────────────────────────────
|
|
await ReplSession.RunAsync(config);
|
|
return 0;
|