Sha256: 21f0746923c38233c7c303b180bef8d5934c63e8a14009f73feabcc83d17e1d5
Contents?: true
Size: 1.5 KB
Versions: 1
Compression:
Stored size: 1.5 KB
Contents
#!/usr/bin/env ruby $:.unshift File.join(File.dirname(__FILE__), '../lib') require 'logger' require 'optparse' require 'yq' $stdout.sync = $stderr.sync = true unless defined?(LOGGER) LOGGER = Logger.new($stderr) end LOGGER.level = Logger::INFO @options = { context: :main_loop, output: :yaml } def prereqs ARGV << '--help' if ARGV.empty? opts = OptionParser.new do |opts| opts.banner = "Usage: #{File.basename($0)}" opts.separator '' opts.on_tail('-h', '--help', 'Show this message') do puts opts exit 0 end opts.on('--verbose', '-v', 'verbose') do LOGGER.level = Logger::DEBUG end opts.on("--develop", "Run in developer mode") do @options[:context] = :develop end opts.on('-r', '--raw-output') do @options[:output] = :raw end opts.on('--json-output') do @options[:output] = :json end end opts.parse! required_vars = %w[ ] required_vars.each do |v| raise "#{v} must be specified in the environment variables" unless ENV[v] end raise "jq not installed" unless Yq.which('jq') end def start begin @yaml = $stdin.read puts Yq.search_yaml(ARGV[0], @yaml, output: @options[:output]) rescue => e LOGGER.error "Unhandled exception #{e.class}: #{e.message}" e.backtrace.each do |v| LOGGER.debug v end raise end end def develop require 'pry' LOGGER.level = Logger::DEBUG LOGGER.info "Develop mode" start end def main_loop start end prereqs self.send(@options[:context])
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
yq-0.4.0 | bin/yq |