Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] Command Registration #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

[POC] Command Registration #4

wants to merge 2 commits into from

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