feat(commands): clear, config, version

- clear: clears terminal screen
- config: view and set editor / code-editor preferences
- version: print version and git hash (noz 0.1.0 (abc1234))
This commit is contained in:
kryptomrx 2026-05-16 23:21:06 +02:00
parent ae8a961cfd
commit 1865a7ccc2
4 changed files with 102 additions and 0 deletions

View file

@ -0,0 +1,16 @@
using NozCli.Repl;
namespace NozCli.Commands;
public class ClearCommand : ICommand
{
public string Name => "clear";
public string Description => "Clear the terminal screen";
public string Usage => "clear";
public Task ExecuteAsync(string[] args, ReplContext ctx, CancellationToken ct = default)
{
Console.Clear();
return Task.CompletedTask;
}
}

View file

@ -0,0 +1,64 @@
using NozCli.Repl;
using Spectre.Console;
namespace NozCli.Commands;
public class ConfigCommand : ICommand
{
public string Name => "config";
public string Description => "Show or set CLI configuration (editor, code-editor)";
public string Usage => "config [editor|code-editor] [value]";
public Task ExecuteAsync(string[] args, ReplContext ctx, CancellationToken ct = default)
{
var cfg = ctx.Config;
if (args.Length == 0)
{
// Show current config
var editorVal = cfg.Editor ?? "[dim](auto)[/]";
var codeEditorVal = cfg.CodeEditor ?? "[dim](auto)[/]";
AnsiConsole.WriteLine();
AnsiConsole.MarkupLine($" [dim grey]editor[/] {editorVal}");
AnsiConsole.MarkupLine($" [dim grey]code-editor[/] {codeEditorVal}");
AnsiConsole.MarkupLine($" [dim grey]server[/] {cfg.ServerUrl}");
AnsiConsole.WriteLine();
AnsiConsole.MarkupLine("[dim]Set with: config editor <nano|vim|vi|notepad>[/]");
AnsiConsole.MarkupLine("[dim] config code-editor <code|zed|subl|vim>[/]");
AnsiConsole.WriteLine();
return Task.CompletedTask;
}
var key = args[0].ToLowerInvariant();
var value = args.Length > 1 ? args[1] : null;
if (value is null)
{
AnsiConsole.MarkupLine($"[red]Usage: config {key} <value>[/]");
return Task.CompletedTask;
}
switch (key)
{
case "editor":
cfg.Editor = value;
cfg.Save();
AnsiConsole.MarkupLine($"[green]✓[/] editor → [white]{value}[/]");
break;
case "code-editor":
case "codeeditor":
cfg.CodeEditor = value;
cfg.Save();
AnsiConsole.MarkupLine($"[green]✓[/] code-editor → [white]{value}[/]");
break;
default:
AnsiConsole.MarkupLine($"[red]Unknown key:[/] {key} [dim](editor, code-editor)[/]");
break;
}
return Task.CompletedTask;
}
}

View file

@ -0,0 +1,17 @@
using NozCli.Repl;
using Spectre.Console;
namespace NozCli.Commands;
public class VersionCommand : ICommand
{
public string Name => "version";
public string Description => "Show noz version info";
public string Usage => "version";
public Task ExecuteAsync(string[] args, ReplContext ctx, CancellationToken ct = default)
{
AnsiConsole.MarkupLine($"\n [bold cyan]noz[/] [white]{VersionInfo.Full}[/]\n");
return Task.CompletedTask;
}
}

View file

@ -15,11 +15,16 @@ public class CommandRegistry
new LsCommand(), new LsCommand(),
new CdCommand(), new CdCommand(),
new CatCommand(), new CatCommand(),
new NewCommand(),
new EditCommand(), new EditCommand(),
new PushCommand(), new PushCommand(),
new SyncCommand(), new SyncCommand(),
new StatusCommand(), new StatusCommand(),
new RmCommand(), new RmCommand(),
new ConfigCommand(),
new TreeCommand(),
new VersionCommand(),
new ClearCommand(),
}; };
// HelpCommand gets the full list so it can print them all // HelpCommand gets the full list so it can print them all
list.Add(new HelpCommand(list)); list.Add(new HelpCommand(list));