#20 new

FeatureRequest: config file support

Reported by commander_fan | March 26th, 2009 @ 05:50 AM

It'd be handy if commander also looked after config files.


$ commander --configure-list
Reading config file ~/.commander/commanderrc ...

  verbose = on
  debug = off
  logfile = /var/log/commander/commander.log
  welcome = "Hello there"

$ commander --configure-enable debug
Writing debug value to ~/.commander/commanderrc

$ commander --configure-set logfile /tmp/commander.log
Writing logfile value to ~/.commander/commanderrc

$ commander --configure welcome
Enter a value for welcome: "Welcome"

Writing welcome value to ~/.commander/commanderrc

$ commander --configure-list
Reading config file ~/.commander/commanderrc ...

  verbose = on
  debug = on
  logfile = /tmp/commander.log
  welcome = "Welcome"

And determine the config file using a set of config files and a global config option, like so,

  program :config_files, [
  program :config_type, 'YAML'

  global_option('-c', '--config FILE', 'Load config data for your commands to use') { |file| 
    program[:config_file] = file }

With a change to Commander::Runner

  class Runner
    def program key, *args
      elsif key == :config_files and !args.empty?
        @program[:config_file] ||= key.detect { |f| Pathname(f).expand_path.exist? }

Comments and changes to this ticket

  • commander_fan

    commander_fan March 26th, 2009 @ 05:54 AM

    • Tag set to config, featurerequest
  • TJ Holowaychuk

    TJ Holowaychuk March 26th, 2009 @ 03:24 PM

    • Tag changed from config, featurerequest to config, feature_request, options

    I think there is a ticket for --config already, but I like the additional info here. One thing I want to be careful with is cluttering EVERY executable with to many default features. Perhaps we should have:

    program :name, 'foo'
    program, :enable, :config

    or have it enabled by default etc, but I can see some people being a bit frustrated if its cluttered with tons of this stuff. I actually did this already with my visionmedia-release gem, however that was just an ad-hoc implementation.

    Personally I think this would be a sub-command, and --options would simply load options from a file, for example this is what I have working with release:

    # Adds all the switches passed and writes foo as a new config
    re config add foo --file bin/re --history --dry-run
    # Shows all configurations
    re config show
    # Utilize it using a real sub-command, pulling in all the options
    re bump minor --config foo
    # Remove one
    re config remove foo

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

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

The complete solution for Ruby command-line executables

People watching this ticket