Method: Fast::Cli#run!

Defined in:
lib/fast/cli.rb

#run!Object

Show help or search for node patterns



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/fast/cli.rb', line 186

def run!
  raise 'pry and parallel options are incompatible :(' if @parallel && @pry

  if @help || @files.empty? && @pattern.nil?
    puts option_parser.help
    return
  end

  if @similar
    ast = Fast.public_send( @sql ? :parse_sql : :ast, @pattern)
    @pattern = Fast.expression_from(ast)
    debug "Search similar to #{@pattern}"
  elsif @from_code
    ast = Fast.public_send( @sql ? :parse_sql : :ast, @pattern)
    @pattern = ast.to_sexp
    if @sql
      @pattern.gsub!(/\b-\b/,'_')
    end
    debug "Search from code to #{@pattern}"
  end

  if @files.empty?
    ast ||= Fast.public_send( @sql ? :parse_sql : :ast, @pattern)
    puts Fast.highlight(ast, show_sexp: @show_sexp, colorize: @colorize, sql: @sql)
  else
    search
  end
end