Sha256: 78f7ccffcc3a6e9899d9a1726bd2593f9265364025c3f95bf5f75e0adad20b6f

Contents?: true

Size: 1.48 KB

Versions: 6

Compression:

Stored size: 1.48 KB

Contents

#!/usr/bin/env ruby

require 'pathname'
require "optparse"
require_relative "../lib/syntax_search.rb"

options = {}
options[:terminal] = true
options[:record_dir] = ENV["SYNTAX_SEARCH_RECORD_DIR"]

parser = OptionParser.new do |opts|
  opts.banner = <<~EOM
    Usage: syntax_search <file> [options]

    Parses a ruby source file and searches for syntax error(s) unexpected `end', expecting end-of-input.

    Example:

      $ syntax_search dog.rb

      # ...

      ```
         1  require 'animals'
         2
      ❯ 10  defdog
      ❯ 15  end
      ❯ 16
        20  def cat
        22  end
      ```

    Env options:

      SYNTAX_SEARCH_RECORD_DIR=<dir>

      When enabled, records the steps used to search for a syntax error to the given directory

    Options:
  EOM

  opts.on("--help", "Help - displays this message") do |v|
    puts opts
    exit
  end

  opts.on("--record <dir>", "When enabled, records the steps used to search for a syntax error to the given directory") do |v|
    options[:record_dir] = v
  end

  opts.on("--no-terminal", "Disable terminal highlighting") do |v|
    options[:terminal] = false
  end
end
parser.parse!

file = ARGV[0]

if file.nil? || file.empty?
  # Display help if raw command
  parser.parse! %w[--help]
end

file = Pathname(file)

$stderr.puts "Record dir: #{options[:record_dir]}"  if options[:record_dir]

SyntaxErrorSearch.call(
  source: file.read,
  filename: file.expand_path,
  terminal: options[:terminal],
  record_dir: options[:record_dir]
)

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
syntax_search-0.1.5 exe/syntax_search
syntax_search-0.1.4 exe/syntax_search
syntax_search-0.1.3 exe/syntax_search
syntax_search-0.1.2 exe/syntax_search
syntax_search-0.1.1 exe/syntax_search
syntax_search-0.1.0 exe/syntax_search