0.0
Low commit activity in last 3 years
A long-lived project that still receives updates
Useful Add-ons Thor CLI
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 0.0.1
~> 1
 Project Readme

Thor Add-ons

Build Status Gem Version

Extend Thor with useful Add-ons

Installation

gem install thor-addons

Usage

Options

The Options module allows you to read the CLI options from a configuration file or/and environment variables.

include the Options module to your Thor class.

require 'thor'
require 'thor_addons'

class CLI < Thor
  include ThorAddons::Options

  class_option :config_file, type: :string, default: "config.yml", desc: "Configuration file for the CLI"

  method_option :bar, type: :string, default: "biz", desc: "some option"
  desc "foo", "install one of the available apps"
  def foo
    # code
  end
end

In the example above the --bar option will be read from the configuration file --config-file

foo:
  bar: "zip"

and via the environment variable BAR

if you want to disable the configuration file you need to set in your class

def with_config_file?
  false
end

and for disabling the environment variables

def with_env?
  false
end

you can also have environment variables aliases, by setting

def envs_aliases
  # source => alias
  { "BAR" => "MY_BAR" }
end

The cli will set bar with the value of BAR or MY_BAR if BAR is not set.

This module will set the options in this order: cli options, config file, environment variables

Contributing

If you would like to help, please read the CONTRIBUTING file for suggestions.

License

Released under the MIT License. See the LICENSE file for further details.