This project is archived and is in readonly mode.

#5930 new
Andrei Kulakov

dbconsole arguments order mismatch

Reported by Andrei Kulakov | November 8th, 2010 @ 01:28 AM

rails dbconsole --help

yields

Usage: dbconsole [options] [environment]
-p, --include-password           Automatically provide the password from database.yml
--mode [MODE]                Automatically put the sqlite3 database in the specified mode (html, list, line, column).
-h, --header
but neather
rails dbconsole -p production
or
rails dbconsole -p test
sets correct rails environment.
rails dbconsole production -p
and
rails dbconsole production -p
set correct environment.

I supply patch and hope this is correct way to solve the issue.

Comments and changes to this ticket

  • Ryan Bigg

    Ryan Bigg November 8th, 2010 @ 01:51 AM

    • Importance changed from “” to “Low”

    Automatic cleanup of spam.

  • Ryan Bigg

    Ryan Bigg November 8th, 2010 @ 01:51 AM

    Automatic cleanup of spam.

  • Vijay Dev

    Vijay Dev February 5th, 2011 @ 04:51 PM

    • Tag set to railties

    Won't it be easier to just change the Usage to specify environment first and then the options? :)

    @Andrei: Applying the patch fails. Please check it against master.

  • Vijay Dev

    Vijay Dev February 5th, 2011 @ 04:58 PM

    If someone decides, we can change the usage message, attaching the simple patch.

  • Andrei Kulakov
  • Xavier Noria

    Xavier Noria March 9th, 2011 @ 07:55 PM

    I think it is more common to have options first, arguments later, generally speaking. I'd vote for revising the implementation.

  • Andrei Kulakov

    Andrei Kulakov March 9th, 2011 @ 08:02 PM

    Renewed patch. Maybe there is a better implementation.

  • Xavier Noria

    Xavier Noria March 9th, 2011 @ 08:17 PM

    • Assigned user set to “Xavier Noria”

    I have not debugged the issue, but this should easily work correctly with optparse. I mean, no manual option handling if possible, better to use a standard library that solves that.

    Could you give it a whirl please?

  • Andrei Kulakov

    Andrei Kulakov March 9th, 2011 @ 08:56 PM

    I couldn't make it load correct database, when I set ENV['RAILS_ENV'] within block of opt.on.

    opt.on("-e", "--environment=name", String,
            "Specifies the environment to load database for (test/development/production).",
            "Default: development") do |env|
      ENV['RAILS_ENV'] = %w(production development test).detect { |e| e =~ /^#{env}/} || env
    end
    

    I think manual option handling has something to do with warning in this comment:

    # Has to set the RAILS_ENV before config/application is required
    if ARGV.first && !ARGV.first.index("-") && env = ARGV.first
      ENV['RAILS_ENV'] = %w(production development test).find { |e| e.index(env) } || env
    end
    

    Could you give it a whirl please?

    Apologies for my knowledge of English, could you rephrase that please.

  • Andrei Kulakov

    Andrei Kulakov March 9th, 2011 @ 09:52 PM

    Regular rails console has usage message:

    Usage: console [environment] [options]
    

    and similar option handling implementation to dbconsole.

    But rails server specifies environment through option:

    -e, --environment=name           Specifies the environment to run this server under (test/development/production).
                                     Default: development
    
  • Xavier Noria

    Xavier Noria March 9th, 2011 @ 10:23 PM

    Yes there are counterexamples, for example find(1) needs the directory first, and then options. But I think the most common interface is options, then arguments.

    A pity Rails commands are not consistent there. Maybe something worth taking into account for the next major revision.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Tags

Pages