Sha256: 699725775987040009298847f5386fdb07ccccca809884121b588334bde4c657

Contents?: true

Size: 1.68 KB

Versions: 3

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

require_relative 'options_helpers.rb'

# This class executes a system command to retrieve the git history, which is passed through `rg`
# (ripgrep), and then ultimately is fed back to `fcom` for parsing.
class Fcom::Querier
  include ::Fcom::OptionsHelpers

  def initialize(options)
    @options = options
  end

  # rubocop:disable Metrics/CyclomaticComplexity
  # rubocop:disable Metrics/PerceivedComplexity
  def query
    expression_to_match = search_string
    expression_to_match = Regexp.escape(expression_to_match).gsub('\\ ', ' ') unless regex_mode?

    if expression_to_match.nil? || expression_to_match.empty?
      puts('provide expression to match as first argument')
      exit
    end

    quote = expression_to_match.include?('"') ? "'" : '"'

    command = <<~COMMAND.squish
      git log
        #{%(--author="#{author}") if author}
        #{"--since=#{days}.day" unless days.nil?}
        --full-diff
        --no-textconv
        --format="commit %s|%H|%an|%cr (%ci)"
        --source
        -p #{path}
        |

      rg #{quote}(#{expression_to_match})|(^commit )|(^diff )#{quote}
        --color never
        #{'--ignore-case' if ignore_case?}
        #{@options[:rg_options]}
        |

      #{'exe/' if development?}fcom #{quote}#{search_string}#{quote}
        #{"--days #{days}" if days}
        #{'--regex' if regex_mode?}
        #{'--debug' if debug?}
        #{'--ignore-case' if ignore_case?}
        --path #{path}
        --parse-mode
        --repo #{repo}
    COMMAND

    Fcom.logger.debug("Executing command: #{command}")
    system(command)
  end
  # rubocop:enable Metrics/PerceivedComplexity
  # rubocop:enable Metrics/CyclomaticComplexity
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fcom-0.7.0 lib/fcom/querier.rb
fcom-0.6.0 lib/fcom/querier.rb
fcom-0.5.1 lib/fcom/querier.rb