Thor & Yaml Outputting as Binary

Thor Reading config yaml file to override options

I think you are looking for a way to set configuration options via the command line and via a configuration file.

Here is an example from the foreman gem.

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

It overrides the options method and merges values from a configuration file into the original options hash.

In your case, the following might work:

def csv2strings(name)
# do something with options
end

private
def options
original_options = super
filename = original_options[:file] || '.csvconverter.yaml'
return original_options unless File.exists?(filename)
defaults = ::YAML::load_file(filename) || {}
defaults.merge(original_options)
# alternatively, set original_options[:langs] and then return it
end

(I recently wrote a post about Foreman on my blog that explains this in more detail.)

ruby 1.8.7 why .to_yaml converts some Strings to non-readable bytes

Whether YAML prefers to dump a string as text or binary is a matter of ratio between ASCII and non ASCII characters.

If you want to avoid !binary as much as possible, you should use the ya2yaml gem. It tries hard to dump strings as ASCII + escaped UTF-8.

Evernote API Binary Error - Ruby on Rails - OAuth

I guess to_yml makes your error message unreadable like:

--- !binary |-
U1NMX2Nvbm5lY3QgcmV0dXJuZWQ9MSBlcnJubz0wIHN0YXRlPVNTTHYzIHJl
YWQgc2VydmVyIGNlcnRpZmljYXRlIEI6IGNlcnRpZmljYXRlIHZlcmlmeSBm
YWlsZWQ=

Can you replace to_yml with inspect?
It seems simply your message is outputted as binary and you could figure out the cause of error from messages if it is outputted as text.

Related post:
Thor & YAML outputting as binary?

split files to key value pair

This works:

awk '
sub(/^[[:space:]]+- name: /, ""){n=$0}
sub(/^[[:space:]]+value: /, ""){print n": "$0}'

Match and remove the name: /value: labels, and print the remainder of both lines on a single line.

Cant run rails server, project is telling me i dont have node even though I do?

I think you need a webpacker.yml file in your apps config file. I also suggest running bundle install and bundle update commands before launching the rails server after you installed a gem. Here's a closed issue similar to your problem; https://github.com/rails/webpacker/issues/940



Related Topics



Leave a reply



Submit