如何从 rake 任务启动 IRB 控制台?
我正在尝试编写一个 rake 任务来设置一个镜像我的项目的环境。
task :environment do
require 'rubygems'
require 'sequel'
# require 'my_projects_special_files'
end
task :foo => [:environment] do
require 'irb'
IRB.start
end
导致 irb 抱怨“foo”不存在(任务名称)
10:28:01:irb_test >> rake foo --trace (in /Users/mwlang/projects/personal/rake/irb_test) ** Invoke foo (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute foo rake aborted! No such file or directory - foo /opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `initialize' /opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `open' /opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `initialize' /opt/local/lib/ruby/1.8/irb/context.rb:80:in `new' /opt/local/lib/ruby/1.8/irb/context.rb:80:in `initialize' /opt/local/lib/ruby/1.8/irb.rb:92:in `new' /opt/local/lib/ruby/1.8/irb.rb:92:in `initialize' /opt/local/lib/ruby/1.8/irb.rb:57:in `new' /opt/local/lib/ruby/1.8/irb.rb:57:in `start' /Users/mwlang/projects/personal/rake/irb_test/Rakefile:9
I'm trying to write a rake task that will set up an environment mirroring my project.
task :environment do
require 'rubygems'
require 'sequel'
# require 'my_projects_special_files'
end
task :foo => [:environment] do
require 'irb'
IRB.start
end
Leads to irb complaining that "foo" doesn't exist (the name of the task)
10:28:01:irb_test >> rake foo --trace (in /Users/mwlang/projects/personal/rake/irb_test) ** Invoke foo (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute foo rake aborted! No such file or directory - foo /opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `initialize' /opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `open' /opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `initialize' /opt/local/lib/ruby/1.8/irb/context.rb:80:in `new' /opt/local/lib/ruby/1.8/irb/context.rb:80:in `initialize' /opt/local/lib/ruby/1.8/irb.rb:92:in `new' /opt/local/lib/ruby/1.8/irb.rb:92:in `initialize' /opt/local/lib/ruby/1.8/irb.rb:57:in `new' /opt/local/lib/ruby/1.8/irb.rb:57:in `start' /Users/mwlang/projects/personal/rake/irb_test/Rakefile:9
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
IRB.start 正在查看 ARGV,其中包含来自 rake 命令行的任务名称。首先尝试清除 ARGV。
IRB.start is looking at ARGV which contains the task name(s) from the rake command line. Try clearing ARGV first.
从 Ruby 2.4.0 开始,您可以执行以下操作:
As of Ruby 2.4.0, you can do this:
我在运行我的任务时遇到了类似的问题。将其设置为默认任务解决了问题,但对解决错误没有帮助。在这里:我做了什么
I've had a similar problem when running my task like that. Setting it the default task solved the problem but it did not help with the bug. Here: what i did
rake 文件内容如下,其名称为 Rakefile。
执行 rake test:console
后,使用 rake test:console 从终端运行它,会弹出 irb,您可以看到它通过使用 Sanitize 的 clean 方法工作。
Sanitize.clean“一些文本”
The rake file contents are below and it is named Rakefile.
Run it from terminal with rake test:console
once you've executed the rake test:console, irb pops up and you can see that it works by using Sanitize's clean method.
Sanitize.clean "some text"
显然你定义任务的方式肯定有问题。如果您更改
为会发生什么
Apparently there must be a problem with how you defined your task. What happens if you change
to