From 1865a7ccc29ed21f4b9adea12890ac2311c7f835 Mon Sep 17 00:00:00 2001 From: kryptomrx Date: Sat, 16 May 2026 23:21:06 +0200 Subject: [PATCH] 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)) --- NozCli/Commands/ClearCommand.cs | 16 ++++++++ NozCli/Commands/ConfigCommand.cs | 64 +++++++++++++++++++++++++++++++ NozCli/Commands/VersionCommand.cs | 17 ++++++++ NozCli/Repl/CommandRegistry.cs | 5 +++ 4 files changed, 102 insertions(+) create mode 100644 NozCli/Commands/ClearCommand.cs create mode 100644 NozCli/Commands/ConfigCommand.cs create mode 100644 NozCli/Commands/VersionCommand.cs diff --git a/NozCli/Commands/ClearCommand.cs b/NozCli/Commands/ClearCommand.cs new file mode 100644 index 0000000..d82f890 --- /dev/null +++ b/NozCli/Commands/ClearCommand.cs @@ -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; + } +} diff --git a/NozCli/Commands/ConfigCommand.cs b/NozCli/Commands/ConfigCommand.cs new file mode 100644 index 0000000..9f2841e --- /dev/null +++ b/NozCli/Commands/ConfigCommand.cs @@ -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 [/]"); + AnsiConsole.MarkupLine("[dim] config code-editor [/]"); + 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} [/]"); + 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; + } +} diff --git a/NozCli/Commands/VersionCommand.cs b/NozCli/Commands/VersionCommand.cs new file mode 100644 index 0000000..6fe469f --- /dev/null +++ b/NozCli/Commands/VersionCommand.cs @@ -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; + } +} diff --git a/NozCli/Repl/CommandRegistry.cs b/NozCli/Repl/CommandRegistry.cs index 15904cc..4a2548e 100644 --- a/NozCli/Repl/CommandRegistry.cs +++ b/NozCli/Repl/CommandRegistry.cs @@ -15,11 +15,16 @@ public class CommandRegistry new LsCommand(), new CdCommand(), new CatCommand(), + new NewCommand(), new EditCommand(), new PushCommand(), new SyncCommand(), new StatusCommand(), new RmCommand(), + new ConfigCommand(), + new TreeCommand(), + new VersionCommand(), + new ClearCommand(), }; // HelpCommand gets the full list so it can print them all list.Add(new HelpCommand(list));