feat: SquidStd.ConsoleCommands - interactive console commands with a fixed prompt#55
Merged
Conversation
…d quoted tokenizer
…ddConsoleCommands
…om the reference design
- feat(generators): ConsoleCommandRegistrationGenerator emitting RegisterGeneratedConsoleCommands with singleton registration and deferred RegisterCommand wiring via DryIoc RegisterInitializer - feat(generators): SQDGEN006 diagnostic for unsupported console command classes - feat(samples): SquidStd.Samples.ConsoleCommands with attribute, delegate and builtin command usage - test(generators): ConsoleCommandRegistrationGeneratorTests covering generation, description fallback, no-op and diagnostics - docs: SquidStd.ConsoleCommands package README, docfx article and toc entry
…ries on redefine, single log stream in the sample
Comment on lines
+56
to
+73
| foreach (var alias in aliases) | ||
| { | ||
| if (!_commands.TryAdd(alias, entry)) | ||
| { | ||
| _logger.Warning("Console command '{Command}' redefined", alias); | ||
| var displaced = _commands[alias]; | ||
| _commands[alias] = entry; | ||
|
|
||
| // Keep help output truthful: drop every other key that still points at the | ||
| // displaced entry, so its stale alias list is no longer reported. | ||
| foreach (var staleKey in _commands.Where(pair => ReferenceEquals(pair.Value, displaced)) | ||
| .Select(pair => pair.Key) | ||
| .ToArray()) | ||
| { | ||
| _commands.TryRemove(staleKey, out _); | ||
| } | ||
| } | ||
| } |
Comment on lines
+161
to
+165
| catch (Exception ex) | ||
| { | ||
| _logger.Error(ex, "Console command '{Command}' failed", name); | ||
| writeLine($"Command '{name}' failed: {ex.Message}"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New package
SquidStd.ConsoleCommands- interactive operator commands with a fixed prompt, ported (and generalized) from the moongatev2 console system.The stack (
container.AddConsoleCommands())|aliases, quoted-argument tokenizer (say "hello world"), case-insensitive dispatch, handler exceptions reported and logged but never fatal,ExecuteCommandWithOutputAsyncoutput capture (ready for future remote sources), prefix + per-command autocomplete providers.ConsolePromptLogSink: registered as a containerILogEventSink, picked up automatically by the bootstrap logger hook - setlogger.EnableConsole: falseand the prompt owns the terminal.help/?,clear/cls,exit/quit(resolves the bootstrap and stops it - engine events and lifecycle logs included).consoleCommands:Prompt,StartLocked,UnlockCharacter.[RegisterConsoleCommand("ping|p", "Replies pong.")]onIConsoleCommandExecutorclasses + source generator emittingRegisterGeneratedConsoleCommands()(lazy wiring viaRegisterInitializer<ICommandSystemService>, new SQDGEN006 diagnostic).Also
SquidStd.Samples.ConsoleCommands(runtime-verified: help list + pong, single log stream); package README + docs article + toc.help), sample log duplication fixed.Test Plan
Follow-ups noted (non-blocking)
exitstops all services but aRunAsync-hosted app keeps waiting on its infinite delay - the bootstrap needs a shutdown signal (next batch candidate).ConsoleUiServicerender paths.