Skip to content

[POC] Command Registration#4

Open
st0012 wants to merge 2 commits intomasterfrom
command-registry
Open

[POC] Command Registration#4
st0012 wants to merge 2 commits intomasterfrom
command-registry

Conversation

@st0012
Copy link
Owner

@st0012 st0012 commented Jul 19, 2022

Benefits

Extensible

Users or gems will be able to register new commands with:

DEBUGGER__::Session.register_command("foo", aliases: ["fo"]) do |arg|
  # my command
end.document category: "My Gem", content: <<~MD
  * foo does blablabla
MD

And then the command document will appear in the help

❯ ruby -Ilib -rdebug target.rb
[4, 9] in target.rb
     4|   # my command
     5| end.document category: "My Gem", content: <<~MD
     6|   * foo does blablabla
     7| MD
     8|
=>   9| binding.b
=>#0    <main> at target.rb:9
(rdbg) help foo    # command

### My Gem

* foo does blablabla
(rdbg)

Easier to maintain

Currently, command documents need to be written in Ruby comments with a strict format. And the parsing logic is quite adhoc for that reason. With this approach, we can simplify the parsing logic and make the document naturally a part of the command definition.

Additional thoughts

  • The CommandSet logic is a replication of the Config class, which prevents sharing mutable hash while allowing modifying values. I hope this will make it Ractor-safe?

@st0012 st0012 force-pushed the command-registry branch from ae2deb3 to 52a6aa4 Compare July 20, 2022 08:49
@st0012 st0012 force-pushed the command-registry branch from 52a6aa4 to 9c22681 Compare July 20, 2022 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant