Class: Grepfruit::Commands::Search

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/grepfruit/cli.rb

Instance Method Summary collapse

Instance Method Details

#call(path: ".", **options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/grepfruit/cli.rb', line 21

def call(path: ".", **options)
  error_exit("You must specify a regex pattern using the -r or --regex option.") unless options[:regex]
  error_exit("Jobs must be at least 1") if options[:jobs] && options[:jobs].to_i < 1

  begin
    regex_pattern = Regexp.new(options[:regex])
  rescue RegexpError => e
    error_exit("Invalid regex pattern - #{e.message}")
  end

  Grepfruit::CliSearch.new(
    path: path,
    regex: regex_pattern,
    exclude: options[:exclude] || [],
    include: options[:include] || [],
    truncate: options[:truncate]&.to_i,
    search_hidden: options[:search_hidden],
    jobs: options[:jobs]&.to_i,
    json: options[:json],
    count: options[:count]
  ).execute
end