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.
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.htmlFor
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 B.’
Railscasthttp://railscasts.com/episodes/85-yaml-configuration-fileon
YAML configuration files as a sort of loose template. Are you looking
for something more sophisticated than that?
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 B.’
Railscasthttp://railscasts.com/episodes/85-yaml-configuration-fileon
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.