Sha256: 8bab1457cfded409d79c6f85aef1e5018e0c41dea7eeb2aa54700dac73208ece

Contents?: true

Size: 899 Bytes

Versions: 2

Compression:

Stored size: 899 Bytes

Contents

#!/usr/bin/env ruby
require_relative '../lib/hsql/command_line'

command_line = HSQL::CommandLine.new
options = command_line.options
filename = command_line.filename

unless filename
  puts command_line.option_parser
  exit 1
end

begin
  file = File.new(filename)
rescue Errno::ENOENT
  puts "#{filename.inspect}: No such file"
  exit 1
end

require_relative '../lib/hsql'

file = HSQL::File.parse_file(filename, options)
if 'yaml' == options[:meta_only]
  puts file.to_yaml
elsif 'json' == options[:meta_only]
  puts file.to_json
else
  # Runs the whole SQL string through the parser to find the individual queries
  # and then deparses it
  file.queries.each do |query|
    warn '-- Parsed and deparsed SQL:' if command_line.options[:verbose]
    begin
      puts query
    rescue => e
      warn "-- #{e.inspect}" if command_line.options[:verbose]
      puts file.rendered_sql
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hsql-0.4.1 bin/hsql
hsql-0.4.0 bin/hsql