Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read options from yaml file instead of passed options #413

Closed
netbe opened this issue Apr 24, 2014 · 1 comment
Closed

read options from yaml file instead of passed options #413

netbe opened this issue Apr 24, 2014 · 1 comment

Comments

@netbe
Copy link

netbe commented Apr 24, 2014

Hi,

I did manage to have a subclass of Thor read a config YAML file doing something like this:

  private

  def options
    original_options = super
    return original_options unless File.exists?(".babelish")
    defaults = ::YAML.load_file(".babelish") || {}
    Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
  end

this works well until you use required options and then the configuration is not reqd. So i guess my coed should be put elsewhere before required options are checked. Any advice where that may be?

Thanks

@ralph-tice
Copy link

I think foreman is the original source for this code block: ddollar/foreman@7f8ca7d

It would be nice to have first class support for config files.

In actual usage (a class deriving from Thor) I had to do this, which still breaks required options:

no_commands {
  def options
        require 'active_support/core_ext/hash/keys'
        original_options = super
        return original_options unless File.exists?(File.expand_path("~/.grout"))
        defaults = ::YAML.load_file(File.expand_path("~/.grout")) || {}
        Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
      end
    }

@rails rails locked and limited conversation to collaborators May 12, 2023
@rafaelfranca rafaelfranca converted this issue into discussion #822 May 12, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

3 participants