-
Notifications
You must be signed in to change notification settings - Fork 76
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
Use the IRB extension API to add commands to the console #117
Conversation
@@ -67,10 +67,9 @@ class Engine < ::Rails::Engine | |||
|
|||
console do | |||
require "irb" | |||
require "irb/context" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newer versions of IRB require irb/context
by default, so this won't be necessary.
module MissionControl::Jobs | ||
class ConnectTo < IRB::Command::Base | ||
category "Mission control jobs" | ||
description "Connect to a job server" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also add help_message
to commands to display more detailed messages when help <cmd>
is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!!
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec| | |||
spec.add_dependency "importmap-rails" | |||
spec.add_dependency "turbo-rails" | |||
spec.add_dependency "stimulus-rails" | |||
spec.add_dependency "irb", "~> 1.13" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new API is added in v1.13, so it's necessary to require it.
I'm so sorry for the delay, @st0012. I love this!! 🤩 Amazing work on this new IRB extension API; it's super cool 🙇♀️ |
After rails/rails#51705, the current way to add commands to the console will no longer work as `Rails::ConsoleMethods` will not be directly included in the IRB internal anymore. So this commit uses the new IRB extension API to add commands instead, which would also bring a few benefits: - Commands can be displayed in IRB's help message to make them easier to discover. - The parameter of `connect_to` doesn't need to be a string anymore as registered commands aren't treated as Ruby methods.
12b4e60
to
113a887
Compare
After rails/rails#51705, the current way to add commands to the console will no longer work as
Rails::ConsoleMethods
will not be directly included to the IRB internal anymore.So this commit uses the new IRB extension API to add commands instead, which would also bring a few benefits:
Commands can be displayed in IRB's help message to make them easier to discover.
The parameter of
connect_to
doesn't need to be a string anymore as registered commands aren't treated as Ruby methods. So this now works too: