def optparse_env
    # Has to set the RAILS_ENV before config/application is required
    if ARGV.first && !ARGV.first.index("-") && env = ARGV.shift # has to shift the env ARGV so IRB doesn't freak
      ENV['RAILS_ENV'] = %w(production development test).detect {|e| e =~ /^#{env}/} || env
    end
  end
def optparse_env
    # Has to set the RAILS_ENV before config/application is required
    if ARGV.first && !ARGV.first.index("-") && env = ARGV.shift # has to shift the env ARGV so IRB doesn't freak
      ENV['RAILS_ENV'] = %w(production development test).detect {|e| e =~ /^#{env}/} || env
    end
  end
copied from rails/commands/console