Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 d236827
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 53 deletions.
6 changes: 6 additions & 0 deletions railties/CHANGELOG
@@ -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]
Expand Down
47 changes: 25 additions & 22 deletions railties/bin/rails
@@ -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
3 changes: 0 additions & 3 deletions railties/lib/generators/rails/app/templates/script/about

This file was deleted.

5 changes: 0 additions & 5 deletions railties/lib/generators/rails/app/templates/script/console.tt

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions railties/lib/generators/rails/app/templates/script/destroy

This file was deleted.

2 changes: 0 additions & 2 deletions railties/lib/generators/rails/app/templates/script/generate

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions railties/lib/generators/rails/app/templates/script/plugin

This file was deleted.

6 changes: 6 additions & 0 deletions railties/lib/generators/rails/app/templates/script/rails
@@ -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'
3 changes: 0 additions & 3 deletions railties/lib/generators/rails/app/templates/script/runner

This file was deleted.

5 changes: 0 additions & 5 deletions railties/lib/generators/rails/app/templates/script/server.tt

This file was deleted.

12 changes: 12 additions & 0 deletions railties/lib/rails/commands/application.rb
@@ -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
69 changes: 69 additions & 0 deletions railties/lib/rails/commands/rails.rb
@@ -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
Copy link
Contributor

@mhfs mhfs commented on d236827 Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@yuritomanek
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice.

@trvsdnn
Copy link
Contributor

@trvsdnn trvsdnn commented on d236827 Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, this is cool.

@carlosantoniodasilva
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No aliases anymore =).

@floering
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweetness. no more fat fingering the slashes.

@antoniorosado
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so nice.

@wildchild
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@codesnik
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@rails
Copy link
Collaborator

@rails rails commented on d236827 Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

@Aupajo Aupajo commented on d236827 Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

+1 Nice commit.

@bensie
Copy link
Contributor

@bensie bensie commented on d236827 Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

@bensie bensie commented on d236827 Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@codesnik
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

@jinzhu jinzhu commented on d236827 Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@changwang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@mikel
Copy link
Member

@mikel mikel commented on d236827 Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@changwang thanks, will be fixed shortly

@jo
Copy link

@jo jo commented on d236827 Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for what I always have been waited for

@dmathieu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay ! :)

@tofumatt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@alan-andrade
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jonatas
Copy link

@jonatas jonatas commented on d236827 Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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

@rails
Copy link
Collaborator

@rails rails commented on d236827 Feb 3, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@chikamichi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

@grigio grigio commented on d236827 Feb 4, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

@grigio grigio commented on d236827 Feb 5, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

@nertzy nertzy commented on d236827 Feb 16, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Please sign in to comment.