Sha256: 306a0629666348a44495feb223739c5230c9bf3b5c38399c4bed94ce57e81730
Contents?: true
Size: 1.47 KB
Versions: 2
Compression:
Stored size: 1.47 KB
Contents
require 'optparse' require 'psych' class YamlQuery::Settings @options = {} attr_reader :options def self.get_options get_rc set_default get_flags @options end private 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 def self.get_rc yqrc_path = "#{ENV['HOME']}/.yqrc.yaml" if File.exist?(yqrc_path) @options = Psych.load_file(yqrc_path) end end def self.set_default @options[:delimiter] = '.' end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
yamlquery-0.0.2 | lib/yamlquery/settings.rb |
yamlquery-0.0.1 | lib/yamlquery/settings.rb |