Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

dbconsole arguments order mismatch

#5930
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.

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

State: new
Milestone: none
Assigned to: Xavier Noria Xavier Noria
Importance: Low

Activity

  1. Ryan Bigg
    Ryan Bigg
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 8th, 2010 @ 01:51 AM

  2. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    November 8th, 2010 @ 01:51 AM

  3. Vijay Dev
    Vijay Dev
    • 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.

    February 5th, 2011 @ 04:51 PM

  4. Vijay Dev
    Vijay Dev

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

    February 5th, 2011 @ 04:58 PM

  5. Andrei Kulakov
  6. Xavier Noria
    Xavier Noria

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

    March 9th, 2011 @ 07:55 PM

  7. Andrei Kulakov
    Andrei Kulakov

    Renewed patch. Maybe there is a better implementation.

    March 9th, 2011 @ 08:02 PM

  8. Xavier Noria
    Xavier Noria
    • 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?

    March 9th, 2011 @ 08:17 PM

  9. Andrei Kulakov
    Andrei Kulakov

    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.

    March 9th, 2011 @ 08:56 PM

  10. Andrei Kulakov
    Andrei Kulakov

    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
    

    March 9th, 2011 @ 09:52 PM

  11. Xavier Noria
    Xavier Noria

    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.

    March 9th, 2011 @ 10:23 PM