mdub/clamp — Issue #17: Feature: environment variables as flag values
Author: jordansissel
Created: 2012-03-07 05:19:35+00:00
State: open

Howdy!

It's fairly common in some environements (like heroku, etc) to use environment variables to configure applications. I am happy to produce this feature as a patch, but am looking for feedback and thumbs-up before I spend time on it :)

Thoughts? General proposal below:

## New feature: Flags can be set with environment variables

### The problem

I see lots of programs that take flags but also support configuration via environment variables (rails, heroku, etc). In most cases, I find these programs using optparse, clamp, etc, for the flag handling, but then handling environment variables separately, and often, with code that is not shared across projects.

### Automatic env handling:

option "--foo-bar", "FOO", "Some foo"

The above could be set with 'myapp --foo-bar value' like normal, but also FOO_BAR=value from the environment

### Explicit env

option "--foo-bar", "FOO", "Some foo", :env => "FOO"

The above would allow `FOO=value` to set the value for --foo-bar.

### --help improvements

Some hints should be given in the --help usage to indicate that environment variables can be used.

### Conflicts

When given both env and flag values, the flag value should win.