gem to deal with config file / program options

Discussion in 'Ruby' started by Shadowfirebird, Mar 7, 2011.

  1. Hi all,

    Short version: What gems do people use to deal with program options in a YAML file and taken from the command line? I seem to have too much choice to make a sensible decision as to which to use.


    Long version:

    I mostly write command-line ruby programs and I've getting fed up with dealing with program options. You know the sort of thing: my program collects command line options using optparse; saved options from a YAML file; and implicitly knows good defaults for these. The idea being that these three all end up in a hash that the gubbins of my program can refer to.

    I've decided that rather than dealing with this in a half-arsed manner I want to get it right this time. I don't mind rolling my own, but obviously if there's a gem that does it for me, I'll use that. The problem is that there are hundreds of gems called config-something, and half of them look as if they might do the job -- if there was any documentation...

    (The real trick I'd like to pull is to specify the YAML filename on the command line, but still have the command line options override those in the YAML file.)

    What does everyone else use?

    Ta,
    Shadowfirebird.
    --
    It's easier to take it apart than to put it back together.
    -- Washlesky
     
    Shadowfirebird, Mar 7, 2011
    #1
    1. Advertising

  2. Shadowfirebird

    Chris Kottom Guest

    [Note: parts of this message were removed to make it a legal post.]

    For command line arguments, Ruby's OptionParser is a part of the standard
    library.
    http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html

    <http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html>For
    YAML configuration files, I've never needed anything so complex that I
    couldn't get there with a combination of YAML::load_file and Hash#merge
    using Ryan Bates'
    Railscast<http://railscasts.com/episodes/85-yaml-configuration-file>on
    YAML configuration files as a sort of loose template. Are you looking
    for something more sophisticated than that?

    On Mon, Mar 7, 2011 at 11:27 PM, Shadowfirebird <>wrote:

    > Hi all,
    >
    > Short version: What gems do people use to deal with program options in a
    > YAML file and taken from the command line? I seem to have too much choice
    > to make a sensible decision as to which to use.
    >
    >
    > Long version:
    >
    > I mostly write command-line ruby programs and I've getting fed up with
    > dealing with program options. You know the sort of thing: my program
    > collects command line options using optparse; saved options from a YAML
    > file; and implicitly knows good defaults for these. The idea being that
    > these three all end up in a hash that the gubbins of my program can refer
    > to.
    >
    > I've decided that rather than dealing with this in a half-arsed manner I
    > want to get it right this time. I don't mind rolling my own, but obviously
    > if there's a gem that does it for me, I'll use that. The problem is that
    > there are hundreds of gems called config-something, and half of them look as
    > if they might do the job -- if there was any documentation...
    >
    > (The real trick I'd like to pull is to specify the YAML filename on the
    > command line, but still have the command line options override those in the
    > YAML file.)
    >
    > What does everyone else use?
    >
    > Ta,
    > Shadowfirebird.
    > --
    > It's easier to take it apart than to put it back together.
    > -- Washlesky
    >
    >
     
    Chris Kottom, Mar 8, 2011
    #2
    1. Advertising

  3. > I've never needed anything so complex that I
    > couldn't get there with a combination of YAML::load_file and Hash#merge
    > using Ryan Bates'
    > Railscast<http://railscasts.com/episodes/85-yaml-configuration-file>on
    > YAML configuration files as a sort of loose template. Are you looking
    > for something more sophisticated than that?


    A little more, yes.

    I've done as you did until I reached the point where the program I was writing needed the ability to specify the config file on the command line -- but still have command line options override those in the config file.

    Sure, I can see to code my own way out of this: one hash for default options, one hash made up of command line options, and one hash for the config file; then merge. But if some kind person has written an elegant gem that gives me all I could want in this department (much as optparse does so well for the command line), and if everyone but me was already using it, then I should be, too.

    Plus, some of the descriptions for gems hint at cleverer stuff: objects that inherently know what their configuration options are, for example. But I can't find any documentation on how this works out in practice.

    --
    You can't have everything... where would you put it?
    -- Steven Wright
     
    Shadowfirebird, Mar 8, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rbt

    deal or no deal

    rbt, Dec 22, 2005, in forum: Python
    Replies:
    7
    Views:
    571
    Duncan Smith
    Dec 28, 2005
  2. CSharpner
    Replies:
    0
    Views:
    1,093
    CSharpner
    Apr 9, 2007
  3. Austin 7873
    Replies:
    5
    Views:
    198
    Eric Hodel
    Jan 27, 2007
  4. Chiyuan Zhang

    How does gem deal with extensions?

    Chiyuan Zhang, Mar 2, 2008, in forum: Ruby
    Replies:
    0
    Views:
    102
    Chiyuan Zhang
    Mar 2, 2008
  5. Brandon Simmons
    Replies:
    0
    Views:
    360
    Brandon Simmons
    Dec 22, 2010
Loading...

Share This Page