module Threatinator::CLI::Helpers

Public Instance Methods

add_cli_args(gli, config_properties) click to toggle source
# File lib/threatinator/cli/parser.rb, line 13
def add_cli_args(gli, config_properties)
  config_properties.each do |key, args|
    desc, type, default_value = args
    if type.base == Axiom::Types::Boolean
      gli.switch key, desc: desc
    elsif type.base ==Axiom::Types::Array
      gli.flag key, desc: desc, type: Array
    else 
      gli.flag key, desc: desc
    end
  end
end
clean_opts(opts) click to toggle source
# File lib/threatinator/cli/parser.rb, line 26
def clean_opts(opts)
  opts.delete_if {|k, v| k.kind_of?(::Symbol) or (k == 'help') or v.nil? }
  opts
end
fix_opts(opts) click to toggle source
# File lib/threatinator/cli/parser.rb, line 47
def fix_opts(opts)
  nest_opts(clean_opts(opts))
end
nest_opts(opts) click to toggle source
# File lib/threatinator/cli/parser.rb, line 31
def nest_opts(opts)
  config_hash = {}
  opts.each_pair do |key, val|
    key_path = key.to_s.split('.')
    final_key = key_path.pop
    nested_hash = config_hash
    while key_path.length > 0
      part = key_path.shift
      nested_hash[part] ||= {}
      nested_hash = nested_hash[part]
    end
    nested_hash[final_key] = val
  end
  config_hash
end