提交 8ff214e0 编写于 作者: J José Valim

Use the proper shebang when using Ruby 1.9 or jruby or windows.

上级 da09d46e
......@@ -335,18 +335,21 @@ def self.get_options_from_invocations(group_options, base_options)
# default value plus an instance helper method called shebang.
#
def self.add_shebang_option!
require 'rbconfig'
default = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
class_option :ruby, :type => :string, :aliases => "-r", :default => default,
class_option :ruby, :type => :string, :aliases => "-r", :default => Thor::Util.ruby_command,
:desc => "Path to the Ruby binary of your choice", :banner => "PATH"
class_eval <<-METHOD, __FILE__, __LINE__
protected
def shebang
"#!\#{options[:ruby] || "/usr/bin/env ruby"}"
no_tasks {
define_method :shebang do
@shebang ||= begin
command = if options[:ruby] == Thor::Util.ruby_command
"/usr/bin/env #{File.basename(Thor::Util.ruby_command)}"
else
options[:ruby]
end
"#!#{command}"
end
end
METHOD
}
end
end
......
......@@ -109,6 +109,21 @@ def test_shebang_is_added_to_files
).each { |path| assert_file "script/#{path}", /#!foo\/bar\/baz/ }
end
def test_shebang_when_is_the_same_as_default_use_env
run_generator ["--ruby", Thor::Util.ruby_command]
%w(
about
console
dbconsole
destroy
generate
plugin
runner
server
).each { |path| assert_file "script/#{path}", /#!\/usr\/bin\/env/ }
end
def test_rails_is_frozen
generator(:freeze => true, :database => "sqlite3").expects(:run).with("rake rails:freeze:edge", false)
silence(:stdout){ generator.invoke }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册