class YamlQuery::Settings

Attributes

options[R]

Public Class Methods

get_options() click to toggle source
# File lib/yamlquery/settings.rb, line 9
def self.get_options
  get_rc
  set_default
  get_flags
  @options
end

Private Class Methods

get_flags() click to toggle source
# File lib/yamlquery/settings.rb, line 18
def self.get_flags
  OptionParser.new do |opts|
    opts.banner = 'Usage: yq [options] "yaml.path.to.parameter"'

    opts.on('-h', '--help', 'Prints this help') do
      puts opts
      exit
    end

    opts.on('-y', '--yaml', "Generate output as yaml") do
      @options[:yaml?] = true
    end

    opts.on('-d', '--depth DEPTH', 'Only return keys from DEPTH in output') do |depth|
      @options[:depth] = depth
    end

    opts.on('-p', '--yamlpath PATH', 'Path to yaml files', String) do |path|
      @options[:yamlpath] = path
    end

    opts.on('-f', '--onlyfile', 'Only list file names that match') do
      @options[:onlyfile?] = true
    end

    opts.on('-1', '--oneline', 'Matches will be displayed in oneline mode') do
      @options[:oneline?] = true
    end

    opts.on('--debug', 'Prints some extra output helpful for debugging') do
      @options[:debug] = true
    end
  end.parse!

  if ARGV.empty?
    puts 'Query string is required.'
    exit 1
  else
    @options[:query] = ARGV[0]
  end
end
get_rc() click to toggle source
# File lib/yamlquery/settings.rb, line 60
def self.get_rc
  yqrc_path = "#{ENV['HOME']}/.yqrc.yaml"
  if File.exist?(yqrc_path)
    @options = Psych.load_file(yqrc_path)
  end
end
set_default() click to toggle source
# File lib/yamlquery/settings.rb, line 67
def self.set_default
  @options[:delimiter] = '.'
end