Project

cli_config

0.0
No commit activity in last 3 years
No release in over 3 years
Provides dsl heavily based on solnic/virtus forspecifying options that will be filled from yamlor command line options via OptionParser
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
>= 0

Runtime

 Project Readme

CLIConfig

A tiny gem for handling configs for command line apps

CLIConfig provides a dsl heavily based on solnic/virtus for specifying options that will be filled from yam or command line options via OptionParser.

Installation

Add this line to your application's Gemfile:

gem 'cli_config'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cli_config

Usage

class RPGConfig
  include CLIConfig

  option :name, String, desc: 'your name'
  option :race, Symbol, desc: 'your race (%{default})', default: :human
  option :strength, Integer, desc: 'your strength (%{default})', default: 33
  option :stamina, Integer, desc: 'your stamina (%{default})', default: 33, key: :x
  option :intelligence, Integer, desc: 'your intelligence (%{default})', default: 34
end

config = RPGConfig.new(name: 'test')

# Or read from a yaml file
# config = RPGConfig.load('/some/config.yml')

parser = OptionParser.new
parser.banner = "Usage: #{$0} [options]"
config.override_from_option_parser(parser)

puts parser

Output:

Usage: rpg [options]
    -n, --name VALUE                 your name
    -r, --race VALUE                 your race (human)
    -s, --strength VALUE             your strength (33)
    -x, --stamina VALUE              your stamina (33)
    -i, --intelligence VALUE         your intelligence (34)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jreinert/cli_config.