Permalink
Browse files

Removed all the default commands in script/* and replaced them with s…

…cript/rails and a rails command that'll act the same when run from within the app [DHH]
  • Loading branch information...
dhh committed Feb 2, 2010
1 parent 144f41e commit d236827881d119fb9ad25c81ce8e7756f1966823
View
@@ -1,5 +1,11 @@
*Edge*
* Removed all the default commands in script/* and replaced them with script/rails and a rails command that'll act the same when run from within the app [DHH]. Example:
./script/generate scaffold post title:string can now be called as rails g scaffold post title:string
Run rails --help inside an app for more help.
* Removed config/initializers/new_rails_defaults.rb as all frameworks now follow the settings from it [DHH]
* Set config.time_zone to UTC by default [DHH]
View
@@ -1,27 +1,30 @@
begin
require 'rails/ruby_version_check'
rescue LoadError
# If people are not using gems, the load path must still
# be correct.
# TODO: Remove the begin / rescue block somehow
$:.unshift File.expand_path('../../lib', __FILE__)
$:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
$:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
require 'rails/ruby_version_check'
end
if File.exists?(Dir.getwd + '/script/rails')
exec(Dir.getwd + '/script/rails', *ARGV)
else
begin
require 'rails/ruby_version_check'
rescue LoadError
# If people are not using gems, the load path must still
# be correct.
# TODO: Remove the begin / rescue block somehow
$:.unshift File.expand_path('../../lib', __FILE__)
$:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
$:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
require 'rails/ruby_version_check'
end
Signal.trap("INT") { puts; exit }
Signal.trap("INT") { puts; exit }
require 'rails/version'
if %w(--version -v).include? ARGV.first
puts "Rails #{Rails::VERSION::STRING}"
exit(0)
end
require 'rails/version'
if %w(--version -v).include? ARGV.first
puts "Rails #{Rails::VERSION::STRING}"
exit(0)
end
ARGV << "--help" if ARGV.empty?
ARGV << "--help" if ARGV.empty?
require 'rails/generators'
require 'generators/rails/app/app_generator'
require 'rails/generators'
require 'generators/rails/app/app_generator'
Rails::Generators::AppGenerator.start
Rails::Generators::AppGenerator.start
end

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,6 @@
ENV_PATH = File.expand_path('../../config/environment', __FILE__)
BOOT_PATH = File.expand_path('../../config/boot', __FILE__)
APP_PATH = File.expand_path('../../config/application', __FILE__)
require BOOT_PATH
require 'rails/commands/rails'

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,12 @@
require 'rails/version'
if %w(--version -v).include? ARGV.first
puts "Rails #{Rails::VERSION::STRING}"
exit(0)
end
ARGV << "--help" if ARGV.empty?
require 'rails/generators'
require 'generators/rails/app/app_generator'
Rails::Generators::AppGenerator.start
@@ -0,0 +1,69 @@
if ARGV.empty?
ARGV << '--help'
end
HELP_TEXT = <<-EOT
usage: rails COMMAND [ARGS]
The most common rails commands are:
generate Generate new code (short-cut alias: "g")
console Start the Rails console (short-cut alias: "c")
server Start the Rails server (short-cut alias: "s")
In addition to those, there are:
application Generate the Rails application code
dbconsole Start a console for the database specified in config/database.yml
destroy Undo code generated with "generate"
benchmarker See how fast a piece of code runs
profiler Get profile information from a piece of code
plugin Install a plugin
runner Run a piece of code in the application environment
All commands can be run with -h for more information.
EOT
case ARGV.shift
when 'g', 'generate'
require ENV_PATH
require 'rails/commands/generate'
when 'c', 'console'
require BOOT_PATH
require 'rails/commands/console'
require APP_PATH
Rails::Console.start(Rails::Application)
when 's', 'server'
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands/server'
Dir.chdir(File.expand_path('../..', __FILE__))
Rails::Server.start
when 'dbconsole'
require BOOT_PATH
require 'rails/commands/dbconsole'
require APP_PATH
Rails::DBConsole.start(Rails::Application)
when 'destroy'
require ENV_PATH
require 'rails/commands/destroy'
when 'benchmarker'
require ENV_PATH
require 'rails/commands/performance/benchmarker'
when 'profiler'
require ENV_PATH
require 'rails/commands/performance/profiler'
when 'plugin'
require APP_PATH
require 'rails/commands/plugin'
when 'runner'
require BOOT_PATH
require 'rails/commands/runner'
require ENV_PATH
when '--help', '-h'
puts HELP_TEXT
else
puts "Error: Command not recognized"
puts HELP_TEXT
end

27 comments on commit d236827

@mhfs

This comment has been minimized.

Contributor

mhfs replied Feb 3, 2010

Awesome!

@yuritomanek

This comment has been minimized.

yuritomanek replied Feb 3, 2010

Very nice.

@blahed

This comment has been minimized.

blahed replied Feb 3, 2010

wow, this is cool.

@carlosantoniodasilva

This comment has been minimized.

Member

carlosantoniodasilva replied Feb 3, 2010

No aliases anymore =).

@floering

This comment has been minimized.

Contributor

floering replied Feb 3, 2010

sweetness. no more fat fingering the slashes.

@antoniorosado

This comment has been minimized.

antoniorosado replied Feb 3, 2010

This is so nice.

@wildchild

This comment has been minimized.

Contributor

wildchild replied Feb 3, 2010

This is cool, but merb's way (merb, merb-gen) is better imho.

@codesnik

This comment has been minimized.

Contributor

codesnik replied Feb 3, 2010

you type "rails generate",
then shell finds "rails" command somewhere in "usr/local/bin"
then it runs it just to ask ruby to search actual rails executable buried somewhere in your gems
just to find real rails in your script/ directory
and execute it, and once again

nice, two unnecessary steps
gonna buy faster laptop
or write witty alias for rails

P.S. zsh allows me to type
s/g TAB to complete script/generate, so no relaxation for fingers either

@ghost

This comment has been minimized.

Collaborator

ghost replied Feb 3, 2010

codesnik, I recommend you do not look at how Ruby code is turned into Assembler. The inefficiencies that the Ruby community at large go through to present a nicer human environment is probably disgusting to most if you look under the covers. Don't look inside inside the chocolate factory!

Also, you can do "rails g" for generate. All the major commands have shortcuts. See "rails --help" for an index of them all.

@Aupajo

This comment has been minimized.

Aupajo replied Feb 3, 2010

Wait, there's a chocolate factory? Sounds like _why's secret hiding place.

+1 Nice commit.

@bensie

This comment has been minimized.

Contributor

bensie replied Feb 3, 2010

When trying to create a new app -

rails/railties/bin/rails: line 1: syntax error near unexpected token Dir.getwd' rails/railties/bin/rails: line 1:if File.exists?(Dir.getwd + '/script/rails')'

@bensie

This comment has been minimized.

Contributor

bensie replied Feb 3, 2010

Really wishing you could delete comments right about now...

@codesnik

This comment has been minimized.

Contributor

codesnik replied Feb 3, 2010

ok, i'm a little grouchy here. still, i'd like to hear what jruby guys feel about extra "exec".
but of course they can use script/rails

@jinzhu

This comment has been minimized.

jinzhu replied Feb 3, 2010

+1

@changwang

This comment has been minimized.

changwang replied Feb 3, 2010

I think you guys should modify the default index page though, there is no script/generate any more. :)

@mikel

This comment has been minimized.

Member

mikel replied Feb 3, 2010

@changwang thanks, will be fixed shortly

@jo

This comment has been minimized.

jo replied Feb 3, 2010

+1 for what I always have been waited for

@dmathieu

This comment has been minimized.

Contributor

dmathieu replied Feb 3, 2010

Yay ! :)

@tofumatt

This comment has been minimized.

tofumatt replied Feb 3, 2010

This is a good idea; script/* was always something that felt clunky. I'm alright with the extra "exec" ;-)

@alan-andrade

This comment has been minimized.

alan-andrade replied Feb 3, 2010

Thanks for this fix. Its definitely better than the actual way.

@jonatas

This comment has been minimized.

jonatas replied Feb 3, 2010

actually, i'm using 'db' shortcut for script/dbconsole :D

  • alias db='script/dbconsole '
  • alias db='rails dbconsole'
@ghost

This comment has been minimized.

Collaborator

ghost replied Feb 3, 2010

See http://github.com/rails/rails/commit/f390eade5fd70615ba2ee8e089821bcf2d5f7b17 -- we added rails db as a shortcut for dbconsole.

@chikamichi

This comment has been minimized.

chikamichi replied Feb 4, 2010

I'm a little bit confused by the new way to go. I created a brand new app with ruby rails my_app --dev, rails being an alias to my railties/bin/rails. Went fine, bundle's ok. But now I want to run the server, so I guess I must do ruby rails s, but I only get a load of code being prompted. Ctrl-Cing and checking for the error backtrace, I read:

WARNING: Invalid .gemspec format in '/home/jd/.gem/ruby/1.9.1/specifications/mail-2.1.2.gemspec'
WARNING: #<NoMethodError: undefined method `>' for nil:NilClass>

-*- encoding: u^C/opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/user_interaction.rb:240:in `write': Interrupt

from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/user_interaction.rb:240:in `puts'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/user_interaction.rb:240:in `alert_warning'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/user_interaction.rb:125:in `alert_warning'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/source_index.rb:108:in `rescue in load_specification'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/source_index.rb:94:in `load_specification'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/source_index.rb:153:in `block (2 levels) in load_gems_in'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/source_index.rb:152:in `each'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/source_index.rb:152:in `block in load_gems_in'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/source_index.rb:149:in `reverse_each'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/source_index.rb:149:in `load_gems_in'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/source_index.rb:345:in `refresh!'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/source_index.rb:78:in `from_gems_in'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/source_index.rb:58:in `from_installed_gems'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems.rb:944:in `source_index'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/gem_path_searcher.rb:84:in `init_gemspecs'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/gem_path_searcher.rb:19:in `initialize'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems.rb:889:in `new'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems.rb:889:in `block in searcher'
from <internal:prelude>:8:in `synchronize'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems.rb:888:in `searcher'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems.rb:528:in `find_files'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems.rb:1132:in `<top (required)>'
from <internal:gem_prelude>:235:in `require'
from <internal:gem_prelude>:235:in `load_full_rubygems_library'
from <internal:gem_prelude>:334:in `const_missing'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/specification.rb:1038:in `<class:Specification>'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/rubygems-update-1.3.5/lib/rubygems/specification.rb:28:in `<top (required)>'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/bundler-0.9.0.pre4/lib/bundler/rubygems.rb:2:in `require'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/bundler-0.9.0.pre4/lib/bundler/rubygems.rb:2:in `<top (required)>'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/bundler-0.9.0.pre4/lib/bundler.rb:4:in `require'
from /opt/ruby1.9/lib/ruby1.9/gems/1.9.1/gems/bundler-0.9.0.pre4/lib/bundler.rb:4:in `<top (required)>'
from /var/www/oggo/config/boot.rb:6:in `require'
from /var/www/oggo/config/boot.rb:6:in `rescue in <top (required)>'
from /var/www/oggo/config/boot.rb:2:in `<top (required)>'
from /var/www/oggo/script/rails:9:in `require'
from /var/www/oggo/script/rails:9:in `<main>'

What did I do wrong? Brand new install of Ruby1.9 from source, Rails edge fetched from git following RailsBlog wycats instructions.
Thx.

@grigio

This comment has been minimized.

grigio replied Feb 4, 2010

I get this:
WARNING: Invalid .gemspec format in '/var/lib/gems/1.9.0/specifications/memcache-client-1.7.7.gemspec'
/home/grigio/Documenti/rails/railties/lib/rails.rb:25:in <top (required)>': undefined methoddefault_external=' for Encoding:Class (NoMethodError)

@grigio

This comment has been minimized.

grigio replied Feb 5, 2010

OMG! internal:gem_prelude:114:in push_gem_version_on_load_path': undefined method<=>' for nil:NilClass (NoMethodError)
from internal:gem_prelude:8:in `gem'

@codesnik

This comment has been minimized.

Contributor

codesnik replied Feb 9, 2010

meanwhile, for zsh (bash too?) users out there

http://gist.github.com/298942

so it would work even while rails3 is in beta. and maybe afterwards.

@nertzy

This comment has been minimized.

Contributor

nertzy replied Feb 16, 2010

codesnik, why not just run script/rails directly if you are worried about the additional exec?

Please sign in to comment.